| 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 | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2012 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 | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 74 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 75 | static IOCB_t * |
| 76 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 77 | { |
| 78 | return &iocbq->iocb; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 83 | * @q: The Work Queue to operate on. |
| 84 | * @wqe: The work Queue Entry to put on the Work queue. |
| 85 | * |
| 86 | * This routine will copy the contents of @wqe to the next available entry on |
| 87 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 88 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 89 | * successful. If no entries are available on @q then this function will return |
| 90 | * -ENOMEM. |
| 91 | * The caller is expected to hold the hbalock when calling this routine. |
| 92 | **/ |
| 93 | static uint32_t |
| 94 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 95 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 96 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 97 | struct lpfc_register doorbell; |
| 98 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 99 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 100 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 101 | /* sanity check on queue memory */ |
| 102 | if (unlikely(!q)) |
| 103 | return -ENOMEM; |
| 104 | temp_wqe = q->qe[q->host_index].wqe; |
| 105 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 106 | /* 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] | 107 | idx = ((q->host_index + 1) % q->entry_count); |
| 108 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 109 | q->WQ_overflow++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 110 | return -ENOMEM; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 111 | } |
| 112 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 113 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 114 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 115 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 116 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 117 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 118 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
| 119 | |
| 120 | /* Update the host index before invoking device */ |
| 121 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 122 | |
| 123 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 124 | |
| 125 | /* Ring Doorbell */ |
| 126 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 127 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
| 128 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
| 129 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); |
| 130 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
| 131 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 132 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 133 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 134 | } else { |
| 135 | return -EINVAL; |
| 136 | } |
| 137 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 144 | * @q: The Work Queue to operate on. |
| 145 | * @index: The index to advance the hba index to. |
| 146 | * |
| 147 | * This routine will update the HBA index of a queue to reflect consumption of |
| 148 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 149 | * an entry the host calls this function to update the queue's internal |
| 150 | * pointers. This routine returns the number of entries that were consumed by |
| 151 | * the HBA. |
| 152 | **/ |
| 153 | static uint32_t |
| 154 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 155 | { |
| 156 | uint32_t released = 0; |
| 157 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 158 | /* sanity check on queue memory */ |
| 159 | if (unlikely(!q)) |
| 160 | return 0; |
| 161 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 162 | if (q->hba_index == index) |
| 163 | return 0; |
| 164 | do { |
| 165 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 166 | released++; |
| 167 | } while (q->hba_index != index); |
| 168 | return released; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 173 | * @q: The Mailbox Queue to operate on. |
| 174 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 175 | * |
| 176 | * This routine will copy the contents of @mqe to the next available entry on |
| 177 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 178 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 179 | * successful. If no entries are available on @q then this function will return |
| 180 | * -ENOMEM. |
| 181 | * The caller is expected to hold the hbalock when calling this routine. |
| 182 | **/ |
| 183 | static uint32_t |
| 184 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 185 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 186 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 187 | struct lpfc_register doorbell; |
| 188 | uint32_t host_index; |
| 189 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 190 | /* sanity check on queue memory */ |
| 191 | if (unlikely(!q)) |
| 192 | return -ENOMEM; |
| 193 | temp_mqe = q->qe[q->host_index].mqe; |
| 194 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 195 | /* If the host has not yet processed the next entry then we are done */ |
| 196 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 197 | return -ENOMEM; |
| 198 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 199 | /* Save off the mailbox pointer for completion */ |
| 200 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 201 | |
| 202 | /* Update the host index before invoking device */ |
| 203 | host_index = q->host_index; |
| 204 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 205 | |
| 206 | /* Ring Doorbell */ |
| 207 | doorbell.word0 = 0; |
| 208 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 209 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 210 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 216 | * @q: The Mailbox Queue to operate on. |
| 217 | * |
| 218 | * This routine will update the HBA index of a queue to reflect consumption of |
| 219 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 220 | * an entry the host calls this function to update the queue's internal |
| 221 | * pointers. This routine returns the number of entries that were consumed by |
| 222 | * the HBA. |
| 223 | **/ |
| 224 | static uint32_t |
| 225 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 226 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 227 | /* sanity check on queue memory */ |
| 228 | if (unlikely(!q)) |
| 229 | return 0; |
| 230 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 231 | /* Clear the mailbox pointer for completion */ |
| 232 | q->phba->mbox = NULL; |
| 233 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 234 | return 1; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 239 | * @q: The Event Queue to get the first valid EQE from |
| 240 | * |
| 241 | * This routine will get the first valid Event Queue Entry from @q, update |
| 242 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 243 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 244 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 245 | **/ |
| 246 | static struct lpfc_eqe * |
| 247 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 248 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 249 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 250 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 251 | |
| 252 | /* sanity check on queue memory */ |
| 253 | if (unlikely(!q)) |
| 254 | return NULL; |
| 255 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 256 | |
| 257 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 258 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 259 | return NULL; |
| 260 | /* 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] | 261 | idx = ((q->hba_index + 1) % q->entry_count); |
| 262 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 263 | return NULL; |
| 264 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 265 | q->hba_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 266 | return eqe; |
| 267 | } |
| 268 | |
| 269 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 270 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 271 | * @q: The Event Queue to disable interrupts |
| 272 | * |
| 273 | **/ |
| 274 | static inline void |
| 275 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 276 | { |
| 277 | struct lpfc_register doorbell; |
| 278 | |
| 279 | doorbell.word0 = 0; |
| 280 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 281 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 282 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 283 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 284 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 285 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 286 | } |
| 287 | |
| 288 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 289 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 290 | * @q: The Event Queue that the host has completed processing for. |
| 291 | * @arm: Indicates whether the host wants to arms this CQ. |
| 292 | * |
| 293 | * This routine will mark all Event Queue Entries on @q, from the last |
| 294 | * known completed entry to the last entry that was processed, as completed |
| 295 | * by clearing the valid bit for each completion queue entry. Then it will |
| 296 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 297 | * The internal host index in the @q will be updated by this routine to indicate |
| 298 | * that the host has finished processing the entries. The @arm parameter |
| 299 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 300 | * |
| 301 | * This function will return the number of EQEs that were popped. |
| 302 | **/ |
| 303 | uint32_t |
| 304 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 305 | { |
| 306 | uint32_t released = 0; |
| 307 | struct lpfc_eqe *temp_eqe; |
| 308 | struct lpfc_register doorbell; |
| 309 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 310 | /* sanity check on queue memory */ |
| 311 | if (unlikely(!q)) |
| 312 | return 0; |
| 313 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 314 | /* while there are valid entries */ |
| 315 | while (q->hba_index != q->host_index) { |
| 316 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 317 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 318 | released++; |
| 319 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 320 | } |
| 321 | if (unlikely(released == 0 && !arm)) |
| 322 | return 0; |
| 323 | |
| 324 | /* ring doorbell for number popped */ |
| 325 | doorbell.word0 = 0; |
| 326 | if (arm) { |
| 327 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 328 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 329 | } |
| 330 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 331 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 332 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 333 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 334 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 335 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 336 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 337 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 338 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 339 | return released; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 344 | * @q: The Completion Queue to get the first valid CQE from |
| 345 | * |
| 346 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 347 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 348 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 349 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 350 | **/ |
| 351 | static struct lpfc_cqe * |
| 352 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 353 | { |
| 354 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 355 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 356 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 357 | /* sanity check on queue memory */ |
| 358 | if (unlikely(!q)) |
| 359 | return NULL; |
| 360 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 361 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 362 | 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] | 363 | return NULL; |
| 364 | /* 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] | 365 | idx = ((q->hba_index + 1) % q->entry_count); |
| 366 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 367 | return NULL; |
| 368 | |
| 369 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 370 | q->hba_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 371 | return cqe; |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 376 | * @q: The Completion Queue that the host has completed processing for. |
| 377 | * @arm: Indicates whether the host wants to arms this CQ. |
| 378 | * |
| 379 | * This routine will mark all Completion queue entries on @q, from the last |
| 380 | * known completed entry to the last entry that was processed, as completed |
| 381 | * by clearing the valid bit for each completion queue entry. Then it will |
| 382 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 383 | * The internal host index in the @q will be updated by this routine to indicate |
| 384 | * that the host has finished processing the entries. The @arm parameter |
| 385 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 386 | * |
| 387 | * This function will return the number of CQEs that were released. |
| 388 | **/ |
| 389 | uint32_t |
| 390 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 391 | { |
| 392 | uint32_t released = 0; |
| 393 | struct lpfc_cqe *temp_qe; |
| 394 | struct lpfc_register doorbell; |
| 395 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 396 | /* sanity check on queue memory */ |
| 397 | if (unlikely(!q)) |
| 398 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 399 | /* while there are valid entries */ |
| 400 | while (q->hba_index != q->host_index) { |
| 401 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 402 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 403 | released++; |
| 404 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 405 | } |
| 406 | if (unlikely(released == 0 && !arm)) |
| 407 | return 0; |
| 408 | |
| 409 | /* ring doorbell for number popped */ |
| 410 | doorbell.word0 = 0; |
| 411 | if (arm) |
| 412 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 413 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 414 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 415 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 416 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 417 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 418 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 419 | return released; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 424 | * @q: The Header Receive Queue to operate on. |
| 425 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 426 | * |
| 427 | * This routine will copy the contents of @wqe to the next available entry on |
| 428 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 429 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 430 | * index that the rqe was copied to if successful. If no entries are available |
| 431 | * on @q then this function will return -ENOMEM. |
| 432 | * The caller is expected to hold the hbalock when calling this routine. |
| 433 | **/ |
| 434 | static int |
| 435 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 436 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 437 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 438 | struct lpfc_rqe *temp_hrqe; |
| 439 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 440 | struct lpfc_register doorbell; |
| 441 | int put_index = hq->host_index; |
| 442 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 443 | /* sanity check on queue memory */ |
| 444 | if (unlikely(!hq) || unlikely(!dq)) |
| 445 | return -ENOMEM; |
| 446 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 447 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 448 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 449 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 450 | return -EINVAL; |
| 451 | if (hq->host_index != dq->host_index) |
| 452 | return -EINVAL; |
| 453 | /* If the host has not yet processed the next entry then we are done */ |
| 454 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 455 | return -EBUSY; |
| 456 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 457 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 458 | |
| 459 | /* Update the host index to point to the next slot */ |
| 460 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 461 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 462 | |
| 463 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 464 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 465 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 466 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 467 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 468 | hq->entry_repost); |
| 469 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 470 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 471 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 472 | hq->entry_repost); |
| 473 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 474 | hq->host_index); |
| 475 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 476 | } else { |
| 477 | return -EINVAL; |
| 478 | } |
| 479 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 480 | } |
| 481 | return put_index; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 486 | * @q: The Header Receive Queue to operate on. |
| 487 | * |
| 488 | * This routine will update the HBA index of a queue to reflect consumption of |
| 489 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 490 | * consumed an entry the host calls this function to update the queue's |
| 491 | * internal pointers. This routine returns the number of entries that were |
| 492 | * consumed by the HBA. |
| 493 | **/ |
| 494 | static uint32_t |
| 495 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 496 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 497 | /* sanity check on queue memory */ |
| 498 | if (unlikely(!hq) || unlikely(!dq)) |
| 499 | return 0; |
| 500 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 501 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 502 | return 0; |
| 503 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 504 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 505 | return 1; |
| 506 | } |
| 507 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 508 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 509 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 510 | * @phba: Pointer to HBA context object. |
| 511 | * @pring: Pointer to driver SLI ring object. |
| 512 | * |
| 513 | * This function returns pointer to next command iocb entry |
| 514 | * in the command ring. The caller must hold hbalock to prevent |
| 515 | * other threads consume the next command iocb. |
| 516 | * SLI-2/SLI-3 provide different sized iocbs. |
| 517 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 518 | static inline IOCB_t * |
| 519 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 520 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 521 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 522 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 523 | } |
| 524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 525 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 526 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 527 | * @phba: Pointer to HBA context object. |
| 528 | * @pring: Pointer to driver SLI ring object. |
| 529 | * |
| 530 | * This function returns pointer to next response iocb entry |
| 531 | * in the response ring. The caller must hold hbalock to make sure |
| 532 | * that no other thread consume the next response iocb. |
| 533 | * SLI-2/SLI-3 provide different sized iocbs. |
| 534 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 535 | static inline IOCB_t * |
| 536 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 537 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 538 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 539 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 540 | } |
| 541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 543 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 544 | * @phba: Pointer to HBA context object. |
| 545 | * |
| 546 | * This function is called with hbalock held. This function |
| 547 | * allocates a new driver iocb object from the iocb pool. If the |
| 548 | * allocation is successful, it returns pointer to the newly |
| 549 | * allocated iocb object else it returns NULL. |
| 550 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 551 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 552 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 553 | { |
| 554 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 555 | struct lpfc_iocbq * iocbq = NULL; |
| 556 | |
| 557 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 558 | if (iocbq) |
| 559 | phba->iocb_cnt++; |
| 560 | if (phba->iocb_cnt > phba->iocb_max) |
| 561 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 562 | return iocbq; |
| 563 | } |
| 564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 565 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 566 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 567 | * @phba: Pointer to HBA context object. |
| 568 | * @xritag: XRI value. |
| 569 | * |
| 570 | * This function clears the sglq pointer from the array of acive |
| 571 | * sglq's. The xritag that is passed in is used to index into the |
| 572 | * array. Before the xritag can be used it needs to be adjusted |
| 573 | * by subtracting the xribase. |
| 574 | * |
| 575 | * Returns sglq ponter = success, NULL = Failure. |
| 576 | **/ |
| 577 | static struct lpfc_sglq * |
| 578 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 579 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 580 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 581 | |
| 582 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 583 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 584 | return sglq; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 589 | * @phba: Pointer to HBA context object. |
| 590 | * @xritag: XRI value. |
| 591 | * |
| 592 | * This function returns the sglq pointer from the array of acive |
| 593 | * sglq's. The xritag that is passed in is used to index into the |
| 594 | * array. Before the xritag can be used it needs to be adjusted |
| 595 | * by subtracting the xribase. |
| 596 | * |
| 597 | * Returns sglq ponter = success, NULL = Failure. |
| 598 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 599 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 600 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 601 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 602 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 603 | |
| 604 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 605 | return sglq; |
| 606 | } |
| 607 | |
| 608 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 609 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 610 | * @phba: Pointer to HBA context object. |
| 611 | * @xritag: xri used in this exchange. |
| 612 | * @rrq: The RRQ to be cleared. |
| 613 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 614 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 615 | void |
| 616 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 617 | uint16_t xritag, |
| 618 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 619 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 620 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 621 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 622 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 623 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 624 | |
| 625 | /* The target DID could have been swapped (cable swap) |
| 626 | * we should use the ndlp from the findnode if it is |
| 627 | * available. |
| 628 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 629 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 630 | ndlp = rrq->ndlp; |
| 631 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 632 | if (!ndlp) |
| 633 | goto out; |
| 634 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 635 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 636 | rrq->send_rrq = 0; |
| 637 | rrq->xritag = 0; |
| 638 | rrq->rrq_stop_time = 0; |
| 639 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 640 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 641 | mempool_free(rrq, phba->rrq_pool); |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 646 | * @phba: Pointer to HBA context object. |
| 647 | * |
| 648 | * This function is called with hbalock held. This function |
| 649 | * Checks if stop_time (ratov from setting rrq active) has |
| 650 | * been reached, if it has and the send_rrq flag is set then |
| 651 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 652 | * then it will just call the routine to clear the rrq and |
| 653 | * free the rrq resource. |
| 654 | * The timer is set to the next rrq that is going to expire before |
| 655 | * leaving the routine. |
| 656 | * |
| 657 | **/ |
| 658 | void |
| 659 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 660 | { |
| 661 | struct lpfc_node_rrq *rrq; |
| 662 | struct lpfc_node_rrq *nextrrq; |
| 663 | unsigned long next_time; |
| 664 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 665 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 666 | |
| 667 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 668 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 669 | next_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 670 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 671 | &phba->active_rrq_list, list) { |
| 672 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 673 | list_move(&rrq->list, &send_rrq); |
| 674 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 675 | next_time = rrq->rrq_stop_time; |
| 676 | } |
| 677 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 678 | if (!list_empty(&phba->active_rrq_list)) |
| 679 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 680 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 681 | list_del(&rrq->list); |
| 682 | if (!rrq->send_rrq) |
| 683 | /* this call will free the rrq */ |
| 684 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 685 | else if (lpfc_send_rrq(phba, rrq)) { |
| 686 | /* if we send the rrq then the completion handler |
| 687 | * will clear the bit in the xribitmap. |
| 688 | */ |
| 689 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 690 | rrq); |
| 691 | } |
| 692 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /** |
| 696 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 697 | * @vport: Pointer to vport context object. |
| 698 | * @xri: The xri used in the exchange. |
| 699 | * @did: The targets DID for this exchange. |
| 700 | * |
| 701 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 702 | * rrq = rrq for this xri and target. |
| 703 | **/ |
| 704 | struct lpfc_node_rrq * |
| 705 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 706 | { |
| 707 | struct lpfc_hba *phba = vport->phba; |
| 708 | struct lpfc_node_rrq *rrq; |
| 709 | struct lpfc_node_rrq *nextrrq; |
| 710 | unsigned long iflags; |
| 711 | |
| 712 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 713 | return NULL; |
| 714 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 715 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 716 | if (rrq->vport == vport && rrq->xritag == xri && |
| 717 | rrq->nlp_DID == did){ |
| 718 | list_del(&rrq->list); |
| 719 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 720 | return rrq; |
| 721 | } |
| 722 | } |
| 723 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 724 | return NULL; |
| 725 | } |
| 726 | |
| 727 | /** |
| 728 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 729 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 730 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 731 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 732 | * phba->active_rrq_list and clear the rrq. |
| 733 | * 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] | 734 | **/ |
| 735 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 736 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 737 | |
| 738 | { |
| 739 | struct lpfc_hba *phba = vport->phba; |
| 740 | struct lpfc_node_rrq *rrq; |
| 741 | struct lpfc_node_rrq *nextrrq; |
| 742 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 743 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 744 | |
| 745 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 746 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 747 | if (!ndlp) { |
| 748 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 749 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 750 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 751 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 752 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 753 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 754 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 755 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 756 | |
| 757 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 758 | list_del(&rrq->list); |
| 759 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 760 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | /** |
| 764 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. |
| 765 | * @phba: Pointer to HBA context object. |
| 766 | * |
| 767 | * Remove all rrqs from the phba->active_rrq_list and free them by |
| 768 | * calling __lpfc_clr_active_rrq |
| 769 | * |
| 770 | **/ |
| 771 | void |
| 772 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) |
| 773 | { |
| 774 | struct lpfc_node_rrq *rrq; |
| 775 | struct lpfc_node_rrq *nextrrq; |
| 776 | unsigned long next_time; |
| 777 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 778 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 779 | |
| 780 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 781 | return; |
| 782 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 783 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 784 | next_time = jiffies + HZ * (phba->fc_ratov * 2); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 785 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 786 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 787 | |
| 788 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 789 | list_del(&rrq->list); |
| 790 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 791 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 792 | if (!list_empty(&phba->active_rrq_list)) |
| 793 | mod_timer(&phba->rrq_tmr, next_time); |
| 794 | } |
| 795 | |
| 796 | |
| 797 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 798 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 799 | * @phba: Pointer to HBA context object. |
| 800 | * @ndlp: Targets nodelist pointer for this exchange. |
| 801 | * @xritag the xri in the bitmap to test. |
| 802 | * |
| 803 | * This function is called with hbalock held. This function |
| 804 | * returns 0 = rrq not active for this xri |
| 805 | * 1 = rrq is valid for this xri. |
| 806 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 807 | int |
| 808 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 809 | uint16_t xritag) |
| 810 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 811 | if (!ndlp) |
| 812 | return 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 813 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 814 | return 1; |
| 815 | else |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 821 | * @phba: Pointer to HBA context object. |
| 822 | * @ndlp: nodelist pointer for this target. |
| 823 | * @xritag: xri used in this exchange. |
| 824 | * @rxid: Remote Exchange ID. |
| 825 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 826 | * |
| 827 | * This function takes the hbalock. |
| 828 | * The active bit is always set in the active rrq xri_bitmap even |
| 829 | * if there is no slot avaiable for the other rrq information. |
| 830 | * |
| 831 | * returns 0 rrq actived for this xri |
| 832 | * < 0 No memory or invalid ndlp. |
| 833 | **/ |
| 834 | int |
| 835 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 836 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 837 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 838 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 839 | struct lpfc_node_rrq *rrq; |
| 840 | int empty; |
| 841 | |
| 842 | if (!ndlp) |
| 843 | return -EINVAL; |
| 844 | |
| 845 | if (!phba->cfg_enable_rrq) |
| 846 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 847 | |
| 848 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 849 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 850 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 851 | goto out; |
| 852 | } |
| 853 | |
| 854 | /* |
| 855 | * set the active bit even if there is no mem available. |
| 856 | */ |
| 857 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 858 | goto out; |
| 859 | |
| 860 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 861 | goto out; |
| 862 | |
| 863 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
| 864 | goto out; |
| 865 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 866 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 867 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 868 | if (!rrq) { |
| 869 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 870 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 871 | " DID:0x%x Send:%d\n", |
| 872 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 873 | return -EINVAL; |
| 874 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 875 | if (phba->cfg_enable_rrq == 1) |
| 876 | rrq->send_rrq = send_rrq; |
| 877 | else |
| 878 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 879 | rrq->xritag = xritag; |
| 880 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 881 | rrq->ndlp = ndlp; |
| 882 | rrq->nlp_DID = ndlp->nlp_DID; |
| 883 | rrq->vport = ndlp->vport; |
| 884 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 885 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 886 | empty = list_empty(&phba->active_rrq_list); |
| 887 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 888 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 889 | if (empty) |
| 890 | lpfc_worker_wake_up(phba); |
| 891 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 892 | return 0; |
| 893 | out: |
| 894 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 895 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 896 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 897 | " DID:0x%x Send:%d\n", |
| 898 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 899 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 903 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 904 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 905 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 906 | * |
| 907 | * This function is called with hbalock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 908 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 909 | * list is not empty then it is successful, it returns pointer to the newly |
| 910 | * allocated sglq object else it returns NULL. |
| 911 | **/ |
| 912 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 913 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 914 | { |
| 915 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 916 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 917 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 918 | struct lpfc_scsi_buf *lpfc_cmd; |
| 919 | struct lpfc_nodelist *ndlp; |
| 920 | int found = 0; |
| 921 | |
| 922 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 923 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 924 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 925 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
| 926 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 927 | ndlp = piocbq->context_un.ndlp; |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 928 | else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) && |
| 929 | (piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 930 | ndlp = piocbq->context_un.ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 931 | else |
| 932 | ndlp = piocbq->context1; |
| 933 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 934 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 935 | start_sglq = sglq; |
| 936 | while (!found) { |
| 937 | if (!sglq) |
| 938 | return NULL; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 939 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 940 | /* This xri has an rrq outstanding for this DID. |
| 941 | * put it back in the list and get another xri. |
| 942 | */ |
| 943 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 944 | sglq = NULL; |
| 945 | list_remove_head(lpfc_sgl_list, sglq, |
| 946 | struct lpfc_sglq, list); |
| 947 | if (sglq == start_sglq) { |
| 948 | sglq = NULL; |
| 949 | break; |
| 950 | } else |
| 951 | continue; |
| 952 | } |
| 953 | sglq->ndlp = ndlp; |
| 954 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 955 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 956 | sglq->state = SGL_ALLOCATED; |
| 957 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 958 | return sglq; |
| 959 | } |
| 960 | |
| 961 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 962 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 963 | * @phba: Pointer to HBA context object. |
| 964 | * |
| 965 | * This function is called with no lock held. This function |
| 966 | * allocates a new driver iocb object from the iocb pool. If the |
| 967 | * allocation is successful, it returns pointer to the newly |
| 968 | * allocated iocb object else it returns NULL. |
| 969 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 970 | struct lpfc_iocbq * |
| 971 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 972 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 973 | struct lpfc_iocbq * iocbq = NULL; |
| 974 | unsigned long iflags; |
| 975 | |
| 976 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 977 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 978 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 979 | return iocbq; |
| 980 | } |
| 981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 982 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 983 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 984 | * @phba: Pointer to HBA context object. |
| 985 | * @iocbq: Pointer to driver iocb object. |
| 986 | * |
| 987 | * This function is called with hbalock held to release driver |
| 988 | * iocb object to the iocb pool. The iotag in the iocb object |
| 989 | * does not change for each use of the iocb object. This function |
| 990 | * clears all other fields of the iocb object when it is freed. |
| 991 | * The sqlq structure that holds the xritag and phys and virtual |
| 992 | * mappings for the scatter gather list is retrieved from the |
| 993 | * active array of sglq. The get of the sglq pointer also clears |
| 994 | * the entry in the array. If the status of the IO indiactes that |
| 995 | * this IO was aborted then the sglq entry it put on the |
| 996 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 997 | * IO has good status or fails for any other reason then the sglq |
| 998 | * entry is added to the free list (lpfc_sgl_list). |
| 999 | **/ |
| 1000 | static void |
| 1001 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1002 | { |
| 1003 | struct lpfc_sglq *sglq; |
| 1004 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1005 | unsigned long iflag = 0; |
| 1006 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1007 | |
| 1008 | if (iocbq->sli4_xritag == NO_XRI) |
| 1009 | sglq = NULL; |
| 1010 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1011 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1012 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1013 | /* |
| 1014 | ** This should have been removed from the txcmplq before calling |
| 1015 | ** iocbq_release. The normal completion |
| 1016 | ** path should have already done the list_del_init. |
| 1017 | */ |
| 1018 | if (unlikely(!list_empty(&iocbq->list))) { |
| 1019 | if (iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ) |
| 1020 | iocbq->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
| 1021 | list_del_init(&iocbq->list); |
| 1022 | } |
| 1023 | |
| 1024 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1025 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1026 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1027 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1028 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 1029 | iflag); |
| 1030 | list_add(&sglq->list, |
| 1031 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 1032 | spin_unlock_irqrestore( |
| 1033 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1034 | } else { |
| 1035 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1036 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1037 | list_add_tail(&sglq->list, |
| 1038 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1039 | |
| 1040 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1041 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1042 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1043 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | |
| 1047 | /* |
| 1048 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1049 | */ |
| 1050 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1051 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1052 | iocbq->sli4_xritag = NO_XRI; |
| 1053 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1054 | } |
| 1055 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1056 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1057 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1058 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1059 | * @phba: Pointer to HBA context object. |
| 1060 | * @iocbq: Pointer to driver iocb object. |
| 1061 | * |
| 1062 | * This function is called with hbalock held to release driver |
| 1063 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1064 | * does not change for each use of the iocb object. This function |
| 1065 | * clears all other fields of the iocb object when it is freed. |
| 1066 | **/ |
| 1067 | static void |
| 1068 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1069 | { |
| 1070 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1071 | |
| 1072 | /* |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1073 | ** This should have been removed from the txcmplq before calling |
| 1074 | ** iocbq_release. The normal completion |
| 1075 | ** path should have already done the list_del_init. |
| 1076 | */ |
| 1077 | if (unlikely(!list_empty(&iocbq->list))) |
| 1078 | list_del_init(&iocbq->list); |
| 1079 | |
| 1080 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1081 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1082 | */ |
| 1083 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1084 | iocbq->sli4_xritag = NO_XRI; |
| 1085 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1086 | } |
| 1087 | |
| 1088 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1089 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1090 | * @phba: Pointer to HBA context object. |
| 1091 | * @iocbq: Pointer to driver iocb object. |
| 1092 | * |
| 1093 | * This function is called with hbalock held to release driver |
| 1094 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1095 | * does not change for each use of the iocb object. This function |
| 1096 | * clears all other fields of the iocb object when it is freed. |
| 1097 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1098 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1099 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1100 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1101 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1102 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1103 | } |
| 1104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1105 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1106 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1107 | * @phba: Pointer to HBA context object. |
| 1108 | * @iocbq: Pointer to driver iocb object. |
| 1109 | * |
| 1110 | * This function is called with no lock held to release the iocb to |
| 1111 | * iocb pool. |
| 1112 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1113 | void |
| 1114 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1115 | { |
| 1116 | unsigned long iflags; |
| 1117 | |
| 1118 | /* |
| 1119 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1120 | */ |
| 1121 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1122 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1123 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1124 | } |
| 1125 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1126 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1127 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1128 | * @phba: Pointer to HBA context object. |
| 1129 | * @iocblist: List of IOCBs. |
| 1130 | * @ulpstatus: ULP status in IOCB command field. |
| 1131 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1132 | * |
| 1133 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1134 | * on the list by invoking the complete callback function associated with the |
| 1135 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1136 | * fields. |
| 1137 | **/ |
| 1138 | void |
| 1139 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1140 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1141 | { |
| 1142 | struct lpfc_iocbq *piocb; |
| 1143 | |
| 1144 | while (!list_empty(iocblist)) { |
| 1145 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1146 | if (!piocb->iocb_cmpl) |
| 1147 | lpfc_sli_release_iocbq(phba, piocb); |
| 1148 | else { |
| 1149 | piocb->iocb.ulpStatus = ulpstatus; |
| 1150 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1151 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1152 | } |
| 1153 | } |
| 1154 | return; |
| 1155 | } |
| 1156 | |
| 1157 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1158 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1159 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1160 | * |
| 1161 | * This function is called by ring event handler function to get the iocb type. |
| 1162 | * This function translates the iocb command to an iocb command type used to |
| 1163 | * decide the final disposition of each completed IOCB. |
| 1164 | * The function returns |
| 1165 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1166 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1167 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1168 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1169 | * |
| 1170 | * The caller is not required to hold any lock. |
| 1171 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1172 | static lpfc_iocb_type |
| 1173 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1174 | { |
| 1175 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1176 | |
| 1177 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1178 | return 0; |
| 1179 | |
| 1180 | switch (iocb_cmnd) { |
| 1181 | case CMD_XMIT_SEQUENCE_CR: |
| 1182 | case CMD_XMIT_SEQUENCE_CX: |
| 1183 | case CMD_XMIT_BCAST_CN: |
| 1184 | case CMD_XMIT_BCAST_CX: |
| 1185 | case CMD_ELS_REQUEST_CR: |
| 1186 | case CMD_ELS_REQUEST_CX: |
| 1187 | case CMD_CREATE_XRI_CR: |
| 1188 | case CMD_CREATE_XRI_CX: |
| 1189 | case CMD_GET_RPI_CN: |
| 1190 | case CMD_XMIT_ELS_RSP_CX: |
| 1191 | case CMD_GET_RPI_CR: |
| 1192 | case CMD_FCP_IWRITE_CR: |
| 1193 | case CMD_FCP_IWRITE_CX: |
| 1194 | case CMD_FCP_IREAD_CR: |
| 1195 | case CMD_FCP_IREAD_CX: |
| 1196 | case CMD_FCP_ICMND_CR: |
| 1197 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1198 | case CMD_FCP_TSEND_CX: |
| 1199 | case CMD_FCP_TRSP_CX: |
| 1200 | case CMD_FCP_TRECEIVE_CX: |
| 1201 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1202 | case CMD_ADAPTER_MSG: |
| 1203 | case CMD_ADAPTER_DUMP: |
| 1204 | case CMD_XMIT_SEQUENCE64_CR: |
| 1205 | case CMD_XMIT_SEQUENCE64_CX: |
| 1206 | case CMD_XMIT_BCAST64_CN: |
| 1207 | case CMD_XMIT_BCAST64_CX: |
| 1208 | case CMD_ELS_REQUEST64_CR: |
| 1209 | case CMD_ELS_REQUEST64_CX: |
| 1210 | case CMD_FCP_IWRITE64_CR: |
| 1211 | case CMD_FCP_IWRITE64_CX: |
| 1212 | case CMD_FCP_IREAD64_CR: |
| 1213 | case CMD_FCP_IREAD64_CX: |
| 1214 | case CMD_FCP_ICMND64_CR: |
| 1215 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1216 | case CMD_FCP_TSEND64_CX: |
| 1217 | case CMD_FCP_TRSP64_CX: |
| 1218 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | case CMD_GEN_REQUEST64_CR: |
| 1220 | case CMD_GEN_REQUEST64_CX: |
| 1221 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1222 | case DSSCMD_IWRITE64_CR: |
| 1223 | case DSSCMD_IWRITE64_CX: |
| 1224 | case DSSCMD_IREAD64_CR: |
| 1225 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | type = LPFC_SOL_IOCB; |
| 1227 | break; |
| 1228 | case CMD_ABORT_XRI_CN: |
| 1229 | case CMD_ABORT_XRI_CX: |
| 1230 | case CMD_CLOSE_XRI_CN: |
| 1231 | case CMD_CLOSE_XRI_CX: |
| 1232 | case CMD_XRI_ABORTED_CX: |
| 1233 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1234 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1235 | type = LPFC_ABORT_IOCB; |
| 1236 | break; |
| 1237 | case CMD_RCV_SEQUENCE_CX: |
| 1238 | case CMD_RCV_ELS_REQ_CX: |
| 1239 | case CMD_RCV_SEQUENCE64_CX: |
| 1240 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1241 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1242 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1243 | case CMD_IOCB_RCV_ELS64_CX: |
| 1244 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1245 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1246 | type = LPFC_UNSOL_IOCB; |
| 1247 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1248 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1249 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1250 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1251 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1252 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1253 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1254 | case CMD_IOCB_RET_HBQE64_CN: |
| 1255 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1256 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1257 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1258 | case CMD_IOCB_LOGENTRY_CN: |
| 1259 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1260 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1261 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1262 | type = LPFC_UNKNOWN_IOCB; |
| 1263 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | default: |
| 1265 | type = LPFC_UNKNOWN_IOCB; |
| 1266 | break; |
| 1267 | } |
| 1268 | |
| 1269 | return type; |
| 1270 | } |
| 1271 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1272 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1273 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1274 | * @phba: Pointer to HBA context object. |
| 1275 | * |
| 1276 | * This function is called from SLI initialization code |
| 1277 | * to configure every ring of the HBA's SLI interface. The |
| 1278 | * caller is not required to hold any lock. This function issues |
| 1279 | * a config_ring mailbox command for each ring. |
| 1280 | * This function returns zero if successful else returns a negative |
| 1281 | * error code. |
| 1282 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1284 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | { |
| 1286 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1287 | LPFC_MBOXQ_t *pmb; |
| 1288 | MAILBOX_t *pmbox; |
| 1289 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1291 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1292 | if (!pmb) |
| 1293 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1294 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1295 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | lpfc_config_ring(phba, i, pmb); |
| 1298 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1299 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1300 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1301 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1302 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1303 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1304 | rc, pmbox->mbxCommand, |
| 1305 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1306 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1307 | ret = -ENXIO; |
| 1308 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1309 | } |
| 1310 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1311 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1312 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1313 | } |
| 1314 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1316 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1317 | * @phba: Pointer to HBA context object. |
| 1318 | * @pring: Pointer to driver SLI ring object. |
| 1319 | * @piocb: Pointer to the driver iocb object. |
| 1320 | * |
| 1321 | * This function is called with hbalock held. The function adds the |
| 1322 | * new iocb to txcmplq of the given ring. This function always returns |
| 1323 | * 0. If this function is called for ELS ring, this function checks if |
| 1324 | * there is a vport associated with the ELS command. This function also |
| 1325 | * starts els_tmofunc timer if this is an ELS command. |
| 1326 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1327 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1328 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1329 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1330 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1331 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1332 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1333 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1334 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1335 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 1336 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1337 | if (!piocb->vport) |
| 1338 | BUG(); |
| 1339 | else |
| 1340 | mod_timer(&piocb->vport->els_tmofunc, |
| 1341 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 1342 | } |
| 1343 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1344 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1345 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1346 | } |
| 1347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1349 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1350 | * @phba: Pointer to HBA context object. |
| 1351 | * @pring: Pointer to driver SLI ring object. |
| 1352 | * |
| 1353 | * This function is called with hbalock held to get next |
| 1354 | * iocb in txq of the given ring. If there is any iocb in |
| 1355 | * the txq, the function returns first iocb in the list after |
| 1356 | * removing the iocb from the list, else it returns NULL. |
| 1357 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1358 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1359 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1360 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1361 | struct lpfc_iocbq *cmd_iocb; |
| 1362 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1363 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1364 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1365 | } |
| 1366 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1367 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1368 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1369 | * @phba: Pointer to HBA context object. |
| 1370 | * @pring: Pointer to driver SLI ring object. |
| 1371 | * |
| 1372 | * This function is called with hbalock held and the caller must post the |
| 1373 | * iocb without releasing the lock. If the caller releases the lock, |
| 1374 | * iocb slot returned by the function is not guaranteed to be available. |
| 1375 | * The function returns pointer to the next available iocb slot if there |
| 1376 | * is available slot in the ring, else it returns NULL. |
| 1377 | * If the get index of the ring is ahead of the put index, the function |
| 1378 | * will post an error attention event to the worker thread to take the |
| 1379 | * HBA to offline state. |
| 1380 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1381 | static IOCB_t * |
| 1382 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1383 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1384 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1385 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
| 1386 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1387 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1388 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1390 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1391 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1392 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1393 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1394 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1395 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1396 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1397 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1398 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1399 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1400 | pring->sli.sli3.local_getidx, |
| 1401 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1402 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1403 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1404 | /* |
| 1405 | * All error attention handlers are posted to |
| 1406 | * worker thread |
| 1407 | */ |
| 1408 | phba->work_ha |= HA_ERATT; |
| 1409 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1410 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1411 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1412 | |
| 1413 | return NULL; |
| 1414 | } |
| 1415 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1416 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | return NULL; |
| 1418 | } |
| 1419 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1420 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1421 | } |
| 1422 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1424 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1425 | * @phba: Pointer to HBA context object. |
| 1426 | * @iocbq: Pointer to driver iocb object. |
| 1427 | * |
| 1428 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1429 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1430 | * array and assigns a new iotag. |
| 1431 | * The function returns the allocated iotag if successful, else returns zero. |
| 1432 | * Zero is not a valid iotag. |
| 1433 | * The caller is not required to hold any lock. |
| 1434 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1435 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1436 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1437 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1438 | struct lpfc_iocbq **new_arr; |
| 1439 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1440 | size_t new_len; |
| 1441 | struct lpfc_sli *psli = &phba->sli; |
| 1442 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1444 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1445 | iotag = psli->last_iotag; |
| 1446 | if(++iotag < psli->iocbq_lookup_len) { |
| 1447 | psli->last_iotag = iotag; |
| 1448 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1449 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1450 | iocbq->iotag = iotag; |
| 1451 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1452 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1453 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1454 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1455 | spin_unlock_irq(&phba->hbalock); |
| 1456 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1457 | GFP_KERNEL); |
| 1458 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1459 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1460 | old_arr = psli->iocbq_lookup; |
| 1461 | if (new_len <= psli->iocbq_lookup_len) { |
| 1462 | /* highly unprobable case */ |
| 1463 | kfree(new_arr); |
| 1464 | iotag = psli->last_iotag; |
| 1465 | if(++iotag < psli->iocbq_lookup_len) { |
| 1466 | psli->last_iotag = iotag; |
| 1467 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1468 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1469 | iocbq->iotag = iotag; |
| 1470 | return iotag; |
| 1471 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1472 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1473 | return 0; |
| 1474 | } |
| 1475 | if (psli->iocbq_lookup) |
| 1476 | memcpy(new_arr, old_arr, |
| 1477 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1478 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1479 | psli->iocbq_lookup = new_arr; |
| 1480 | psli->iocbq_lookup_len = new_len; |
| 1481 | psli->last_iotag = iotag; |
| 1482 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1483 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1484 | iocbq->iotag = iotag; |
| 1485 | kfree(old_arr); |
| 1486 | return iotag; |
| 1487 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1488 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1489 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1491 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1492 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1493 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1494 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1495 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | } |
| 1497 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1498 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1499 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1500 | * @phba: Pointer to HBA context object. |
| 1501 | * @pring: Pointer to driver SLI ring object. |
| 1502 | * @iocb: Pointer to iocb slot in the ring. |
| 1503 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1504 | * posted to firmware. |
| 1505 | * |
| 1506 | * This function is called with hbalock held to post a new iocb to |
| 1507 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1508 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1509 | * a completion call back for this iocb else the function will free the |
| 1510 | * iocb object. |
| 1511 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | static void |
| 1513 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1514 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1515 | { |
| 1516 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1517 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1519 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1520 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1521 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1522 | if (pring->ringno == LPFC_ELS_RING) { |
| 1523 | lpfc_debugfs_slow_ring_trc(phba, |
| 1524 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1525 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1526 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1527 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1528 | } |
| 1529 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1530 | /* |
| 1531 | * Issue iocb command to adapter |
| 1532 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1533 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | wmb(); |
| 1535 | pring->stats.iocb_cmd++; |
| 1536 | |
| 1537 | /* |
| 1538 | * If there is no completion routine to call, we can release the |
| 1539 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1540 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1541 | */ |
| 1542 | if (nextiocb->iocb_cmpl) |
| 1543 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1544 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1545 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | |
| 1547 | /* |
| 1548 | * Let the HBA know what IOCB slot will be the next one the |
| 1549 | * driver will put a command into. |
| 1550 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1551 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1552 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | } |
| 1554 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1555 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1556 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1557 | * @phba: Pointer to HBA context object. |
| 1558 | * @pring: Pointer to driver SLI ring object. |
| 1559 | * |
| 1560 | * The caller is not required to hold any lock for calling this function. |
| 1561 | * This function updates the chip attention bits for the ring to inform firmware |
| 1562 | * that there are pending work to be done for this ring and requests an |
| 1563 | * interrupt when there is space available in the ring. This function is |
| 1564 | * called when the driver is unable to post more iocbs to the ring due |
| 1565 | * to unavailability of space in the ring. |
| 1566 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1567 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1568 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1569 | { |
| 1570 | int ringno = pring->ringno; |
| 1571 | |
| 1572 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1573 | |
| 1574 | wmb(); |
| 1575 | |
| 1576 | /* |
| 1577 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1578 | * The HBA will tell us when an IOCB entry is available. |
| 1579 | */ |
| 1580 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1581 | readl(phba->CAregaddr); /* flush */ |
| 1582 | |
| 1583 | pring->stats.iocb_cmd_full++; |
| 1584 | } |
| 1585 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1586 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1587 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1588 | * @phba: Pointer to HBA context object. |
| 1589 | * @pring: Pointer to driver SLI ring object. |
| 1590 | * |
| 1591 | * This function updates the chip attention register bit for the |
| 1592 | * given ring to inform HBA that there is more work to be done |
| 1593 | * in this ring. The caller is not required to hold any lock. |
| 1594 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1595 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1596 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1597 | { |
| 1598 | int ringno = pring->ringno; |
| 1599 | |
| 1600 | /* |
| 1601 | * Tell the HBA that there is work to do in this ring. |
| 1602 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1603 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1604 | wmb(); |
| 1605 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1606 | readl(phba->CAregaddr); /* flush */ |
| 1607 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1608 | } |
| 1609 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1610 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1611 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1612 | * @phba: Pointer to HBA context object. |
| 1613 | * @pring: Pointer to driver SLI ring object. |
| 1614 | * |
| 1615 | * This function is called with hbalock held to post pending iocbs |
| 1616 | * in the txq to the firmware. This function is called when driver |
| 1617 | * detects space available in the ring. |
| 1618 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1619 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1620 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | { |
| 1622 | IOCB_t *iocb; |
| 1623 | struct lpfc_iocbq *nextiocb; |
| 1624 | |
| 1625 | /* |
| 1626 | * Check to see if: |
| 1627 | * (a) there is anything on the txq to send |
| 1628 | * (b) link is up |
| 1629 | * (c) link attention events can be processed (fcp ring only) |
| 1630 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1631 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1632 | |
| 1633 | if (lpfc_is_link_up(phba) && |
| 1634 | (!list_empty(&pring->txq)) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1636 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1637 | |
| 1638 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1639 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1640 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1641 | |
| 1642 | if (iocb) |
| 1643 | lpfc_sli_update_ring(phba, pring); |
| 1644 | else |
| 1645 | lpfc_sli_update_full_ring(phba, pring); |
| 1646 | } |
| 1647 | |
| 1648 | return; |
| 1649 | } |
| 1650 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1651 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1652 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1653 | * @phba: Pointer to HBA context object. |
| 1654 | * @hbqno: HBQ number. |
| 1655 | * |
| 1656 | * This function is called with hbalock held to get the next |
| 1657 | * available slot for the given HBQ. If there is free slot |
| 1658 | * available for the HBQ it will return pointer to the next available |
| 1659 | * HBQ entry else it will return NULL. |
| 1660 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1661 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1662 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1663 | { |
| 1664 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1665 | |
| 1666 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1667 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1668 | hbqp->next_hbqPutIdx = 0; |
| 1669 | |
| 1670 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1671 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1672 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1673 | |
| 1674 | hbqp->local_hbqGetIdx = getidx; |
| 1675 | |
| 1676 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1677 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1678 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1679 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1680 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1681 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1682 | hbqp->entry_count); |
| 1683 | |
| 1684 | phba->link_state = LPFC_HBA_ERROR; |
| 1685 | return NULL; |
| 1686 | } |
| 1687 | |
| 1688 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1689 | return NULL; |
| 1690 | } |
| 1691 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1692 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1693 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1694 | } |
| 1695 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1696 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1697 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1698 | * @phba: Pointer to HBA context object. |
| 1699 | * |
| 1700 | * This function is called with no lock held to free all the |
| 1701 | * hbq buffers while uninitializing the SLI interface. It also |
| 1702 | * frees the HBQ buffers returned by the firmware but not yet |
| 1703 | * processed by the upper layers. |
| 1704 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1705 | void |
| 1706 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1707 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1708 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1709 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1710 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1711 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1712 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1713 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1714 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1715 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1716 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1717 | for (i = 0; i < hbq_count; ++i) { |
| 1718 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1719 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1720 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1721 | list_del(&hbq_buf->dbuf.list); |
| 1722 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1723 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1724 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1725 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1726 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1727 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1728 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1729 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1730 | list_del(&hbq_buf->dbuf.list); |
| 1731 | if (hbq_buf->tag == -1) { |
| 1732 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1733 | (phba, hbq_buf); |
| 1734 | } else { |
| 1735 | hbqno = hbq_buf->tag >> 16; |
| 1736 | if (hbqno >= LPFC_MAX_HBQS) |
| 1737 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1738 | (phba, hbq_buf); |
| 1739 | else |
| 1740 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1741 | hbq_buf); |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | /* Mark the HBQs not in use */ |
| 1746 | phba->hbq_in_use = 0; |
| 1747 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1748 | } |
| 1749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1750 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1751 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1752 | * @phba: Pointer to HBA context object. |
| 1753 | * @hbqno: HBQ number. |
| 1754 | * @hbq_buf: Pointer to HBQ buffer. |
| 1755 | * |
| 1756 | * This function is called with the hbalock held to post a |
| 1757 | * hbq buffer to the firmware. If the function finds an empty |
| 1758 | * slot in the HBQ, it will post the buffer. The function will return |
| 1759 | * pointer to the hbq entry if it successfully post the buffer |
| 1760 | * else it will return NULL. |
| 1761 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1762 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1763 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1764 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1765 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1766 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1767 | } |
| 1768 | |
| 1769 | /** |
| 1770 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1771 | * @phba: Pointer to HBA context object. |
| 1772 | * @hbqno: HBQ number. |
| 1773 | * @hbq_buf: Pointer to HBQ buffer. |
| 1774 | * |
| 1775 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1776 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1777 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1778 | * it successfully post the buffer else it will return an error. |
| 1779 | **/ |
| 1780 | static int |
| 1781 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1782 | struct hbq_dmabuf *hbq_buf) |
| 1783 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1784 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1785 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1786 | |
| 1787 | /* Get next HBQ entry slot to use */ |
| 1788 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1789 | if (hbqe) { |
| 1790 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1791 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1792 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1793 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1794 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1795 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1796 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1797 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1798 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1799 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1800 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1801 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1802 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1803 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1804 | return 0; |
| 1805 | } else |
| 1806 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1807 | } |
| 1808 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1809 | /** |
| 1810 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1811 | * @phba: Pointer to HBA context object. |
| 1812 | * @hbqno: HBQ number. |
| 1813 | * @hbq_buf: Pointer to HBQ buffer. |
| 1814 | * |
| 1815 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1816 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1817 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1818 | **/ |
| 1819 | static int |
| 1820 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1821 | struct hbq_dmabuf *hbq_buf) |
| 1822 | { |
| 1823 | int rc; |
| 1824 | struct lpfc_rqe hrqe; |
| 1825 | struct lpfc_rqe drqe; |
| 1826 | |
| 1827 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1828 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1829 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1830 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1831 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1832 | &hrqe, &drqe); |
| 1833 | if (rc < 0) |
| 1834 | return rc; |
| 1835 | hbq_buf->tag = rc; |
| 1836 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1840 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1841 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1842 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1843 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1844 | .mask_count = 0, |
| 1845 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1846 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1847 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1848 | .init_count = 40, |
| 1849 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1850 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1851 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1852 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1853 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1854 | .rn = 1, |
| 1855 | .entry_count = 200, |
| 1856 | .mask_count = 0, |
| 1857 | .profile = 0, |
| 1858 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1859 | .buffer_count = 0, |
| 1860 | .init_count = 0, |
| 1861 | .add_count = 5, |
| 1862 | }; |
| 1863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1864 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1865 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1866 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1867 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1868 | }; |
| 1869 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1870 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1871 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1872 | * @phba: Pointer to HBA context object. |
| 1873 | * @hbqno: HBQ number. |
| 1874 | * @count: Number of HBQ buffers to be posted. |
| 1875 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1876 | * This function is called with no lock held to post more hbq buffers to the |
| 1877 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1878 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1879 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1880 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1881 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1882 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1883 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1884 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1885 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1886 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1887 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1888 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1889 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1890 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1891 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1892 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1893 | phba->hbqs[hbqno].buffer_count; |
| 1894 | if (!count) |
| 1895 | return 0; |
| 1896 | /* Allocate HBQ entries */ |
| 1897 | for (i = 0; i < count; i++) { |
| 1898 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1899 | if (!hbq_buffer) |
| 1900 | break; |
| 1901 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1902 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1903 | /* Check whether HBQ is still in use */ |
| 1904 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1905 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1906 | goto err; |
| 1907 | while (!list_empty(&hbq_buf_list)) { |
| 1908 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1909 | dbuf.list); |
| 1910 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1911 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1912 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1913 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1914 | posted++; |
| 1915 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1916 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1917 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1918 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1919 | return posted; |
| 1920 | err: |
| 1921 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1922 | while (!list_empty(&hbq_buf_list)) { |
| 1923 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1924 | dbuf.list); |
| 1925 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1926 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1927 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1928 | } |
| 1929 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1930 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1931 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1932 | * @phba: Pointer to HBA context object. |
| 1933 | * @qno: HBQ number. |
| 1934 | * |
| 1935 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1936 | * is called with no lock held. The function returns the number of HBQ entries |
| 1937 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1938 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1939 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1940 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1941 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1942 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1943 | return 0; |
| 1944 | else |
| 1945 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1946 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1947 | } |
| 1948 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1949 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1950 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1951 | * @phba: Pointer to HBA context object. |
| 1952 | * @qno: HBQ queue number. |
| 1953 | * |
| 1954 | * This function is called from SLI initialization code path with |
| 1955 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1956 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1957 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1958 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1959 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1960 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1961 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1962 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1963 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1964 | else |
| 1965 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1966 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1967 | } |
| 1968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1969 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1970 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1971 | * @phba: Pointer to HBA context object. |
| 1972 | * @hbqno: HBQ number. |
| 1973 | * |
| 1974 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1975 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1976 | **/ |
| 1977 | static struct hbq_dmabuf * |
| 1978 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1979 | { |
| 1980 | struct lpfc_dmabuf *d_buf; |
| 1981 | |
| 1982 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1983 | if (!d_buf) |
| 1984 | return NULL; |
| 1985 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1986 | } |
| 1987 | |
| 1988 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1989 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1990 | * @phba: Pointer to HBA context object. |
| 1991 | * @tag: Tag of the hbq buffer. |
| 1992 | * |
| 1993 | * This function is called with hbalock held. This function searches |
| 1994 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1995 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1996 | * it returns NULL. |
| 1997 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1998 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1999 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2000 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2001 | struct lpfc_dmabuf *d_buf; |
| 2002 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2003 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2004 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2005 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2006 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2007 | return NULL; |
| 2008 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2009 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2010 | 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] | 2011 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2012 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2013 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2014 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2015 | } |
| 2016 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2017 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2018 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2019 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2020 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2021 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2022 | } |
| 2023 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2024 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2025 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2026 | * @phba: Pointer to HBA context object. |
| 2027 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2028 | * |
| 2029 | * This function is called with hbalock. This function gives back |
| 2030 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2031 | * post the buffer, it will free the buffer. |
| 2032 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2033 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2034 | 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] | 2035 | { |
| 2036 | uint32_t hbqno; |
| 2037 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2038 | if (hbq_buffer) { |
| 2039 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2040 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2041 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2045 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2046 | * 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] | 2047 | * @mbxCommand: mailbox command code. |
| 2048 | * |
| 2049 | * This function is called by the mailbox event handler function to verify |
| 2050 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2051 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2052 | * and the mailbox event handler will take the HBA offline. |
| 2053 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | static int |
| 2055 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2056 | { |
| 2057 | uint8_t ret; |
| 2058 | |
| 2059 | switch (mbxCommand) { |
| 2060 | case MBX_LOAD_SM: |
| 2061 | case MBX_READ_NV: |
| 2062 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2063 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | case MBX_RUN_BIU_DIAG: |
| 2065 | case MBX_INIT_LINK: |
| 2066 | case MBX_DOWN_LINK: |
| 2067 | case MBX_CONFIG_LINK: |
| 2068 | case MBX_CONFIG_RING: |
| 2069 | case MBX_RESET_RING: |
| 2070 | case MBX_READ_CONFIG: |
| 2071 | case MBX_READ_RCONFIG: |
| 2072 | case MBX_READ_SPARM: |
| 2073 | case MBX_READ_STATUS: |
| 2074 | case MBX_READ_RPI: |
| 2075 | case MBX_READ_XRI: |
| 2076 | case MBX_READ_REV: |
| 2077 | case MBX_READ_LNK_STAT: |
| 2078 | case MBX_REG_LOGIN: |
| 2079 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2080 | case MBX_CLEAR_LA: |
| 2081 | case MBX_DUMP_MEMORY: |
| 2082 | case MBX_DUMP_CONTEXT: |
| 2083 | case MBX_RUN_DIAGS: |
| 2084 | case MBX_RESTART: |
| 2085 | case MBX_UPDATE_CFG: |
| 2086 | case MBX_DOWN_LOAD: |
| 2087 | case MBX_DEL_LD_ENTRY: |
| 2088 | case MBX_RUN_PROGRAM: |
| 2089 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2090 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2092 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2094 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | case MBX_LOAD_AREA: |
| 2096 | case MBX_RUN_BIU_DIAG64: |
| 2097 | case MBX_CONFIG_PORT: |
| 2098 | case MBX_READ_SPARM64: |
| 2099 | case MBX_READ_RPI64: |
| 2100 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2101 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2102 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | case MBX_SET_DEBUG: |
| 2104 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2105 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2106 | case MBX_REG_VPI: |
| 2107 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2108 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2109 | case MBX_PORT_CAPABILITIES: |
| 2110 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2111 | case MBX_SLI4_CONFIG: |
| 2112 | case MBX_SLI4_REQ_FTRS: |
| 2113 | case MBX_REG_FCFI: |
| 2114 | case MBX_UNREG_FCFI: |
| 2115 | case MBX_REG_VFI: |
| 2116 | case MBX_UNREG_VFI: |
| 2117 | case MBX_INIT_VPI: |
| 2118 | case MBX_INIT_VFI: |
| 2119 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2120 | case MBX_READ_EVENT_LOG_STATUS: |
| 2121 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2122 | case MBX_SECURITY_MGMT: |
| 2123 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2124 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | ret = mbxCommand; |
| 2126 | break; |
| 2127 | default: |
| 2128 | ret = MBX_SHUTDOWN; |
| 2129 | break; |
| 2130 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2131 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2133 | |
| 2134 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2135 | * 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] | 2136 | * @phba: Pointer to HBA context object. |
| 2137 | * @pmboxq: Pointer to mailbox command. |
| 2138 | * |
| 2139 | * This is completion handler function for mailbox commands issued from |
| 2140 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2141 | * mailbox event handler function with no lock held. This function |
| 2142 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2143 | * of the mailbox. |
| 2144 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2145 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2146 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | { |
| 2148 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2149 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | |
| 2151 | /* |
| 2152 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2153 | * continued running. |
| 2154 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2155 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2156 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2158 | if (pdone_q) |
| 2159 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2160 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2161 | return; |
| 2162 | } |
| 2163 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2164 | |
| 2165 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2166 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2167 | * @phba: Pointer to HBA context object. |
| 2168 | * @pmb: Pointer to mailbox object. |
| 2169 | * |
| 2170 | * This function is the default mailbox completion handler. It |
| 2171 | * frees the memory resources associated with the completed mailbox |
| 2172 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2173 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2174 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2176 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2178 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2180 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2181 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2182 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2183 | int rc; |
| 2184 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2185 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2186 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2187 | if (mp) { |
| 2188 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2189 | kfree(mp); |
| 2190 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2191 | |
| 2192 | /* |
| 2193 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2194 | * is in re-discovery driver need to cleanup the RPI. |
| 2195 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2196 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2197 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2198 | !pmb->u.mb.mbxStatus) { |
| 2199 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2200 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2201 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2202 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2203 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2204 | if (rc != MBX_NOT_FINISHED) |
| 2205 | return; |
| 2206 | } |
| 2207 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2208 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2209 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2210 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2211 | shost = lpfc_shost_from_vport(vport); |
| 2212 | spin_lock_irq(shost->host_lock); |
| 2213 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2214 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2215 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2216 | } |
| 2217 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2218 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2219 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2220 | lpfc_nlp_put(ndlp); |
| 2221 | pmb->context2 = NULL; |
| 2222 | } |
| 2223 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2224 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2225 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2226 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2227 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2228 | "2860 SLI authentication is required " |
| 2229 | "for INIT_LINK but has not done yet\n"); |
| 2230 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2231 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2232 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2233 | else |
| 2234 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | } |
| 2236 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2237 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2238 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2239 | * @phba: Pointer to HBA context object. |
| 2240 | * |
| 2241 | * This function is called with no lock held. This function processes all |
| 2242 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2243 | * service routine processes mailbox completion interrupt and adds completed |
| 2244 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2245 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2246 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2247 | * function returns the mailbox commands to the upper layer by calling the |
| 2248 | * completion handler function of each mailbox. |
| 2249 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2251 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2253 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2255 | int rc; |
| 2256 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | |
| 2258 | phba->sli.slistat.mbox_event++; |
| 2259 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2260 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2261 | spin_lock_irq(&phba->hbalock); |
| 2262 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2263 | spin_unlock_irq(&phba->hbalock); |
| 2264 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2266 | do { |
| 2267 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2268 | if (pmb == NULL) |
| 2269 | break; |
| 2270 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2271 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2272 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2273 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2274 | if (pmb->vport) { |
| 2275 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2276 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2277 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2278 | (uint32_t)pmbox->mbxCommand, |
| 2279 | pmbox->un.varWords[0], |
| 2280 | pmbox->un.varWords[1]); |
| 2281 | } |
| 2282 | else { |
| 2283 | lpfc_debugfs_disc_trc(phba->pport, |
| 2284 | LPFC_DISC_TRC_MBOX, |
| 2285 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2286 | (uint32_t)pmbox->mbxCommand, |
| 2287 | pmbox->un.varWords[0], |
| 2288 | pmbox->un.varWords[1]); |
| 2289 | } |
| 2290 | } |
| 2291 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2292 | /* |
| 2293 | * It is a fatal error if unknown mbox command completion. |
| 2294 | */ |
| 2295 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2296 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2297 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2298 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2299 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2300 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2301 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2302 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2303 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2304 | pmb), |
| 2305 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2306 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2307 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | phba->work_hs = HS_FFER3; |
| 2309 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2310 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | } |
| 2312 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | if (pmbox->mbxStatus) { |
| 2314 | phba->sli.slistat.mbox_stat_err++; |
| 2315 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2316 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2317 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2318 | LOG_MBOX | LOG_SLI, |
| 2319 | "(%d):0305 Mbox cmd cmpl " |
| 2320 | "error - RETRYing Data: x%x " |
| 2321 | "(x%x/x%x) x%x x%x x%x\n", |
| 2322 | pmb->vport ? pmb->vport->vpi : 0, |
| 2323 | pmbox->mbxCommand, |
| 2324 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2325 | pmb), |
| 2326 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2327 | pmb), |
| 2328 | pmbox->mbxStatus, |
| 2329 | pmbox->un.varWords[0], |
| 2330 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | pmbox->mbxStatus = 0; |
| 2332 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2334 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2335 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2340 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2341 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2343 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2345 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2346 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2347 | pmb->mbox_cmpl, |
| 2348 | *((uint32_t *) pmbox), |
| 2349 | pmbox->un.varWords[0], |
| 2350 | pmbox->un.varWords[1], |
| 2351 | pmbox->un.varWords[2], |
| 2352 | pmbox->un.varWords[3], |
| 2353 | pmbox->un.varWords[4], |
| 2354 | pmbox->un.varWords[5], |
| 2355 | pmbox->un.varWords[6], |
| 2356 | pmbox->un.varWords[7]); |
| 2357 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2358 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2360 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2361 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2362 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2363 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2364 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2365 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2366 | * @phba: Pointer to HBA context object. |
| 2367 | * @pring: Pointer to driver SLI ring object. |
| 2368 | * @tag: buffer tag. |
| 2369 | * |
| 2370 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2371 | * is set in the tag the buffer is posted for a particular exchange, |
| 2372 | * the function will return the buffer without replacing the buffer. |
| 2373 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2374 | * returns the buffer and also posts another buffer to the firmware. |
| 2375 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2376 | static struct lpfc_dmabuf * |
| 2377 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2378 | struct lpfc_sli_ring *pring, |
| 2379 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2380 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2381 | struct hbq_dmabuf *hbq_entry; |
| 2382 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2383 | if (tag & QUE_BUFTAG_BIT) |
| 2384 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2385 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2386 | if (!hbq_entry) |
| 2387 | return NULL; |
| 2388 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2389 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2390 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2391 | /** |
| 2392 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2393 | * @phba: Pointer to HBA context object. |
| 2394 | * @pring: Pointer to driver SLI ring object. |
| 2395 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2396 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2397 | * @fch_type: the type for the first frame of the sequence. |
| 2398 | * |
| 2399 | * This function is called with no lock held. This function uses the r_ctl and |
| 2400 | * type of the received sequence to find the correct callback function to call |
| 2401 | * to process the sequence. |
| 2402 | **/ |
| 2403 | static int |
| 2404 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2405 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2406 | uint32_t fch_type) |
| 2407 | { |
| 2408 | int i; |
| 2409 | |
| 2410 | /* unSolicited Responses */ |
| 2411 | if (pring->prt[0].profile) { |
| 2412 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2413 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2414 | saveq); |
| 2415 | return 1; |
| 2416 | } |
| 2417 | /* We must search, based on rctl / type |
| 2418 | for the right routine */ |
| 2419 | for (i = 0; i < pring->num_mask; i++) { |
| 2420 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2421 | (pring->prt[i].type == fch_type)) { |
| 2422 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2423 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2424 | (phba, pring, saveq); |
| 2425 | return 1; |
| 2426 | } |
| 2427 | } |
| 2428 | return 0; |
| 2429 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2430 | |
| 2431 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2432 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2433 | * @phba: Pointer to HBA context object. |
| 2434 | * @pring: Pointer to driver SLI ring object. |
| 2435 | * @saveq: Pointer to the unsolicited iocb. |
| 2436 | * |
| 2437 | * This function is called with no lock held by the ring event handler |
| 2438 | * when there is an unsolicited iocb posted to the response ring by the |
| 2439 | * firmware. This function gets the buffer associated with the iocbs |
| 2440 | * and calls the event handler for the ring. This function handles both |
| 2441 | * qring buffers and hbq buffers. |
| 2442 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2443 | * upper layer functions will free the iocb objects. |
| 2444 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2445 | static int |
| 2446 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2447 | struct lpfc_iocbq *saveq) |
| 2448 | { |
| 2449 | IOCB_t * irsp; |
| 2450 | WORD5 * w5p; |
| 2451 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2452 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2453 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2454 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | |
| 2456 | match = 0; |
| 2457 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2458 | |
| 2459 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2460 | if (pring->lpfc_sli_rcv_async_status) |
| 2461 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2462 | else |
| 2463 | lpfc_printf_log(phba, |
| 2464 | KERN_WARNING, |
| 2465 | LOG_SLI, |
| 2466 | "0316 Ring %d handler: unexpected " |
| 2467 | "ASYNC_STATUS iocb received evt_code " |
| 2468 | "0x%x\n", |
| 2469 | pring->ringno, |
| 2470 | irsp->un.asyncstat.evt_code); |
| 2471 | return 1; |
| 2472 | } |
| 2473 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2474 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2475 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2476 | if (irsp->ulpBdeCount > 0) { |
| 2477 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2478 | irsp->un.ulpWord[3]); |
| 2479 | lpfc_in_buf_free(phba, dmzbuf); |
| 2480 | } |
| 2481 | |
| 2482 | if (irsp->ulpBdeCount > 1) { |
| 2483 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2484 | irsp->unsli3.sli3Words[3]); |
| 2485 | lpfc_in_buf_free(phba, dmzbuf); |
| 2486 | } |
| 2487 | |
| 2488 | if (irsp->ulpBdeCount > 2) { |
| 2489 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2490 | irsp->unsli3.sli3Words[7]); |
| 2491 | lpfc_in_buf_free(phba, dmzbuf); |
| 2492 | } |
| 2493 | |
| 2494 | return 1; |
| 2495 | } |
| 2496 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2497 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2498 | if (irsp->ulpBdeCount != 0) { |
| 2499 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2500 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2501 | if (!saveq->context2) |
| 2502 | lpfc_printf_log(phba, |
| 2503 | KERN_ERR, |
| 2504 | LOG_SLI, |
| 2505 | "0341 Ring %d Cannot find buffer for " |
| 2506 | "an unsolicited iocb. tag 0x%x\n", |
| 2507 | pring->ringno, |
| 2508 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2509 | } |
| 2510 | if (irsp->ulpBdeCount == 2) { |
| 2511 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2512 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2513 | if (!saveq->context3) |
| 2514 | lpfc_printf_log(phba, |
| 2515 | KERN_ERR, |
| 2516 | LOG_SLI, |
| 2517 | "0342 Ring %d Cannot find buffer for an" |
| 2518 | " unsolicited iocb. tag 0x%x\n", |
| 2519 | pring->ringno, |
| 2520 | irsp->unsli3.sli3Words[7]); |
| 2521 | } |
| 2522 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2523 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2524 | if (irsp->ulpBdeCount != 0) { |
| 2525 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2526 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2527 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2528 | lpfc_printf_log(phba, |
| 2529 | KERN_ERR, |
| 2530 | LOG_SLI, |
| 2531 | "0343 Ring %d Cannot find " |
| 2532 | "buffer for an unsolicited iocb" |
| 2533 | ". tag 0x%x\n", pring->ringno, |
| 2534 | irsp->un.ulpWord[3]); |
| 2535 | } |
| 2536 | if (irsp->ulpBdeCount == 2) { |
| 2537 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2538 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2539 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2540 | lpfc_printf_log(phba, |
| 2541 | KERN_ERR, |
| 2542 | LOG_SLI, |
| 2543 | "0344 Ring %d Cannot find " |
| 2544 | "buffer for an unsolicited " |
| 2545 | "iocb. tag 0x%x\n", |
| 2546 | pring->ringno, |
| 2547 | irsp->unsli3.sli3Words[7]); |
| 2548 | } |
| 2549 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2550 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2551 | if (irsp->ulpBdeCount != 0 && |
| 2552 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2553 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2554 | int found = 0; |
| 2555 | |
| 2556 | /* search continue save q for same XRI */ |
| 2557 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2558 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2559 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2560 | list_add_tail(&saveq->list, &iocbq->list); |
| 2561 | found = 1; |
| 2562 | break; |
| 2563 | } |
| 2564 | } |
| 2565 | if (!found) |
| 2566 | list_add_tail(&saveq->clist, |
| 2567 | &pring->iocb_continue_saveq); |
| 2568 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2569 | list_del_init(&iocbq->clist); |
| 2570 | saveq = iocbq; |
| 2571 | irsp = &(saveq->iocb); |
| 2572 | } else |
| 2573 | return 0; |
| 2574 | } |
| 2575 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2576 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2577 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2578 | Rctl = FC_RCTL_ELS_REQ; |
| 2579 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2580 | } else { |
| 2581 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2582 | Rctl = w5p->hcsw.Rctl; |
| 2583 | Type = w5p->hcsw.Type; |
| 2584 | |
| 2585 | /* Firmware Workaround */ |
| 2586 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2587 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2588 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2589 | Rctl = FC_RCTL_ELS_REQ; |
| 2590 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2591 | w5p->hcsw.Rctl = Rctl; |
| 2592 | w5p->hcsw.Type = Type; |
| 2593 | } |
| 2594 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2595 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2596 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2597 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2598 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2599 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2600 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2601 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2602 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | } |
| 2604 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2605 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2606 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2607 | * @phba: Pointer to HBA context object. |
| 2608 | * @pring: Pointer to driver SLI ring object. |
| 2609 | * @prspiocb: Pointer to response iocb object. |
| 2610 | * |
| 2611 | * This function looks up the iocb_lookup table to get the command iocb |
| 2612 | * corresponding to the given response iocb using the iotag of the |
| 2613 | * response iocb. This function is called with the hbalock held. |
| 2614 | * This function returns the command iocb object if it finds the command |
| 2615 | * iocb else returns NULL. |
| 2616 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2617 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2618 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2619 | struct lpfc_sli_ring *pring, |
| 2620 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2623 | uint16_t iotag; |
| 2624 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2625 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2627 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2628 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2629 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2630 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2631 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2632 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2633 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | } |
| 2635 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2637 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2638 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2639 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2640 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | return NULL; |
| 2642 | } |
| 2643 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2644 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2645 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2646 | * @phba: Pointer to HBA context object. |
| 2647 | * @pring: Pointer to driver SLI ring object. |
| 2648 | * @iotag: IOCB tag. |
| 2649 | * |
| 2650 | * This function looks up the iocb_lookup table to get the command iocb |
| 2651 | * corresponding to the given iotag. This function is called with the |
| 2652 | * hbalock held. |
| 2653 | * This function returns the command iocb object if it finds the command |
| 2654 | * iocb else returns NULL. |
| 2655 | **/ |
| 2656 | static struct lpfc_iocbq * |
| 2657 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2658 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2659 | { |
| 2660 | struct lpfc_iocbq *cmd_iocb; |
| 2661 | |
| 2662 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2663 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2664 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2665 | /* remove from txcmpl queue list */ |
| 2666 | list_del_init(&cmd_iocb->list); |
| 2667 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2668 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2669 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2670 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2671 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2672 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2673 | iotag, phba->sli.last_iotag); |
| 2674 | return NULL; |
| 2675 | } |
| 2676 | |
| 2677 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2678 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2679 | * @phba: Pointer to HBA context object. |
| 2680 | * @pring: Pointer to driver SLI ring object. |
| 2681 | * @saveq: Pointer to the response iocb to be processed. |
| 2682 | * |
| 2683 | * This function is called by the ring event handler for non-fcp |
| 2684 | * rings when there is a new response iocb in the response ring. |
| 2685 | * The caller is not required to hold any locks. This function |
| 2686 | * gets the command iocb associated with the response iocb and |
| 2687 | * calls the completion handler for the command iocb. If there |
| 2688 | * is no completion handler, the function will free the resources |
| 2689 | * associated with command iocb. If the response iocb is for |
| 2690 | * an already aborted command iocb, the status of the completion |
| 2691 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2692 | * This function always returns 1. |
| 2693 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2695 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2696 | struct lpfc_iocbq *saveq) |
| 2697 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2698 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | int rc = 1; |
| 2700 | unsigned long iflag; |
| 2701 | |
| 2702 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2703 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2704 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2705 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2706 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | if (cmdiocbp) { |
| 2708 | if (cmdiocbp->iocb_cmpl) { |
| 2709 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2710 | * If an ELS command failed send an event to mgmt |
| 2711 | * application. |
| 2712 | */ |
| 2713 | if (saveq->iocb.ulpStatus && |
| 2714 | (pring->ringno == LPFC_ELS_RING) && |
| 2715 | (cmdiocbp->iocb.ulpCommand == |
| 2716 | CMD_ELS_REQUEST64_CR)) |
| 2717 | lpfc_send_els_failure_event(phba, |
| 2718 | cmdiocbp, saveq); |
| 2719 | |
| 2720 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | * Post all ELS completions to the worker thread. |
| 2722 | * All other are passed to the completion callback. |
| 2723 | */ |
| 2724 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2725 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2726 | (cmdiocbp->iocb_flag & |
| 2727 | LPFC_DRIVER_ABORTED)) { |
| 2728 | spin_lock_irqsave(&phba->hbalock, |
| 2729 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2730 | cmdiocbp->iocb_flag &= |
| 2731 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2732 | spin_unlock_irqrestore(&phba->hbalock, |
| 2733 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2734 | saveq->iocb.ulpStatus = |
| 2735 | IOSTAT_LOCAL_REJECT; |
| 2736 | saveq->iocb.un.ulpWord[4] = |
| 2737 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2738 | |
| 2739 | /* Firmware could still be in progress |
| 2740 | * of DMAing payload, so don't free data |
| 2741 | * buffer till after a hbeat. |
| 2742 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2743 | spin_lock_irqsave(&phba->hbalock, |
| 2744 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2745 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2746 | spin_unlock_irqrestore(&phba->hbalock, |
| 2747 | iflag); |
| 2748 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2749 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2750 | if (saveq->iocb_flag & |
| 2751 | LPFC_EXCHANGE_BUSY) { |
| 2752 | /* Set cmdiocb flag for the |
| 2753 | * exchange busy so sgl (xri) |
| 2754 | * will not be released until |
| 2755 | * the abort xri is received |
| 2756 | * from hba. |
| 2757 | */ |
| 2758 | spin_lock_irqsave( |
| 2759 | &phba->hbalock, iflag); |
| 2760 | cmdiocbp->iocb_flag |= |
| 2761 | LPFC_EXCHANGE_BUSY; |
| 2762 | spin_unlock_irqrestore( |
| 2763 | &phba->hbalock, iflag); |
| 2764 | } |
| 2765 | if (cmdiocbp->iocb_flag & |
| 2766 | LPFC_DRIVER_ABORTED) { |
| 2767 | /* |
| 2768 | * Clear LPFC_DRIVER_ABORTED |
| 2769 | * bit in case it was driver |
| 2770 | * initiated abort. |
| 2771 | */ |
| 2772 | spin_lock_irqsave( |
| 2773 | &phba->hbalock, iflag); |
| 2774 | cmdiocbp->iocb_flag &= |
| 2775 | ~LPFC_DRIVER_ABORTED; |
| 2776 | spin_unlock_irqrestore( |
| 2777 | &phba->hbalock, iflag); |
| 2778 | cmdiocbp->iocb.ulpStatus = |
| 2779 | IOSTAT_LOCAL_REJECT; |
| 2780 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2781 | IOERR_ABORT_REQUESTED; |
| 2782 | /* |
| 2783 | * For SLI4, irsiocb contains |
| 2784 | * NO_XRI in sli_xritag, it |
| 2785 | * shall not affect releasing |
| 2786 | * sgl (xri) process. |
| 2787 | */ |
| 2788 | saveq->iocb.ulpStatus = |
| 2789 | IOSTAT_LOCAL_REJECT; |
| 2790 | saveq->iocb.un.ulpWord[4] = |
| 2791 | IOERR_SLI_ABORTED; |
| 2792 | spin_lock_irqsave( |
| 2793 | &phba->hbalock, iflag); |
| 2794 | saveq->iocb_flag |= |
| 2795 | LPFC_DELAY_MEM_FREE; |
| 2796 | spin_unlock_irqrestore( |
| 2797 | &phba->hbalock, iflag); |
| 2798 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2799 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2800 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2801 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2802 | } else |
| 2803 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | } else { |
| 2805 | /* |
| 2806 | * Unknown initiating command based on the response iotag. |
| 2807 | * This could be the case on the ELS ring because of |
| 2808 | * lpfc_els_abort(). |
| 2809 | */ |
| 2810 | if (pring->ringno != LPFC_ELS_RING) { |
| 2811 | /* |
| 2812 | * Ring <ringno> handler: unexpected completion IoTag |
| 2813 | * <IoTag> |
| 2814 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2815 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2816 | "0322 Ring %d handler: " |
| 2817 | "unexpected completion IoTag x%x " |
| 2818 | "Data: x%x x%x x%x x%x\n", |
| 2819 | pring->ringno, |
| 2820 | saveq->iocb.ulpIoTag, |
| 2821 | saveq->iocb.ulpStatus, |
| 2822 | saveq->iocb.un.ulpWord[4], |
| 2823 | saveq->iocb.ulpCommand, |
| 2824 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2825 | } |
| 2826 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2827 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2828 | return rc; |
| 2829 | } |
| 2830 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2831 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2832 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2833 | * @phba: Pointer to HBA context object. |
| 2834 | * @pring: Pointer to driver SLI ring object. |
| 2835 | * |
| 2836 | * This function is called from the iocb ring event handlers when |
| 2837 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2838 | * an error attention condition to the worker thread and the worker |
| 2839 | * thread will transition the HBA to offline state. |
| 2840 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2841 | static void |
| 2842 | 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] | 2843 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2844 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2845 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2846 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2847 | * rsp ring <portRspMax> |
| 2848 | */ |
| 2849 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2850 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2851 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2852 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2853 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2854 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2855 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2856 | |
| 2857 | /* |
| 2858 | * All error attention handlers are posted to |
| 2859 | * worker thread |
| 2860 | */ |
| 2861 | phba->work_ha |= HA_ERATT; |
| 2862 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2863 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2864 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2865 | |
| 2866 | return; |
| 2867 | } |
| 2868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2869 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2870 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2871 | * @ptr: Pointer to address of HBA context object. |
| 2872 | * |
| 2873 | * This function is invoked by the Error Attention polling timer when the |
| 2874 | * timer times out. It will check the SLI Error Attention register for |
| 2875 | * possible attention events. If so, it will post an Error Attention event |
| 2876 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2877 | * Error Attention polling timer for the next poll. |
| 2878 | **/ |
| 2879 | void lpfc_poll_eratt(unsigned long ptr) |
| 2880 | { |
| 2881 | struct lpfc_hba *phba; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2882 | uint32_t eratt = 0, rem; |
| 2883 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2884 | |
| 2885 | phba = (struct lpfc_hba *)ptr; |
| 2886 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2887 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 2888 | sli_intr = phba->sli.slistat.sli_intr; |
| 2889 | |
| 2890 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 2891 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 2892 | sli_intr); |
| 2893 | else |
| 2894 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 2895 | |
| 2896 | /* 64-bit integer division not supporte on 32-bit x86 - use do_div */ |
| 2897 | rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL); |
| 2898 | phba->sli.slistat.sli_ips = cnt; |
| 2899 | |
| 2900 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 2901 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2902 | /* Check chip HA register for error event */ |
| 2903 | eratt = lpfc_sli_check_eratt(phba); |
| 2904 | |
| 2905 | if (eratt) |
| 2906 | /* Tell the worker thread there is work to do */ |
| 2907 | lpfc_worker_wake_up(phba); |
| 2908 | else |
| 2909 | /* Restart the timer for next eratt poll */ |
| 2910 | mod_timer(&phba->eratt_poll, jiffies + |
| 2911 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 2912 | return; |
| 2913 | } |
| 2914 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2915 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2917 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2918 | * @phba: Pointer to HBA context object. |
| 2919 | * @pring: Pointer to driver SLI ring object. |
| 2920 | * @mask: Host attention register mask for this ring. |
| 2921 | * |
| 2922 | * This function is called from the interrupt context when there is a ring |
| 2923 | * event for the fcp ring. The caller does not hold any lock. |
| 2924 | * 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] | 2925 | * 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] | 2926 | * LE bit set. The function will call the completion handler of the command iocb |
| 2927 | * if the response iocb indicates a completion for a command iocb or it is |
| 2928 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2929 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2930 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2931 | * to check it explicitly. |
| 2932 | */ |
| 2933 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2934 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2935 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2936 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2937 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2939 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2940 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2941 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | uint32_t status; |
| 2943 | uint32_t portRspPut, portRspMax; |
| 2944 | int rc = 1; |
| 2945 | lpfc_iocb_type type; |
| 2946 | unsigned long iflag; |
| 2947 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2948 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2949 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2950 | pring->stats.iocb_event++; |
| 2951 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2952 | /* |
| 2953 | * The next available response entry should never exceed the maximum |
| 2954 | * entries. If it does, treat it as an adapter hardware error. |
| 2955 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2956 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2958 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2959 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2960 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2961 | return 1; |
| 2962 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2963 | if (phba->fcp_ring_in_use) { |
| 2964 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2965 | return 1; |
| 2966 | } else |
| 2967 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | |
| 2969 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2970 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2971 | /* |
| 2972 | * Fetch an entry off the ring and copy it into a local data |
| 2973 | * structure. The copy involves a byte-swap since the |
| 2974 | * network byte order and pci byte orders are different. |
| 2975 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2976 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2977 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2978 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2979 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 2980 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2981 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2982 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2983 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2984 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2985 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2986 | irsp = &rspiocbq.iocb; |
| 2987 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2989 | pring->stats.iocb_rsp++; |
| 2990 | rsp_cmpl++; |
| 2991 | |
| 2992 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2993 | /* |
| 2994 | * If resource errors reported from HBA, reduce |
| 2995 | * queuedepths of the SCSI device. |
| 2996 | */ |
| 2997 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 2998 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 2999 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3000 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3001 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3002 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3003 | } |
| 3004 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3005 | /* Rsp ring <ringno> error: IOCB */ |
| 3006 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3007 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3008 | "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] | 3009 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3010 | irsp->un.ulpWord[0], |
| 3011 | irsp->un.ulpWord[1], |
| 3012 | irsp->un.ulpWord[2], |
| 3013 | irsp->un.ulpWord[3], |
| 3014 | irsp->un.ulpWord[4], |
| 3015 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3016 | *(uint32_t *)&irsp->un1, |
| 3017 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | switch (type) { |
| 3021 | case LPFC_ABORT_IOCB: |
| 3022 | case LPFC_SOL_IOCB: |
| 3023 | /* |
| 3024 | * Idle exchange closed via ABTS from port. No iocb |
| 3025 | * resources need to be recovered. |
| 3026 | */ |
| 3027 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3028 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3029 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3030 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3031 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3032 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3033 | break; |
| 3034 | } |
| 3035 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3036 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3037 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3038 | if (unlikely(!cmdiocbq)) |
| 3039 | break; |
| 3040 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3041 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3042 | if (cmdiocbq->iocb_cmpl) { |
| 3043 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3044 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3045 | &rspiocbq); |
| 3046 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3047 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3048 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3049 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3050 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3051 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3052 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3053 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3054 | default: |
| 3055 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3056 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3057 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3058 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3059 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3060 | dev_warn(&((phba->pcidev)->dev), |
| 3061 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3062 | phba->brd_no, adaptermsg); |
| 3063 | } else { |
| 3064 | /* Unknown IOCB command */ |
| 3065 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3066 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3067 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3068 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3069 | irsp->ulpStatus, |
| 3070 | irsp->ulpIoTag, |
| 3071 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3072 | } |
| 3073 | break; |
| 3074 | } |
| 3075 | |
| 3076 | /* |
| 3077 | * The response IOCB has been processed. Update the ring |
| 3078 | * pointer in SLIM. If the port response put pointer has not |
| 3079 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3080 | * response put pointer. |
| 3081 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3082 | writel(pring->sli.sli3.rspidx, |
| 3083 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3085 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3086 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3087 | } |
| 3088 | |
| 3089 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3090 | pring->stats.iocb_rsp_full++; |
| 3091 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3092 | writel(status, phba->CAregaddr); |
| 3093 | readl(phba->CAregaddr); |
| 3094 | } |
| 3095 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3096 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3097 | pring->stats.iocb_cmd_empty++; |
| 3098 | |
| 3099 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3100 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3101 | lpfc_sli_resume_iocb(phba, pring); |
| 3102 | |
| 3103 | if ((pring->lpfc_sli_cmd_available)) |
| 3104 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3105 | |
| 3106 | } |
| 3107 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3108 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3109 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | return rc; |
| 3111 | } |
| 3112 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3113 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3114 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3115 | * @phba: Pointer to HBA context object. |
| 3116 | * @pring: Pointer to driver SLI ring object. |
| 3117 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3118 | * |
| 3119 | * This function is called from the worker thread when there is a slow-path |
| 3120 | * response IOCB to process. This function chains all the response iocbs until |
| 3121 | * seeing the iocb with the LE bit set. The function will call |
| 3122 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3123 | * completion of a command iocb. The function will call the |
| 3124 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3125 | * The function frees the resources or calls the completion handler if this |
| 3126 | * iocb is an abort completion. The function returns NULL when the response |
| 3127 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3128 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3129 | * response iocb passed in. |
| 3130 | **/ |
| 3131 | static struct lpfc_iocbq * |
| 3132 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3133 | struct lpfc_iocbq *rspiocbp) |
| 3134 | { |
| 3135 | struct lpfc_iocbq *saveq; |
| 3136 | struct lpfc_iocbq *cmdiocbp; |
| 3137 | struct lpfc_iocbq *next_iocb; |
| 3138 | IOCB_t *irsp = NULL; |
| 3139 | uint32_t free_saveq; |
| 3140 | uint8_t iocb_cmd_type; |
| 3141 | lpfc_iocb_type type; |
| 3142 | unsigned long iflag; |
| 3143 | int rc; |
| 3144 | |
| 3145 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3146 | /* First add the response iocb to the countinueq list */ |
| 3147 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3148 | pring->iocb_continueq_cnt++; |
| 3149 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3150 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3151 | irsp = &rspiocbp->iocb; |
| 3152 | if (irsp->ulpLe) { |
| 3153 | /* |
| 3154 | * By default, the driver expects to free all resources |
| 3155 | * associated with this iocb completion. |
| 3156 | */ |
| 3157 | free_saveq = 1; |
| 3158 | saveq = list_get_first(&pring->iocb_continueq, |
| 3159 | struct lpfc_iocbq, list); |
| 3160 | irsp = &(saveq->iocb); |
| 3161 | list_del_init(&pring->iocb_continueq); |
| 3162 | pring->iocb_continueq_cnt = 0; |
| 3163 | |
| 3164 | pring->stats.iocb_rsp++; |
| 3165 | |
| 3166 | /* |
| 3167 | * If resource errors reported from HBA, reduce |
| 3168 | * queuedepths of the SCSI device. |
| 3169 | */ |
| 3170 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3171 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3172 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3173 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3174 | phba->lpfc_rampdown_queue_depth(phba); |
| 3175 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3176 | } |
| 3177 | |
| 3178 | if (irsp->ulpStatus) { |
| 3179 | /* Rsp ring <ringno> error: IOCB */ |
| 3180 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3181 | "0328 Rsp Ring %d error: " |
| 3182 | "IOCB Data: " |
| 3183 | "x%x x%x x%x x%x " |
| 3184 | "x%x x%x x%x x%x " |
| 3185 | "x%x x%x x%x x%x " |
| 3186 | "x%x x%x x%x x%x\n", |
| 3187 | pring->ringno, |
| 3188 | irsp->un.ulpWord[0], |
| 3189 | irsp->un.ulpWord[1], |
| 3190 | irsp->un.ulpWord[2], |
| 3191 | irsp->un.ulpWord[3], |
| 3192 | irsp->un.ulpWord[4], |
| 3193 | irsp->un.ulpWord[5], |
| 3194 | *(((uint32_t *) irsp) + 6), |
| 3195 | *(((uint32_t *) irsp) + 7), |
| 3196 | *(((uint32_t *) irsp) + 8), |
| 3197 | *(((uint32_t *) irsp) + 9), |
| 3198 | *(((uint32_t *) irsp) + 10), |
| 3199 | *(((uint32_t *) irsp) + 11), |
| 3200 | *(((uint32_t *) irsp) + 12), |
| 3201 | *(((uint32_t *) irsp) + 13), |
| 3202 | *(((uint32_t *) irsp) + 14), |
| 3203 | *(((uint32_t *) irsp) + 15)); |
| 3204 | } |
| 3205 | |
| 3206 | /* |
| 3207 | * Fetch the IOCB command type and call the correct completion |
| 3208 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3209 | * get freed back to the lpfc_iocb_list by the discovery |
| 3210 | * kernel thread. |
| 3211 | */ |
| 3212 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3213 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3214 | switch (type) { |
| 3215 | case LPFC_SOL_IOCB: |
| 3216 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3217 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3218 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3219 | break; |
| 3220 | |
| 3221 | case LPFC_UNSOL_IOCB: |
| 3222 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3223 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3224 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3225 | if (!rc) |
| 3226 | free_saveq = 0; |
| 3227 | break; |
| 3228 | |
| 3229 | case LPFC_ABORT_IOCB: |
| 3230 | cmdiocbp = NULL; |
| 3231 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3232 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3233 | saveq); |
| 3234 | if (cmdiocbp) { |
| 3235 | /* Call the specified completion routine */ |
| 3236 | if (cmdiocbp->iocb_cmpl) { |
| 3237 | spin_unlock_irqrestore(&phba->hbalock, |
| 3238 | iflag); |
| 3239 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3240 | saveq); |
| 3241 | spin_lock_irqsave(&phba->hbalock, |
| 3242 | iflag); |
| 3243 | } else |
| 3244 | __lpfc_sli_release_iocbq(phba, |
| 3245 | cmdiocbp); |
| 3246 | } |
| 3247 | break; |
| 3248 | |
| 3249 | case LPFC_UNKNOWN_IOCB: |
| 3250 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3251 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3252 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3253 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3254 | MAX_MSG_DATA); |
| 3255 | dev_warn(&((phba->pcidev)->dev), |
| 3256 | "lpfc%d: %s\n", |
| 3257 | phba->brd_no, adaptermsg); |
| 3258 | } else { |
| 3259 | /* Unknown IOCB command */ |
| 3260 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3261 | "0335 Unknown IOCB " |
| 3262 | "command Data: x%x " |
| 3263 | "x%x x%x x%x\n", |
| 3264 | irsp->ulpCommand, |
| 3265 | irsp->ulpStatus, |
| 3266 | irsp->ulpIoTag, |
| 3267 | irsp->ulpContext); |
| 3268 | } |
| 3269 | break; |
| 3270 | } |
| 3271 | |
| 3272 | if (free_saveq) { |
| 3273 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3274 | &saveq->list, list) { |
| 3275 | list_del(&rspiocbp->list); |
| 3276 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3277 | } |
| 3278 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3279 | } |
| 3280 | rspiocbp = NULL; |
| 3281 | } |
| 3282 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3283 | return rspiocbp; |
| 3284 | } |
| 3285 | |
| 3286 | /** |
| 3287 | * 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] | 3288 | * @phba: Pointer to HBA context object. |
| 3289 | * @pring: Pointer to driver SLI ring object. |
| 3290 | * @mask: Host attention register mask for this ring. |
| 3291 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3292 | * This routine wraps the actual slow_ring event process routine from the |
| 3293 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3294 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3295 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3296 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3297 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3298 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3299 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3300 | } |
| 3301 | |
| 3302 | /** |
| 3303 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3304 | * @phba: Pointer to HBA context object. |
| 3305 | * @pring: Pointer to driver SLI ring object. |
| 3306 | * @mask: Host attention register mask for this ring. |
| 3307 | * |
| 3308 | * This function is called from the worker thread when there is a ring event |
| 3309 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3310 | * remove each response iocb in the response ring and calls the handle |
| 3311 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3312 | **/ |
| 3313 | static void |
| 3314 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3315 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3316 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3317 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3318 | IOCB_t *entry; |
| 3319 | IOCB_t *irsp = NULL; |
| 3320 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3321 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3323 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3325 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3326 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3327 | pring->stats.iocb_event++; |
| 3328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | /* |
| 3330 | * The next available response entry should never exceed the maximum |
| 3331 | * entries. If it does, treat it as an adapter hardware error. |
| 3332 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3333 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3335 | if (portRspPut >= portRspMax) { |
| 3336 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3337 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | * rsp ring <portRspMax> |
| 3339 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3340 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3341 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3342 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3343 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3345 | phba->link_state = LPFC_HBA_ERROR; |
| 3346 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | |
| 3348 | phba->work_hs = HS_FFER3; |
| 3349 | lpfc_handle_eratt(phba); |
| 3350 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3351 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3355 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | /* |
| 3357 | * Build a completion list and call the appropriate handler. |
| 3358 | * The process is to get the next available response iocb, get |
| 3359 | * a free iocb from the list, copy the response data into the |
| 3360 | * free iocb, insert to the continuation list, and update the |
| 3361 | * next response index to slim. This process makes response |
| 3362 | * iocb's in the ring available to DMA as fast as possible but |
| 3363 | * pays a penalty for a copy operation. Since the iocb is |
| 3364 | * only 32 bytes, this penalty is considered small relative to |
| 3365 | * the PCI reads for register values and a slim write. When |
| 3366 | * the ulpLe field is set, the entire Command has been |
| 3367 | * received. |
| 3368 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3369 | entry = lpfc_resp_iocb(phba, pring); |
| 3370 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3371 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3372 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | if (rspiocbp == NULL) { |
| 3374 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3375 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | break; |
| 3377 | } |
| 3378 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3379 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3380 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | irsp = &rspiocbp->iocb; |
| 3382 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3383 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3384 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3386 | if (pring->ringno == LPFC_ELS_RING) { |
| 3387 | lpfc_debugfs_slow_ring_trc(phba, |
| 3388 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3389 | *(((uint32_t *) irsp) + 4), |
| 3390 | *(((uint32_t *) irsp) + 6), |
| 3391 | *(((uint32_t *) irsp) + 7)); |
| 3392 | } |
| 3393 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3394 | writel(pring->sli.sli3.rspidx, |
| 3395 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3397 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3398 | /* Handle the response IOCB */ |
| 3399 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3400 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3401 | |
| 3402 | /* |
| 3403 | * If the port response put pointer has not been updated, sync |
| 3404 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3405 | * response put pointer. |
| 3406 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3407 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3409 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3410 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3412 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | /* At least one response entry has been freed */ |
| 3414 | pring->stats.iocb_rsp_full++; |
| 3415 | /* SET RxRE_RSP in Chip Att register */ |
| 3416 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3417 | writel(status, phba->CAregaddr); |
| 3418 | readl(phba->CAregaddr); /* flush */ |
| 3419 | } |
| 3420 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3421 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3422 | pring->stats.iocb_cmd_empty++; |
| 3423 | |
| 3424 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3425 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3426 | lpfc_sli_resume_iocb(phba, pring); |
| 3427 | |
| 3428 | if ((pring->lpfc_sli_cmd_available)) |
| 3429 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3430 | |
| 3431 | } |
| 3432 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3433 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3434 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3435 | } |
| 3436 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3437 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3438 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3439 | * @phba: Pointer to HBA context object. |
| 3440 | * @pring: Pointer to driver SLI ring object. |
| 3441 | * @mask: Host attention register mask for this ring. |
| 3442 | * |
| 3443 | * This function is called from the worker thread when there is a pending |
| 3444 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3445 | * queue. The caller does not hold any lock. The function will remove each |
| 3446 | * response iocb from the response worker queue and calls the handle |
| 3447 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3448 | **/ |
| 3449 | static void |
| 3450 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3451 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3452 | { |
| 3453 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3454 | struct hbq_dmabuf *dmabuf; |
| 3455 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3456 | unsigned long iflag; |
| 3457 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3458 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3459 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3460 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3461 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3462 | /* Get the response iocb from the head of work queue */ |
| 3463 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3464 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3465 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3466 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3467 | |
| 3468 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3469 | case CQE_CODE_COMPL_WQE: |
| 3470 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3471 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3472 | /* Translate ELS WCQE to response IOCBQ */ |
| 3473 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3474 | irspiocbq); |
| 3475 | if (irspiocbq) |
| 3476 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3477 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3478 | break; |
| 3479 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3480 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3481 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3482 | cq_event); |
| 3483 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3484 | break; |
| 3485 | default: |
| 3486 | break; |
| 3487 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3492 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3493 | * @phba: Pointer to HBA context object. |
| 3494 | * @pring: Pointer to driver SLI ring object. |
| 3495 | * |
| 3496 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3497 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3498 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3499 | * the return of this function. The caller is not required to hold any locks. |
| 3500 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3501 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3503 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3504 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3505 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3507 | if (pring->ringno == LPFC_ELS_RING) { |
| 3508 | lpfc_fabric_abort_hba(phba); |
| 3509 | } |
| 3510 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3511 | /* Error everything on txq and txcmplq |
| 3512 | * First do the txq. |
| 3513 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3514 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3515 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3516 | |
| 3517 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3518 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3519 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3520 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3521 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3522 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3523 | /* Cancel all the IOCBs from the completions list */ |
| 3524 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3525 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3526 | } |
| 3527 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3528 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3529 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3530 | * @phba: Pointer to HBA context object. |
| 3531 | * |
| 3532 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3533 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3534 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3535 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3536 | * slot has been permanently disabled. |
| 3537 | **/ |
| 3538 | void |
| 3539 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3540 | { |
| 3541 | LIST_HEAD(txq); |
| 3542 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3543 | struct lpfc_sli *psli = &phba->sli; |
| 3544 | struct lpfc_sli_ring *pring; |
| 3545 | |
| 3546 | /* Currently, only one fcp ring */ |
| 3547 | pring = &psli->ring[psli->fcp_ring]; |
| 3548 | |
| 3549 | spin_lock_irq(&phba->hbalock); |
| 3550 | /* Retrieve everything on txq */ |
| 3551 | list_splice_init(&pring->txq, &txq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3552 | |
| 3553 | /* Retrieve everything on the txcmplq */ |
| 3554 | list_splice_init(&pring->txcmplq, &txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3555 | |
| 3556 | /* Indicate the I/O queues are flushed */ |
| 3557 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3558 | spin_unlock_irq(&phba->hbalock); |
| 3559 | |
| 3560 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3561 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3562 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3563 | |
| 3564 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3565 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3566 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3570 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3571 | * @phba: Pointer to HBA context object. |
| 3572 | * @mask: Bit mask to be checked. |
| 3573 | * |
| 3574 | * This function reads the host status register and compares |
| 3575 | * with the provided bit mask to check if HBA completed |
| 3576 | * the restart. This function will wait in a loop for the |
| 3577 | * HBA to complete restart. If the HBA does not restart within |
| 3578 | * 15 iterations, the function will reset the HBA again. The |
| 3579 | * function returns 1 when HBA fail to restart otherwise returns |
| 3580 | * zero. |
| 3581 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3582 | static int |
| 3583 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3585 | uint32_t status; |
| 3586 | int i = 0; |
| 3587 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3589 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3590 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3591 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3593 | /* |
| 3594 | * Check status register every 100ms for 5 retries, then every |
| 3595 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3596 | * every 2.5 sec for 4. |
| 3597 | * Break our of the loop if errors occurred during init. |
| 3598 | */ |
| 3599 | while (((status & mask) != mask) && |
| 3600 | !(status & HS_FFERM) && |
| 3601 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3602 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3603 | if (i <= 5) |
| 3604 | msleep(10); |
| 3605 | else if (i <= 10) |
| 3606 | msleep(500); |
| 3607 | else |
| 3608 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3610 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3611 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3612 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3613 | lpfc_sli_brdrestart(phba); |
| 3614 | } |
| 3615 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3616 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3617 | retval = 1; |
| 3618 | break; |
| 3619 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3622 | /* Check to see if any errors occurred during init */ |
| 3623 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3624 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3625 | "2751 Adapter failed to restart, " |
| 3626 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3627 | status, |
| 3628 | readl(phba->MBslimaddr + 0xa8), |
| 3629 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3630 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3631 | retval = 1; |
| 3632 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3634 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | } |
| 3636 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3637 | /** |
| 3638 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3639 | * @phba: Pointer to HBA context object. |
| 3640 | * @mask: Bit mask to be checked. |
| 3641 | * |
| 3642 | * This function checks the host status register to check if HBA is |
| 3643 | * ready. This function will wait in a loop for the HBA to be ready |
| 3644 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3645 | * function again. The function returns 1 when HBA fail to be ready |
| 3646 | * otherwise returns zero. |
| 3647 | **/ |
| 3648 | static int |
| 3649 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3650 | { |
| 3651 | uint32_t status; |
| 3652 | int retval = 0; |
| 3653 | |
| 3654 | /* Read the HBA Host Status Register */ |
| 3655 | status = lpfc_sli4_post_status_check(phba); |
| 3656 | |
| 3657 | if (status) { |
| 3658 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3659 | lpfc_sli_brdrestart(phba); |
| 3660 | status = lpfc_sli4_post_status_check(phba); |
| 3661 | } |
| 3662 | |
| 3663 | /* Check to see if any errors occurred during init */ |
| 3664 | if (status) { |
| 3665 | phba->link_state = LPFC_HBA_ERROR; |
| 3666 | retval = 1; |
| 3667 | } else |
| 3668 | phba->sli4_hba.intr_enable = 0; |
| 3669 | |
| 3670 | return retval; |
| 3671 | } |
| 3672 | |
| 3673 | /** |
| 3674 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3675 | * @phba: Pointer to HBA context object. |
| 3676 | * @mask: Bit mask to be checked. |
| 3677 | * |
| 3678 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3679 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3680 | **/ |
| 3681 | int |
| 3682 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3683 | { |
| 3684 | return phba->lpfc_sli_brdready(phba, mask); |
| 3685 | } |
| 3686 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3687 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3688 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3689 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3690 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3691 | * @phba: Pointer to HBA context object. |
| 3692 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3693 | * This function is called before resetting an HBA. This function is called |
| 3694 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3695 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3696 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3697 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3698 | uint32_t __iomem *resp_buf; |
| 3699 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3700 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3701 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3702 | int i; |
| 3703 | uint8_t hdrtype; |
| 3704 | |
| 3705 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3706 | if (hdrtype != 0x80 || |
| 3707 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3708 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3709 | return; |
| 3710 | |
| 3711 | /* |
| 3712 | * Tell the other part of the chip to suspend temporarily all |
| 3713 | * its DMA activity. |
| 3714 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3715 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3716 | |
| 3717 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3718 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3719 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3720 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3721 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3722 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3723 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3724 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3725 | return; |
| 3726 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3727 | /* Clear Chip error bit */ |
| 3728 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3729 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | mbox = 0; |
| 3733 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3734 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3735 | |
| 3736 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3737 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3738 | writel(mbox, mbox_buf); |
| 3739 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3740 | for (i = 0; i < 50; i++) { |
| 3741 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3742 | return; |
| 3743 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3744 | mdelay(1); |
| 3745 | else |
| 3746 | break; |
| 3747 | } |
| 3748 | resp_data = 0; |
| 3749 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3750 | return; |
| 3751 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3752 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3753 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3754 | goto restore_hc; |
| 3755 | else |
| 3756 | goto clear_errat; |
| 3757 | } |
| 3758 | |
| 3759 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3760 | resp_data = 0; |
| 3761 | for (i = 0; i < 500; i++) { |
| 3762 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3763 | return; |
| 3764 | if (resp_data != mbox) |
| 3765 | mdelay(1); |
| 3766 | else |
| 3767 | break; |
| 3768 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3769 | |
| 3770 | clear_errat: |
| 3771 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3772 | while (++i < 500) { |
| 3773 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3774 | return; |
| 3775 | if (!(ha_copy & HA_ERATT)) |
| 3776 | mdelay(1); |
| 3777 | else |
| 3778 | break; |
| 3779 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3780 | |
| 3781 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3782 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3783 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3787 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3788 | writel(hc_copy, phba->HCregaddr); |
| 3789 | readl(phba->HCregaddr); /* flush */ |
| 3790 | } |
| 3791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3792 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3793 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3794 | * @phba: Pointer to HBA context object. |
| 3795 | * |
| 3796 | * This function issues a kill_board mailbox command and waits for |
| 3797 | * the error attention interrupt. This function is called for stopping |
| 3798 | * the firmware processing. The caller is not required to hold any |
| 3799 | * locks. This function calls lpfc_hba_down_post function to free |
| 3800 | * any pending commands after the kill. The function will return 1 when it |
| 3801 | * fails to kill the board else will return 0. |
| 3802 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3803 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3804 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3806 | struct lpfc_sli *psli; |
| 3807 | LPFC_MBOXQ_t *pmb; |
| 3808 | uint32_t status; |
| 3809 | uint32_t ha_copy; |
| 3810 | int retval; |
| 3811 | int i = 0; |
| 3812 | |
| 3813 | psli = &phba->sli; |
| 3814 | |
| 3815 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3816 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3817 | "0329 Kill HBA Data: x%x x%x\n", |
| 3818 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3819 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3820 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3821 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3822 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3823 | |
| 3824 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3825 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3826 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3827 | spin_unlock_irq(&phba->hbalock); |
| 3828 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3829 | return 1; |
| 3830 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3831 | status &= ~HC_ERINT_ENA; |
| 3832 | writel(status, phba->HCregaddr); |
| 3833 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3834 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3835 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3836 | |
| 3837 | lpfc_kill_board(phba, pmb); |
| 3838 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3839 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3840 | |
| 3841 | if (retval != MBX_SUCCESS) { |
| 3842 | if (retval != MBX_BUSY) |
| 3843 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3844 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3845 | "2752 KILL_BOARD command failed retval %d\n", |
| 3846 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3847 | spin_lock_irq(&phba->hbalock); |
| 3848 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3849 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3850 | return 1; |
| 3851 | } |
| 3852 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3853 | spin_lock_irq(&phba->hbalock); |
| 3854 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3855 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3856 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3857 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3858 | |
| 3859 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3860 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3861 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3862 | * board is now undefined. |
| 3863 | */ |
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 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3867 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3868 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3869 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3873 | if (ha_copy & HA_ERATT) { |
| 3874 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3875 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3876 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3877 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3878 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3879 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3880 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3881 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3882 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3883 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3884 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3885 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3886 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3887 | } |
| 3888 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3889 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3890 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3891 | * @phba: Pointer to HBA context object. |
| 3892 | * |
| 3893 | * This function resets the HBA by writing HC_INITFF to the control |
| 3894 | * register. After the HBA resets, this function resets all the iocb ring |
| 3895 | * indices. This function disables PCI layer parity checking during |
| 3896 | * the reset. |
| 3897 | * This function returns 0 always. |
| 3898 | * The caller is not required to hold any locks. |
| 3899 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3900 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3902 | { |
| 3903 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3905 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3907 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3908 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3910 | /* Reset HBA */ |
| 3911 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3912 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3913 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3914 | |
| 3915 | /* perform board reset */ |
| 3916 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3917 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3918 | phba->pport->fc_myDID = 0; |
| 3919 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3920 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3921 | /* Turn off parity checking and serr during the physical reset */ |
| 3922 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3923 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 3924 | (cfg_value & |
| 3925 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3926 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3927 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 3928 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3929 | /* Now toggle INITFF bit in the Host Control Register */ |
| 3930 | writel(HC_INITFF, phba->HCregaddr); |
| 3931 | mdelay(1); |
| 3932 | readl(phba->HCregaddr); /* flush */ |
| 3933 | writel(0, phba->HCregaddr); |
| 3934 | readl(phba->HCregaddr); /* flush */ |
| 3935 | |
| 3936 | /* Restore PCI cmd register */ |
| 3937 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | |
| 3939 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3940 | for (i = 0; i < psli->num_rings; i++) { |
| 3941 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3942 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3943 | pring->sli.sli3.rspidx = 0; |
| 3944 | pring->sli.sli3.next_cmdidx = 0; |
| 3945 | pring->sli.sli3.local_getidx = 0; |
| 3946 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3947 | pring->missbufcnt = 0; |
| 3948 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3950 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3951 | return 0; |
| 3952 | } |
| 3953 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3954 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3955 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 3956 | * @phba: Pointer to HBA context object. |
| 3957 | * |
| 3958 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 3959 | * checking during resets the device. The caller is not required to hold |
| 3960 | * any locks. |
| 3961 | * |
| 3962 | * This function returns 0 always. |
| 3963 | **/ |
| 3964 | int |
| 3965 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 3966 | { |
| 3967 | struct lpfc_sli *psli = &phba->sli; |
| 3968 | uint16_t cfg_value; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3969 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3970 | |
| 3971 | /* Reset HBA */ |
| 3972 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3973 | "0295 Reset HBA Data: x%x x%x\n", |
| 3974 | phba->pport->port_state, psli->sli_flag); |
| 3975 | |
| 3976 | /* perform board reset */ |
| 3977 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3978 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3979 | phba->pport->fc_myDID = 0; |
| 3980 | phba->pport->fc_prevDID = 0; |
| 3981 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3982 | spin_lock_irq(&phba->hbalock); |
| 3983 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 3984 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3985 | spin_unlock_irq(&phba->hbalock); |
| 3986 | |
| 3987 | /* Now physically reset the device */ |
| 3988 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3989 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3990 | |
| 3991 | /* Turn off parity checking and serr during the physical reset */ |
| 3992 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3993 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 3994 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3995 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 3996 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3997 | rc = lpfc_pci_function_reset(phba); |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 3998 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3999 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4000 | /* Restore PCI cmd register */ |
| 4001 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4002 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4003 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | /** |
| 4007 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4008 | * @phba: Pointer to HBA context object. |
| 4009 | * |
| 4010 | * This function is called in the SLI initialization code path to |
| 4011 | * restart the HBA. The caller is not required to hold any lock. |
| 4012 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4013 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4014 | * function to free any pending commands. The function enables |
| 4015 | * POST only during the first initialization. The function returns zero. |
| 4016 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4017 | * command before the return of this function. |
| 4018 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4019 | static int |
| 4020 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4021 | { |
| 4022 | MAILBOX_t *mb; |
| 4023 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4024 | volatile uint32_t word0; |
| 4025 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4026 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4027 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4028 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4029 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4030 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4031 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4032 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4033 | psli = &phba->sli; |
| 4034 | |
| 4035 | /* Restart HBA */ |
| 4036 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4037 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4038 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4039 | |
| 4040 | word0 = 0; |
| 4041 | mb = (MAILBOX_t *) &word0; |
| 4042 | mb->mbxCommand = MBX_RESTART; |
| 4043 | mb->mbxHc = 1; |
| 4044 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4045 | lpfc_reset_barrier(phba); |
| 4046 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4047 | to_slim = phba->MBslimaddr; |
| 4048 | writel(*(uint32_t *) mb, to_slim); |
| 4049 | readl(to_slim); /* flush */ |
| 4050 | |
| 4051 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4052 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4053 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4054 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4055 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4056 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4057 | writel(*(uint32_t *) mb, to_slim); |
| 4058 | readl(to_slim); /* flush */ |
| 4059 | |
| 4060 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4061 | phba->pport->stopped = 0; |
| 4062 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4063 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4064 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4065 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4066 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4067 | psli->stats_start = get_seconds(); |
| 4068 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4069 | /* Give the INITFF and Post time to settle. */ |
| 4070 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4071 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4072 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4073 | if (hba_aer_enabled) |
| 4074 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4075 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4076 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | |
| 4078 | return 0; |
| 4079 | } |
| 4080 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4081 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4082 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4083 | * @phba: Pointer to HBA context object. |
| 4084 | * |
| 4085 | * This function is called in the SLI initialization code path to restart |
| 4086 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4087 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4088 | * free any pending commands. |
| 4089 | **/ |
| 4090 | static int |
| 4091 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4092 | { |
| 4093 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4094 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4095 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4096 | |
| 4097 | /* Restart HBA */ |
| 4098 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4099 | "0296 Restart HBA Data: x%x x%x\n", |
| 4100 | phba->pport->port_state, psli->sli_flag); |
| 4101 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4102 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4103 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4104 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4105 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4106 | |
| 4107 | spin_lock_irq(&phba->hbalock); |
| 4108 | phba->pport->stopped = 0; |
| 4109 | phba->link_state = LPFC_INIT_START; |
| 4110 | phba->hba_flag = 0; |
| 4111 | spin_unlock_irq(&phba->hbalock); |
| 4112 | |
| 4113 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4114 | psli->stats_start = get_seconds(); |
| 4115 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4116 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4117 | if (hba_aer_enabled) |
| 4118 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4119 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4120 | lpfc_hba_down_post(phba); |
| 4121 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4122 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | /** |
| 4126 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4127 | * @phba: Pointer to HBA context object. |
| 4128 | * |
| 4129 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4130 | * API jump table function pointer from the lpfc_hba struct. |
| 4131 | **/ |
| 4132 | int |
| 4133 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4134 | { |
| 4135 | return phba->lpfc_sli_brdrestart(phba); |
| 4136 | } |
| 4137 | |
| 4138 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4139 | * 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] | 4140 | * @phba: Pointer to HBA context object. |
| 4141 | * |
| 4142 | * This function is called after a HBA restart to wait for successful |
| 4143 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4144 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4145 | * iteration, the function will restart the HBA again. The function returns |
| 4146 | * zero if HBA successfully restarted else returns negative error code. |
| 4147 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | static int |
| 4149 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4150 | { |
| 4151 | uint32_t status, i = 0; |
| 4152 | |
| 4153 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4154 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4155 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | |
| 4157 | /* Check status register to see what current state is */ |
| 4158 | i = 0; |
| 4159 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4160 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4161 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4162 | * retries, then every 1 sec for 50 retires for a total of |
| 4163 | * ~60 seconds before reset the board again and check every |
| 4164 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4165 | * board ready is required by the Falcon FIPS zeroization |
| 4166 | * complete, and any reset the board in between shall cause |
| 4167 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4169 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4170 | /* Adapter failed to init, timeout, status reg |
| 4171 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4172 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4173 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4174 | "timeout, status reg x%x, " |
| 4175 | "FW Data: A8 x%x AC x%x\n", status, |
| 4176 | readl(phba->MBslimaddr + 0xa8), |
| 4177 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4178 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | return -ETIMEDOUT; |
| 4180 | } |
| 4181 | |
| 4182 | /* Check to see if any errors occurred during init */ |
| 4183 | if (status & HS_FFERM) { |
| 4184 | /* ERROR: During chipset initialization */ |
| 4185 | /* Adapter failed to init, chipset, status reg |
| 4186 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4187 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4188 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4189 | "chipset, status reg x%x, " |
| 4190 | "FW Data: A8 x%x AC x%x\n", status, |
| 4191 | readl(phba->MBslimaddr + 0xa8), |
| 4192 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4193 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | return -EIO; |
| 4195 | } |
| 4196 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4197 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4198 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4199 | else if (i <= 100) |
| 4200 | msleep(100); |
| 4201 | else |
| 4202 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4203 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4204 | if (i == 150) { |
| 4205 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4206 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4207 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | } |
| 4209 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4210 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4211 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | /* Check to see if any errors occurred during init */ |
| 4215 | if (status & HS_FFERM) { |
| 4216 | /* ERROR: During chipset initialization */ |
| 4217 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4218 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4219 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4220 | "status reg x%x, " |
| 4221 | "FW Data: A8 x%x AC x%x\n", status, |
| 4222 | readl(phba->MBslimaddr + 0xa8), |
| 4223 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4224 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4225 | return -EIO; |
| 4226 | } |
| 4227 | |
| 4228 | /* Clear all interrupt enable conditions */ |
| 4229 | writel(0, phba->HCregaddr); |
| 4230 | readl(phba->HCregaddr); /* flush */ |
| 4231 | |
| 4232 | /* setup host attn register */ |
| 4233 | writel(0xffffffff, phba->HAregaddr); |
| 4234 | readl(phba->HAregaddr); /* flush */ |
| 4235 | return 0; |
| 4236 | } |
| 4237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4239 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4240 | * |
| 4241 | * This function calculates and returns the number of HBQs required to be |
| 4242 | * configured. |
| 4243 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4244 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4245 | lpfc_sli_hbq_count(void) |
| 4246 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4247 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4248 | } |
| 4249 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4251 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4252 | * |
| 4253 | * This function adds the number of hbq entries in every HBQ to get |
| 4254 | * the total number of hbq entries required for the HBA and returns |
| 4255 | * the total count. |
| 4256 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4257 | static int |
| 4258 | lpfc_sli_hbq_entry_count(void) |
| 4259 | { |
| 4260 | int hbq_count = lpfc_sli_hbq_count(); |
| 4261 | int count = 0; |
| 4262 | int i; |
| 4263 | |
| 4264 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4265 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4266 | return count; |
| 4267 | } |
| 4268 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4269 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4270 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4271 | * |
| 4272 | * This function calculates amount of memory required for all hbq entries |
| 4273 | * to be configured and returns the total memory required. |
| 4274 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4275 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4276 | lpfc_sli_hbq_size(void) |
| 4277 | { |
| 4278 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4279 | } |
| 4280 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4281 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4282 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4283 | * @phba: Pointer to HBA context object. |
| 4284 | * |
| 4285 | * This function is called during the SLI initialization to configure |
| 4286 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4287 | * required to hold any locks. This function will return zero if successful |
| 4288 | * else it will return negative error code. |
| 4289 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4290 | static int |
| 4291 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4292 | { |
| 4293 | int hbq_count = lpfc_sli_hbq_count(); |
| 4294 | LPFC_MBOXQ_t *pmb; |
| 4295 | MAILBOX_t *pmbox; |
| 4296 | uint32_t hbqno; |
| 4297 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4298 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4299 | /* Get a Mailbox buffer to setup mailbox |
| 4300 | * commands for HBA initialization |
| 4301 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4302 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4303 | |
| 4304 | if (!pmb) |
| 4305 | return -ENOMEM; |
| 4306 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4307 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4308 | |
| 4309 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4310 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4311 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4312 | |
| 4313 | hbq_entry_index = 0; |
| 4314 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4315 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4316 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4317 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4318 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4319 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4320 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4321 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4322 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4323 | |
| 4324 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4325 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4326 | mbxStatus <status>, ring <num> */ |
| 4327 | |
| 4328 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4329 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4330 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4331 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4332 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4333 | pmbox->mbxStatus, hbqno); |
| 4334 | |
| 4335 | phba->link_state = LPFC_HBA_ERROR; |
| 4336 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4337 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4338 | } |
| 4339 | } |
| 4340 | phba->hbq_count = hbq_count; |
| 4341 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4342 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4343 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4344 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4345 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4346 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4347 | return 0; |
| 4348 | } |
| 4349 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4350 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4351 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4352 | * @phba: Pointer to HBA context object. |
| 4353 | * |
| 4354 | * This function is called during the SLI initialization to configure |
| 4355 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4356 | * required to hold any locks. This function will return zero if successful |
| 4357 | * else it will return negative error code. |
| 4358 | **/ |
| 4359 | static int |
| 4360 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4361 | { |
| 4362 | phba->hbq_in_use = 1; |
| 4363 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4364 | phba->hbq_count = 1; |
| 4365 | /* Initially populate or replenish the HBQs */ |
| 4366 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4367 | return 0; |
| 4368 | } |
| 4369 | |
| 4370 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4371 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4372 | * @phba: Pointer to HBA context object. |
| 4373 | * @sli_mode: sli mode - 2/3 |
| 4374 | * |
| 4375 | * This function is called by the sli intialization code path |
| 4376 | * to issue config_port mailbox command. This function restarts the |
| 4377 | * HBA firmware and issues a config_port mailbox command to configure |
| 4378 | * the SLI interface in the sli mode specified by sli_mode |
| 4379 | * variable. The caller is not required to hold any locks. |
| 4380 | * The function returns 0 if successful, else returns negative error |
| 4381 | * code. |
| 4382 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4383 | int |
| 4384 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4385 | { |
| 4386 | LPFC_MBOXQ_t *pmb; |
| 4387 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4388 | |
| 4389 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4390 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4391 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | return -ENOMEM; |
| 4393 | } |
| 4394 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4395 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4396 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4397 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4398 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4399 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4400 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4401 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4402 | rc = lpfc_sli_chipset_init(phba); |
| 4403 | if (rc) |
| 4404 | break; |
| 4405 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4406 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4407 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4408 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | resetcount++; |
| 4410 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4411 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4412 | * value of 0 means the call was successful. Any other |
| 4413 | * nonzero value is a failure, but if ERESTART is returned, |
| 4414 | * the driver may reset the HBA and try again. |
| 4415 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4416 | rc = lpfc_config_port_prep(phba); |
| 4417 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4418 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4419 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4420 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4422 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4423 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | lpfc_config_port(phba, pmb); |
| 4425 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4426 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4427 | LPFC_SLI3_HBQ_ENABLED | |
| 4428 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4429 | LPFC_SLI3_BG_ENABLED | |
| 4430 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4431 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4432 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4433 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4434 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4435 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4436 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4437 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4438 | spin_unlock_irq(&phba->hbalock); |
| 4439 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4440 | } else { |
| 4441 | /* Allow asynchronous mailbox command to go through */ |
| 4442 | spin_lock_irq(&phba->hbalock); |
| 4443 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4444 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4445 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4446 | |
| 4447 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4448 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4449 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4450 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4451 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4452 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4453 | if (!done) { |
| 4454 | rc = -EINVAL; |
| 4455 | goto do_prep_failed; |
| 4456 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4457 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4458 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4459 | rc = -ENXIO; |
| 4460 | goto do_prep_failed; |
| 4461 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4462 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4463 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4464 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4465 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4466 | phba->max_vpi : phba->max_vports; |
| 4467 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4468 | } else |
| 4469 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4470 | phba->fips_level = 0; |
| 4471 | phba->fips_spec_rev = 0; |
| 4472 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4473 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4474 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4475 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4476 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4477 | "2850 Security Crypto Active. FIPS x%d " |
| 4478 | "(Spec Rev: x%d)", |
| 4479 | phba->fips_level, phba->fips_spec_rev); |
| 4480 | } |
| 4481 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4482 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4483 | "2856 Config Port Security Crypto " |
| 4484 | "Error: x%x ", |
| 4485 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4486 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4487 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4488 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4489 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4490 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4491 | |
| 4492 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4493 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4494 | |
| 4495 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4496 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4497 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4498 | else |
| 4499 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4500 | "0443 Adapter did not grant " |
| 4501 | "BlockGuard\n"); |
| 4502 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4503 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4504 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4505 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4506 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4507 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4508 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4509 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4510 | return rc; |
| 4511 | } |
| 4512 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4513 | |
| 4514 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4515 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4516 | * @phba: Pointer to HBA context object. |
| 4517 | * |
| 4518 | * This function is the main SLI intialization function. This function |
| 4519 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4520 | * error attention handler code. Caller is not required to hold any |
| 4521 | * locks. This function issues config_port mailbox command to configure |
| 4522 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4523 | * calls the config_port_post function to issue init_link mailbox |
| 4524 | * command and to start the discovery. The function will return zero |
| 4525 | * if successful, else it will return negative error code. |
| 4526 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4527 | int |
| 4528 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4529 | { |
| 4530 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4531 | int mode = 3, i; |
| 4532 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4533 | |
| 4534 | switch (lpfc_sli_mode) { |
| 4535 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4536 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4538 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4539 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4540 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4541 | break; |
| 4542 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4543 | mode = 2; |
| 4544 | break; |
| 4545 | case 0: |
| 4546 | case 3: |
| 4547 | break; |
| 4548 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4549 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4550 | "1819 Unrecognized lpfc_sli_mode " |
| 4551 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4552 | |
| 4553 | break; |
| 4554 | } |
| 4555 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4556 | rc = lpfc_sli_config_port(phba, mode); |
| 4557 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4558 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4559 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4560 | "1820 Unable to select SLI-3. " |
| 4561 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4562 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4563 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4564 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4565 | goto lpfc_sli_hba_setup_error; |
| 4566 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4567 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4568 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4569 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4570 | if (!rc) { |
| 4571 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4572 | "2709 This device supports " |
| 4573 | "Advanced Error Reporting (AER)\n"); |
| 4574 | spin_lock_irq(&phba->hbalock); |
| 4575 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4576 | spin_unlock_irq(&phba->hbalock); |
| 4577 | } else { |
| 4578 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4579 | "2708 This device does not support " |
| 4580 | "Advanced Error Reporting (AER)\n"); |
| 4581 | phba->cfg_aer_support = 0; |
| 4582 | } |
| 4583 | } |
| 4584 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4585 | if (phba->sli_rev == 3) { |
| 4586 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4587 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4588 | } else { |
| 4589 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4590 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4591 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4595 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4596 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4597 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4598 | |
| 4599 | if (rc) |
| 4600 | goto lpfc_sli_hba_setup_error; |
| 4601 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4602 | /* Initialize VPIs. */ |
| 4603 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4604 | /* |
| 4605 | * The VPI bitmask and physical ID array are allocated |
| 4606 | * and initialized once only - at driver load. A port |
| 4607 | * reset doesn't need to reinitialize this memory. |
| 4608 | */ |
| 4609 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4610 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4611 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4612 | GFP_KERNEL); |
| 4613 | if (!phba->vpi_bmask) { |
| 4614 | rc = -ENOMEM; |
| 4615 | goto lpfc_sli_hba_setup_error; |
| 4616 | } |
| 4617 | |
| 4618 | phba->vpi_ids = kzalloc( |
| 4619 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4620 | GFP_KERNEL); |
| 4621 | if (!phba->vpi_ids) { |
| 4622 | kfree(phba->vpi_bmask); |
| 4623 | rc = -ENOMEM; |
| 4624 | goto lpfc_sli_hba_setup_error; |
| 4625 | } |
| 4626 | for (i = 0; i < phba->max_vpi; i++) |
| 4627 | phba->vpi_ids[i] = i; |
| 4628 | } |
| 4629 | } |
| 4630 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4631 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4632 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4633 | rc = lpfc_sli_hbq_setup(phba); |
| 4634 | if (rc) |
| 4635 | goto lpfc_sli_hba_setup_error; |
| 4636 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4637 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4638 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4639 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4640 | |
| 4641 | rc = lpfc_config_port_post(phba); |
| 4642 | if (rc) |
| 4643 | goto lpfc_sli_hba_setup_error; |
| 4644 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4645 | return rc; |
| 4646 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4647 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4648 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4649 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4650 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4651 | return rc; |
| 4652 | } |
| 4653 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4654 | /** |
| 4655 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4656 | * @phba: Pointer to HBA context object. |
| 4657 | * @mboxq: mailbox pointer. |
| 4658 | * This function issue a dump mailbox command to read config region |
| 4659 | * 23 and parse the records in the region and populate driver |
| 4660 | * data structure. |
| 4661 | **/ |
| 4662 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4663 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4664 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4665 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4666 | struct lpfc_dmabuf *mp; |
| 4667 | struct lpfc_mqe *mqe; |
| 4668 | uint32_t data_length; |
| 4669 | int rc; |
| 4670 | |
| 4671 | /* Program the default value of vlan_id and fc_map */ |
| 4672 | phba->valid_vlan = 0; |
| 4673 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4674 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4675 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4676 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4677 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4678 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4679 | return -ENOMEM; |
| 4680 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4681 | mqe = &mboxq->u.mqe; |
| 4682 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4683 | rc = -ENOMEM; |
| 4684 | goto out_free_mboxq; |
| 4685 | } |
| 4686 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4687 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4688 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4689 | |
| 4690 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4691 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4692 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4693 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4694 | "CQ: x%x x%x x%x x%x\n", |
| 4695 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4696 | bf_get(lpfc_mqe_command, mqe), |
| 4697 | bf_get(lpfc_mqe_status, mqe), |
| 4698 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4699 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4700 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4701 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4702 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4703 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4704 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4705 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4706 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4707 | mboxq->mcqe.word0, |
| 4708 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4709 | mboxq->mcqe.trailer); |
| 4710 | |
| 4711 | if (rc) { |
| 4712 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4713 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4714 | rc = -EIO; |
| 4715 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4716 | } |
| 4717 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4718 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4719 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4720 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4721 | rc = -EIO; |
| 4722 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4723 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4724 | |
| 4725 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4726 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4727 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4728 | rc = 0; |
| 4729 | |
| 4730 | out_free_mboxq: |
| 4731 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4732 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | /** |
| 4736 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4737 | * @phba: pointer to lpfc hba data structure. |
| 4738 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4739 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4740 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4741 | * On output, the number of data bytes in @vpd. |
| 4742 | * |
| 4743 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4744 | * addition, this routine gets the port vpd data. |
| 4745 | * |
| 4746 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4747 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4748 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4749 | **/ |
| 4750 | static int |
| 4751 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4752 | uint8_t *vpd, uint32_t *vpd_size) |
| 4753 | { |
| 4754 | int rc = 0; |
| 4755 | uint32_t dma_size; |
| 4756 | struct lpfc_dmabuf *dmabuf; |
| 4757 | struct lpfc_mqe *mqe; |
| 4758 | |
| 4759 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4760 | if (!dmabuf) |
| 4761 | return -ENOMEM; |
| 4762 | |
| 4763 | /* |
| 4764 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4765 | * mailbox command. |
| 4766 | */ |
| 4767 | dma_size = *vpd_size; |
| 4768 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 4769 | dma_size, |
| 4770 | &dmabuf->phys, |
| 4771 | GFP_KERNEL); |
| 4772 | if (!dmabuf->virt) { |
| 4773 | kfree(dmabuf); |
| 4774 | return -ENOMEM; |
| 4775 | } |
| 4776 | memset(dmabuf->virt, 0, dma_size); |
| 4777 | |
| 4778 | /* |
| 4779 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4780 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4781 | * in SLI3. This code corrects the conflicts. |
| 4782 | */ |
| 4783 | lpfc_read_rev(phba, mboxq); |
| 4784 | mqe = &mboxq->u.mqe; |
| 4785 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4786 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4787 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4788 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4789 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4790 | |
| 4791 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4792 | if (rc) { |
| 4793 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4794 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4795 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4796 | return -EIO; |
| 4797 | } |
| 4798 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4799 | /* |
| 4800 | * The available vpd length cannot be bigger than the |
| 4801 | * DMA buffer passed to the port. Catch the less than |
| 4802 | * case and update the caller's size. |
| 4803 | */ |
| 4804 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4805 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4806 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4807 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4808 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4809 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4810 | dmabuf->virt, dmabuf->phys); |
| 4811 | kfree(dmabuf); |
| 4812 | return 0; |
| 4813 | } |
| 4814 | |
| 4815 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4816 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4817 | * @phba: pointer to lpfc hba data structure. |
| 4818 | * |
| 4819 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4820 | * is attached to. |
| 4821 | * |
| 4822 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 4823 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4824 | * otherwise - failed to retrieve physical port name |
| 4825 | **/ |
| 4826 | static int |
| 4827 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4828 | { |
| 4829 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4830 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4831 | struct lpfc_controller_attribute *cntl_attr; |
| 4832 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4833 | void *virtaddr = NULL; |
| 4834 | uint32_t alloclen, reqlen; |
| 4835 | uint32_t shdr_status, shdr_add_status; |
| 4836 | union lpfc_sli4_cfg_shdr *shdr; |
| 4837 | char cport_name = 0; |
| 4838 | int rc; |
| 4839 | |
| 4840 | /* We assume nothing at this point */ |
| 4841 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4842 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4843 | |
| 4844 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4845 | if (!mboxq) |
| 4846 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4847 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4848 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4849 | lpfc_sli4_read_config(phba); |
| 4850 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4851 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4852 | |
| 4853 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4854 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4855 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4856 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4857 | LPFC_SLI4_MBX_NEMBED); |
| 4858 | if (alloclen < reqlen) { |
| 4859 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4860 | "3084 Allocated DMA memory size (%d) is " |
| 4861 | "less than the requested DMA memory size " |
| 4862 | "(%d)\n", alloclen, reqlen); |
| 4863 | rc = -ENOMEM; |
| 4864 | goto out_free_mboxq; |
| 4865 | } |
| 4866 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4867 | virtaddr = mboxq->sge_array->addr[0]; |
| 4868 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 4869 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 4870 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4871 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4872 | if (shdr_status || shdr_add_status || rc) { |
| 4873 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4874 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 4875 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4876 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4877 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4878 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4879 | rc, shdr_status, shdr_add_status); |
| 4880 | rc = -ENXIO; |
| 4881 | goto out_free_mboxq; |
| 4882 | } |
| 4883 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 4884 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 4885 | phba->sli4_hba.lnk_info.lnk_tp = |
| 4886 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 4887 | phba->sli4_hba.lnk_info.lnk_no = |
| 4888 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 4889 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4890 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 4891 | phba->sli4_hba.lnk_info.lnk_tp, |
| 4892 | phba->sli4_hba.lnk_info.lnk_no); |
| 4893 | |
| 4894 | retrieve_ppname: |
| 4895 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4896 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 4897 | sizeof(struct lpfc_mbx_get_port_name) - |
| 4898 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 4899 | LPFC_SLI4_MBX_EMBED); |
| 4900 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 4901 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 4902 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 4903 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 4904 | phba->sli4_hba.lnk_info.lnk_tp); |
| 4905 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4906 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4907 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4908 | if (shdr_status || shdr_add_status || rc) { |
| 4909 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4910 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 4911 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4912 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4913 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4914 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4915 | rc, shdr_status, shdr_add_status); |
| 4916 | rc = -ENXIO; |
| 4917 | goto out_free_mboxq; |
| 4918 | } |
| 4919 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4920 | case LPFC_LINK_NUMBER_0: |
| 4921 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 4922 | &get_port_name->u.response); |
| 4923 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4924 | break; |
| 4925 | case LPFC_LINK_NUMBER_1: |
| 4926 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 4927 | &get_port_name->u.response); |
| 4928 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4929 | break; |
| 4930 | case LPFC_LINK_NUMBER_2: |
| 4931 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 4932 | &get_port_name->u.response); |
| 4933 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4934 | break; |
| 4935 | case LPFC_LINK_NUMBER_3: |
| 4936 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 4937 | &get_port_name->u.response); |
| 4938 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4939 | break; |
| 4940 | default: |
| 4941 | break; |
| 4942 | } |
| 4943 | |
| 4944 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 4945 | phba->Port[0] = cport_name; |
| 4946 | phba->Port[1] = '\0'; |
| 4947 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4948 | "3091 SLI get port name: %s\n", phba->Port); |
| 4949 | } |
| 4950 | |
| 4951 | out_free_mboxq: |
| 4952 | if (rc != MBX_TIMEOUT) { |
| 4953 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 4954 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 4955 | else |
| 4956 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4957 | } |
| 4958 | return rc; |
| 4959 | } |
| 4960 | |
| 4961 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4962 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 4963 | * @phba: pointer to lpfc hba data structure. |
| 4964 | * |
| 4965 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 4966 | * event queues |
| 4967 | **/ |
| 4968 | static void |
| 4969 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 4970 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 4971 | int fcp_eqidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4972 | |
| 4973 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 4974 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4975 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4976 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4977 | do { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4978 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 4979 | LPFC_QUEUE_REARM); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4980 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4981 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4982 | if (phba->sli4_hba.hba_eq) { |
| 4983 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4984 | fcp_eqidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4985 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4986 | LPFC_QUEUE_REARM); |
| 4987 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4991 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 4992 | * @phba: Pointer to HBA context object. |
| 4993 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4994 | * @extnt_count: buffer to hold port available extent count. |
| 4995 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4996 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4997 | * This function calls the port and retrievs the number of available |
| 4998 | * extents and their size for a particular extent type. |
| 4999 | * |
| 5000 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5001 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5002 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5003 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5004 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5005 | { |
| 5006 | int rc = 0; |
| 5007 | uint32_t length; |
| 5008 | uint32_t mbox_tmo; |
| 5009 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5010 | LPFC_MBOXQ_t *mbox; |
| 5011 | |
| 5012 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5013 | if (!mbox) |
| 5014 | return -ENOMEM; |
| 5015 | |
| 5016 | /* Find out how many extents are available for this resource type */ |
| 5017 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5018 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5019 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5020 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5021 | length, LPFC_SLI4_MBX_EMBED); |
| 5022 | |
| 5023 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5024 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5025 | LPFC_SLI4_MBX_EMBED); |
| 5026 | if (unlikely(rc)) { |
| 5027 | rc = -EIO; |
| 5028 | goto err_exit; |
| 5029 | } |
| 5030 | |
| 5031 | if (!phba->sli4_hba.intr_enable) |
| 5032 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5033 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5034 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5035 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5036 | } |
| 5037 | if (unlikely(rc)) { |
| 5038 | rc = -EIO; |
| 5039 | goto err_exit; |
| 5040 | } |
| 5041 | |
| 5042 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5043 | if (bf_get(lpfc_mbox_hdr_status, |
| 5044 | &rsrc_info->header.cfg_shdr.response)) { |
| 5045 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5046 | "2930 Failed to get resource extents " |
| 5047 | "Status 0x%x Add'l Status 0x%x\n", |
| 5048 | bf_get(lpfc_mbox_hdr_status, |
| 5049 | &rsrc_info->header.cfg_shdr.response), |
| 5050 | bf_get(lpfc_mbox_hdr_add_status, |
| 5051 | &rsrc_info->header.cfg_shdr.response)); |
| 5052 | rc = -EIO; |
| 5053 | goto err_exit; |
| 5054 | } |
| 5055 | |
| 5056 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5057 | &rsrc_info->u.rsp); |
| 5058 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5059 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5060 | |
| 5061 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5062 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5063 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5064 | |
| 5065 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5066 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5067 | return rc; |
| 5068 | } |
| 5069 | |
| 5070 | /** |
| 5071 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5072 | * @phba: Pointer to HBA context object. |
| 5073 | * @type: The extent type to check. |
| 5074 | * |
| 5075 | * This function reads the current available extents from the port and checks |
| 5076 | * if the extent count or extent size has changed since the last access. |
| 5077 | * Callers use this routine post port reset to understand if there is a |
| 5078 | * extent reprovisioning requirement. |
| 5079 | * |
| 5080 | * Returns: |
| 5081 | * -Error: error indicates problem. |
| 5082 | * 1: Extent count or size has changed. |
| 5083 | * 0: No changes. |
| 5084 | **/ |
| 5085 | static int |
| 5086 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5087 | { |
| 5088 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5089 | uint16_t size_diff, rsrc_ext_size; |
| 5090 | int rc = 0; |
| 5091 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5092 | struct list_head *rsrc_blk_list = NULL; |
| 5093 | |
| 5094 | size_diff = 0; |
| 5095 | curr_ext_cnt = 0; |
| 5096 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5097 | &rsrc_ext_cnt, |
| 5098 | &rsrc_ext_size); |
| 5099 | if (unlikely(rc)) |
| 5100 | return -EIO; |
| 5101 | |
| 5102 | switch (type) { |
| 5103 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5104 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5105 | break; |
| 5106 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5107 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5108 | break; |
| 5109 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5110 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5111 | break; |
| 5112 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5113 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5114 | break; |
| 5115 | default: |
| 5116 | break; |
| 5117 | } |
| 5118 | |
| 5119 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5120 | curr_ext_cnt++; |
| 5121 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5122 | size_diff++; |
| 5123 | } |
| 5124 | |
| 5125 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5126 | rc = 1; |
| 5127 | |
| 5128 | return rc; |
| 5129 | } |
| 5130 | |
| 5131 | /** |
| 5132 | * lpfc_sli4_cfg_post_extnts - |
| 5133 | * @phba: Pointer to HBA context object. |
| 5134 | * @extnt_cnt - number of available extents. |
| 5135 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5136 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5137 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5138 | * |
| 5139 | * This function executes the extents allocation request. It also |
| 5140 | * takes care of the amount of memory needed to allocate or get the |
| 5141 | * allocated extents. It is the caller's responsibility to evaluate |
| 5142 | * the response. |
| 5143 | * |
| 5144 | * Returns: |
| 5145 | * -Error: Error value describes the condition found. |
| 5146 | * 0: if successful |
| 5147 | **/ |
| 5148 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5149 | 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] | 5150 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5151 | { |
| 5152 | int rc = 0; |
| 5153 | uint32_t req_len; |
| 5154 | uint32_t emb_len; |
| 5155 | uint32_t alloc_len, mbox_tmo; |
| 5156 | |
| 5157 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5158 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5159 | |
| 5160 | /* |
| 5161 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5162 | * accounts for extents-specific word. |
| 5163 | */ |
| 5164 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5165 | sizeof(uint32_t); |
| 5166 | |
| 5167 | /* |
| 5168 | * Presume the allocation and response will fit into an embedded |
| 5169 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5170 | */ |
| 5171 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5172 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5173 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5174 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5175 | sizeof(uint32_t); |
| 5176 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5177 | } |
| 5178 | |
| 5179 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5180 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5181 | req_len, *emb); |
| 5182 | if (alloc_len < req_len) { |
| 5183 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5184 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5185 | "less than the requested DMA memory " |
| 5186 | "size (x%x)\n", alloc_len, req_len); |
| 5187 | return -ENOMEM; |
| 5188 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5189 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5190 | if (unlikely(rc)) |
| 5191 | return -EIO; |
| 5192 | |
| 5193 | if (!phba->sli4_hba.intr_enable) |
| 5194 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5195 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5196 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5197 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5198 | } |
| 5199 | |
| 5200 | if (unlikely(rc)) |
| 5201 | rc = -EIO; |
| 5202 | return rc; |
| 5203 | } |
| 5204 | |
| 5205 | /** |
| 5206 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5207 | * @phba: Pointer to HBA context object. |
| 5208 | * @type: The resource extent type to allocate. |
| 5209 | * |
| 5210 | * This function allocates the number of elements for the specified |
| 5211 | * resource type. |
| 5212 | **/ |
| 5213 | static int |
| 5214 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5215 | { |
| 5216 | bool emb = false; |
| 5217 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5218 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5219 | uint16_t *ids; |
| 5220 | int i, rc; |
| 5221 | unsigned long longs; |
| 5222 | unsigned long *bmask; |
| 5223 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5224 | LPFC_MBOXQ_t *mbox; |
| 5225 | uint32_t length; |
| 5226 | struct lpfc_id_range *id_array = NULL; |
| 5227 | void *virtaddr = NULL; |
| 5228 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5229 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5230 | struct list_head *ext_blk_list; |
| 5231 | |
| 5232 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5233 | &rsrc_cnt, |
| 5234 | &rsrc_size); |
| 5235 | if (unlikely(rc)) |
| 5236 | return -EIO; |
| 5237 | |
| 5238 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5239 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5240 | "3009 No available Resource Extents " |
| 5241 | "for resource type 0x%x: Count: 0x%x, " |
| 5242 | "Size 0x%x\n", type, rsrc_cnt, |
| 5243 | rsrc_size); |
| 5244 | return -ENOMEM; |
| 5245 | } |
| 5246 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5247 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5248 | "2903 Post resource extents type-0x%x: " |
| 5249 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5250 | |
| 5251 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5252 | if (!mbox) |
| 5253 | return -ENOMEM; |
| 5254 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5255 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5256 | if (unlikely(rc)) { |
| 5257 | rc = -EIO; |
| 5258 | goto err_exit; |
| 5259 | } |
| 5260 | |
| 5261 | /* |
| 5262 | * Figure out where the response is located. Then get local pointers |
| 5263 | * to the response data. The port does not guarantee to respond to |
| 5264 | * all extents counts request so update the local variable with the |
| 5265 | * allocated count from the port. |
| 5266 | */ |
| 5267 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5268 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5269 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5270 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5271 | } else { |
| 5272 | virtaddr = mbox->sge_array->addr[0]; |
| 5273 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5274 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5275 | id_array = &n_rsrc->id; |
| 5276 | } |
| 5277 | |
| 5278 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5279 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5280 | |
| 5281 | /* |
| 5282 | * Based on the resource size and count, correct the base and max |
| 5283 | * resource values. |
| 5284 | */ |
| 5285 | length = sizeof(struct lpfc_rsrc_blks); |
| 5286 | switch (type) { |
| 5287 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5288 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5289 | sizeof(unsigned long), |
| 5290 | GFP_KERNEL); |
| 5291 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5292 | rc = -ENOMEM; |
| 5293 | goto err_exit; |
| 5294 | } |
| 5295 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5296 | sizeof(uint16_t), |
| 5297 | GFP_KERNEL); |
| 5298 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5299 | kfree(phba->sli4_hba.rpi_bmask); |
| 5300 | rc = -ENOMEM; |
| 5301 | goto err_exit; |
| 5302 | } |
| 5303 | |
| 5304 | /* |
| 5305 | * The next_rpi was initialized with the maximum available |
| 5306 | * count but the port may allocate a smaller number. Catch |
| 5307 | * that case and update the next_rpi. |
| 5308 | */ |
| 5309 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5310 | |
| 5311 | /* Initialize local ptrs for common extent processing later. */ |
| 5312 | bmask = phba->sli4_hba.rpi_bmask; |
| 5313 | ids = phba->sli4_hba.rpi_ids; |
| 5314 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5315 | break; |
| 5316 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5317 | phba->vpi_bmask = kzalloc(longs * |
| 5318 | sizeof(unsigned long), |
| 5319 | GFP_KERNEL); |
| 5320 | if (unlikely(!phba->vpi_bmask)) { |
| 5321 | rc = -ENOMEM; |
| 5322 | goto err_exit; |
| 5323 | } |
| 5324 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5325 | sizeof(uint16_t), |
| 5326 | GFP_KERNEL); |
| 5327 | if (unlikely(!phba->vpi_ids)) { |
| 5328 | kfree(phba->vpi_bmask); |
| 5329 | rc = -ENOMEM; |
| 5330 | goto err_exit; |
| 5331 | } |
| 5332 | |
| 5333 | /* Initialize local ptrs for common extent processing later. */ |
| 5334 | bmask = phba->vpi_bmask; |
| 5335 | ids = phba->vpi_ids; |
| 5336 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5337 | break; |
| 5338 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5339 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5340 | sizeof(unsigned long), |
| 5341 | GFP_KERNEL); |
| 5342 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5343 | rc = -ENOMEM; |
| 5344 | goto err_exit; |
| 5345 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5346 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5347 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5348 | sizeof(uint16_t), |
| 5349 | GFP_KERNEL); |
| 5350 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5351 | kfree(phba->sli4_hba.xri_bmask); |
| 5352 | rc = -ENOMEM; |
| 5353 | goto err_exit; |
| 5354 | } |
| 5355 | |
| 5356 | /* Initialize local ptrs for common extent processing later. */ |
| 5357 | bmask = phba->sli4_hba.xri_bmask; |
| 5358 | ids = phba->sli4_hba.xri_ids; |
| 5359 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5360 | break; |
| 5361 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5362 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5363 | sizeof(unsigned long), |
| 5364 | GFP_KERNEL); |
| 5365 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5366 | rc = -ENOMEM; |
| 5367 | goto err_exit; |
| 5368 | } |
| 5369 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5370 | sizeof(uint16_t), |
| 5371 | GFP_KERNEL); |
| 5372 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5373 | kfree(phba->sli4_hba.vfi_bmask); |
| 5374 | rc = -ENOMEM; |
| 5375 | goto err_exit; |
| 5376 | } |
| 5377 | |
| 5378 | /* Initialize local ptrs for common extent processing later. */ |
| 5379 | bmask = phba->sli4_hba.vfi_bmask; |
| 5380 | ids = phba->sli4_hba.vfi_ids; |
| 5381 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5382 | break; |
| 5383 | default: |
| 5384 | /* Unsupported Opcode. Fail call. */ |
| 5385 | id_array = NULL; |
| 5386 | bmask = NULL; |
| 5387 | ids = NULL; |
| 5388 | ext_blk_list = NULL; |
| 5389 | goto err_exit; |
| 5390 | } |
| 5391 | |
| 5392 | /* |
| 5393 | * Complete initializing the extent configuration with the |
| 5394 | * allocated ids assigned to this function. The bitmask serves |
| 5395 | * as an index into the array and manages the available ids. The |
| 5396 | * array just stores the ids communicated to the port via the wqes. |
| 5397 | */ |
| 5398 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5399 | if ((i % 2) == 0) |
| 5400 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5401 | &id_array[k]); |
| 5402 | else |
| 5403 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5404 | &id_array[k]); |
| 5405 | |
| 5406 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5407 | if (unlikely(!rsrc_blks)) { |
| 5408 | rc = -ENOMEM; |
| 5409 | kfree(bmask); |
| 5410 | kfree(ids); |
| 5411 | goto err_exit; |
| 5412 | } |
| 5413 | rsrc_blks->rsrc_start = rsrc_id; |
| 5414 | rsrc_blks->rsrc_size = rsrc_size; |
| 5415 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5416 | rsrc_start = rsrc_id; |
| 5417 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5418 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5419 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5420 | |
| 5421 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5422 | ids[j] = rsrc_id; |
| 5423 | rsrc_id++; |
| 5424 | j++; |
| 5425 | } |
| 5426 | /* Entire word processed. Get next word.*/ |
| 5427 | if ((i % 2) == 1) |
| 5428 | k++; |
| 5429 | } |
| 5430 | err_exit: |
| 5431 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5432 | return rc; |
| 5433 | } |
| 5434 | |
| 5435 | /** |
| 5436 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5437 | * @phba: Pointer to HBA context object. |
| 5438 | * @type: the extent's type. |
| 5439 | * |
| 5440 | * This function deallocates all extents of a particular resource type. |
| 5441 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5442 | * is the caller's responsibility to release all kernel memory resources. |
| 5443 | **/ |
| 5444 | static int |
| 5445 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5446 | { |
| 5447 | int rc; |
| 5448 | uint32_t length, mbox_tmo = 0; |
| 5449 | LPFC_MBOXQ_t *mbox; |
| 5450 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5451 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5452 | |
| 5453 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5454 | if (!mbox) |
| 5455 | return -ENOMEM; |
| 5456 | |
| 5457 | /* |
| 5458 | * This function sends an embedded mailbox because it only sends the |
| 5459 | * the resource type. All extents of this type are released by the |
| 5460 | * port. |
| 5461 | */ |
| 5462 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5463 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5464 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5465 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5466 | length, LPFC_SLI4_MBX_EMBED); |
| 5467 | |
| 5468 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5469 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5470 | LPFC_SLI4_MBX_EMBED); |
| 5471 | if (unlikely(rc)) { |
| 5472 | rc = -EIO; |
| 5473 | goto out_free_mbox; |
| 5474 | } |
| 5475 | if (!phba->sli4_hba.intr_enable) |
| 5476 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5477 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5478 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5479 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5480 | } |
| 5481 | if (unlikely(rc)) { |
| 5482 | rc = -EIO; |
| 5483 | goto out_free_mbox; |
| 5484 | } |
| 5485 | |
| 5486 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5487 | if (bf_get(lpfc_mbox_hdr_status, |
| 5488 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5489 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5490 | "2919 Failed to release resource extents " |
| 5491 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5492 | "Resource memory not released.\n", |
| 5493 | type, |
| 5494 | bf_get(lpfc_mbox_hdr_status, |
| 5495 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5496 | bf_get(lpfc_mbox_hdr_add_status, |
| 5497 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5498 | rc = -EIO; |
| 5499 | goto out_free_mbox; |
| 5500 | } |
| 5501 | |
| 5502 | /* Release kernel memory resources for the specific type. */ |
| 5503 | switch (type) { |
| 5504 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5505 | kfree(phba->vpi_bmask); |
| 5506 | kfree(phba->vpi_ids); |
| 5507 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5508 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5509 | &phba->lpfc_vpi_blk_list, list) { |
| 5510 | list_del_init(&rsrc_blk->list); |
| 5511 | kfree(rsrc_blk); |
| 5512 | } |
| 5513 | break; |
| 5514 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5515 | kfree(phba->sli4_hba.xri_bmask); |
| 5516 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5517 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5518 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5519 | list_del_init(&rsrc_blk->list); |
| 5520 | kfree(rsrc_blk); |
| 5521 | } |
| 5522 | break; |
| 5523 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5524 | kfree(phba->sli4_hba.vfi_bmask); |
| 5525 | kfree(phba->sli4_hba.vfi_ids); |
| 5526 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5527 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5528 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5529 | list_del_init(&rsrc_blk->list); |
| 5530 | kfree(rsrc_blk); |
| 5531 | } |
| 5532 | break; |
| 5533 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5534 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5535 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5536 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5537 | list_del_init(&rsrc_blk->list); |
| 5538 | kfree(rsrc_blk); |
| 5539 | } |
| 5540 | break; |
| 5541 | default: |
| 5542 | break; |
| 5543 | } |
| 5544 | |
| 5545 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5546 | |
| 5547 | out_free_mbox: |
| 5548 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5549 | return rc; |
| 5550 | } |
| 5551 | |
| 5552 | /** |
| 5553 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5554 | * @phba: Pointer to HBA context object. |
| 5555 | * |
| 5556 | * This function allocates all SLI4 resource identifiers. |
| 5557 | **/ |
| 5558 | int |
| 5559 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5560 | { |
| 5561 | int i, rc, error = 0; |
| 5562 | uint16_t count, base; |
| 5563 | unsigned long longs; |
| 5564 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5565 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5566 | 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] | 5567 | if (phba->sli4_hba.extents_in_use) { |
| 5568 | /* |
| 5569 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5570 | * resource extent count must be read and allocated before |
| 5571 | * provisioning the resource id arrays. |
| 5572 | */ |
| 5573 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5574 | LPFC_IDX_RSRC_RDY) { |
| 5575 | /* |
| 5576 | * Extent-based resources are set - the driver could |
| 5577 | * be in a port reset. Figure out if any corrective |
| 5578 | * actions need to be taken. |
| 5579 | */ |
| 5580 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5581 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5582 | if (rc != 0) |
| 5583 | error++; |
| 5584 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5585 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5586 | if (rc != 0) |
| 5587 | error++; |
| 5588 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5589 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5590 | if (rc != 0) |
| 5591 | error++; |
| 5592 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5593 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5594 | if (rc != 0) |
| 5595 | error++; |
| 5596 | |
| 5597 | /* |
| 5598 | * It's possible that the number of resources |
| 5599 | * provided to this port instance changed between |
| 5600 | * resets. Detect this condition and reallocate |
| 5601 | * resources. Otherwise, there is no action. |
| 5602 | */ |
| 5603 | if (error) { |
| 5604 | lpfc_printf_log(phba, KERN_INFO, |
| 5605 | LOG_MBOX | LOG_INIT, |
| 5606 | "2931 Detected extent resource " |
| 5607 | "change. Reallocating all " |
| 5608 | "extents.\n"); |
| 5609 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5610 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5611 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5612 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5613 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5614 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5615 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5616 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5617 | } else |
| 5618 | return 0; |
| 5619 | } |
| 5620 | |
| 5621 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5622 | if (unlikely(rc)) |
| 5623 | goto err_exit; |
| 5624 | |
| 5625 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5626 | if (unlikely(rc)) |
| 5627 | goto err_exit; |
| 5628 | |
| 5629 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5630 | if (unlikely(rc)) |
| 5631 | goto err_exit; |
| 5632 | |
| 5633 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5634 | if (unlikely(rc)) |
| 5635 | goto err_exit; |
| 5636 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5637 | LPFC_IDX_RSRC_RDY); |
| 5638 | return rc; |
| 5639 | } else { |
| 5640 | /* |
| 5641 | * The port does not support resource extents. The XRI, VPI, |
| 5642 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5643 | * Just allocate the bitmasks and provision the resource id |
| 5644 | * arrays. If a port reset is active, the resources don't |
| 5645 | * need any action - just exit. |
| 5646 | */ |
| 5647 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5648 | LPFC_IDX_RSRC_RDY) { |
| 5649 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5650 | lpfc_sli4_remove_rpis(phba); |
| 5651 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5652 | /* RPIs. */ |
| 5653 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5654 | if (count <= 0) { |
| 5655 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5656 | "3279 Invalid provisioning of " |
| 5657 | "rpi:%d\n", count); |
| 5658 | rc = -EINVAL; |
| 5659 | goto err_exit; |
| 5660 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5661 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5662 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5663 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5664 | sizeof(unsigned long), |
| 5665 | GFP_KERNEL); |
| 5666 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5667 | rc = -ENOMEM; |
| 5668 | goto err_exit; |
| 5669 | } |
| 5670 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5671 | sizeof(uint16_t), |
| 5672 | GFP_KERNEL); |
| 5673 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5674 | rc = -ENOMEM; |
| 5675 | goto free_rpi_bmask; |
| 5676 | } |
| 5677 | |
| 5678 | for (i = 0; i < count; i++) |
| 5679 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5680 | |
| 5681 | /* VPIs. */ |
| 5682 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5683 | if (count <= 0) { |
| 5684 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5685 | "3280 Invalid provisioning of " |
| 5686 | "vpi:%d\n", count); |
| 5687 | rc = -EINVAL; |
| 5688 | goto free_rpi_ids; |
| 5689 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5690 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5691 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5692 | phba->vpi_bmask = kzalloc(longs * |
| 5693 | sizeof(unsigned long), |
| 5694 | GFP_KERNEL); |
| 5695 | if (unlikely(!phba->vpi_bmask)) { |
| 5696 | rc = -ENOMEM; |
| 5697 | goto free_rpi_ids; |
| 5698 | } |
| 5699 | phba->vpi_ids = kzalloc(count * |
| 5700 | sizeof(uint16_t), |
| 5701 | GFP_KERNEL); |
| 5702 | if (unlikely(!phba->vpi_ids)) { |
| 5703 | rc = -ENOMEM; |
| 5704 | goto free_vpi_bmask; |
| 5705 | } |
| 5706 | |
| 5707 | for (i = 0; i < count; i++) |
| 5708 | phba->vpi_ids[i] = base + i; |
| 5709 | |
| 5710 | /* XRIs. */ |
| 5711 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5712 | if (count <= 0) { |
| 5713 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5714 | "3281 Invalid provisioning of " |
| 5715 | "xri:%d\n", count); |
| 5716 | rc = -EINVAL; |
| 5717 | goto free_vpi_ids; |
| 5718 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5719 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5720 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5721 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5722 | sizeof(unsigned long), |
| 5723 | GFP_KERNEL); |
| 5724 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5725 | rc = -ENOMEM; |
| 5726 | goto free_vpi_ids; |
| 5727 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5728 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5729 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5730 | sizeof(uint16_t), |
| 5731 | GFP_KERNEL); |
| 5732 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5733 | rc = -ENOMEM; |
| 5734 | goto free_xri_bmask; |
| 5735 | } |
| 5736 | |
| 5737 | for (i = 0; i < count; i++) |
| 5738 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5739 | |
| 5740 | /* VFIs. */ |
| 5741 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5742 | if (count <= 0) { |
| 5743 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5744 | "3282 Invalid provisioning of " |
| 5745 | "vfi:%d\n", count); |
| 5746 | rc = -EINVAL; |
| 5747 | goto free_xri_ids; |
| 5748 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5749 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5750 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5751 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5752 | sizeof(unsigned long), |
| 5753 | GFP_KERNEL); |
| 5754 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5755 | rc = -ENOMEM; |
| 5756 | goto free_xri_ids; |
| 5757 | } |
| 5758 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5759 | sizeof(uint16_t), |
| 5760 | GFP_KERNEL); |
| 5761 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5762 | rc = -ENOMEM; |
| 5763 | goto free_vfi_bmask; |
| 5764 | } |
| 5765 | |
| 5766 | for (i = 0; i < count; i++) |
| 5767 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5768 | |
| 5769 | /* |
| 5770 | * Mark all resources ready. An HBA reset doesn't need |
| 5771 | * to reset the initialization. |
| 5772 | */ |
| 5773 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5774 | LPFC_IDX_RSRC_RDY); |
| 5775 | return 0; |
| 5776 | } |
| 5777 | |
| 5778 | free_vfi_bmask: |
| 5779 | kfree(phba->sli4_hba.vfi_bmask); |
| 5780 | free_xri_ids: |
| 5781 | kfree(phba->sli4_hba.xri_ids); |
| 5782 | free_xri_bmask: |
| 5783 | kfree(phba->sli4_hba.xri_bmask); |
| 5784 | free_vpi_ids: |
| 5785 | kfree(phba->vpi_ids); |
| 5786 | free_vpi_bmask: |
| 5787 | kfree(phba->vpi_bmask); |
| 5788 | free_rpi_ids: |
| 5789 | kfree(phba->sli4_hba.rpi_ids); |
| 5790 | free_rpi_bmask: |
| 5791 | kfree(phba->sli4_hba.rpi_bmask); |
| 5792 | err_exit: |
| 5793 | return rc; |
| 5794 | } |
| 5795 | |
| 5796 | /** |
| 5797 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5798 | * @phba: Pointer to HBA context object. |
| 5799 | * |
| 5800 | * This function allocates the number of elements for the specified |
| 5801 | * resource type. |
| 5802 | **/ |
| 5803 | int |
| 5804 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5805 | { |
| 5806 | if (phba->sli4_hba.extents_in_use) { |
| 5807 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5808 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5809 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5810 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5811 | } else { |
| 5812 | kfree(phba->vpi_bmask); |
| 5813 | kfree(phba->vpi_ids); |
| 5814 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5815 | kfree(phba->sli4_hba.xri_bmask); |
| 5816 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5817 | kfree(phba->sli4_hba.vfi_bmask); |
| 5818 | kfree(phba->sli4_hba.vfi_ids); |
| 5819 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5820 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5821 | } |
| 5822 | |
| 5823 | return 0; |
| 5824 | } |
| 5825 | |
| 5826 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5827 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5828 | * @phba: Pointer to HBA context object. |
| 5829 | * @type: The resource extent type. |
| 5830 | * @extnt_count: buffer to hold port extent count response |
| 5831 | * @extnt_size: buffer to hold port extent size response. |
| 5832 | * |
| 5833 | * This function calls the port to read the host allocated extents |
| 5834 | * for a particular type. |
| 5835 | **/ |
| 5836 | int |
| 5837 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5838 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5839 | { |
| 5840 | bool emb; |
| 5841 | int rc = 0; |
| 5842 | uint16_t curr_blks = 0; |
| 5843 | uint32_t req_len, emb_len; |
| 5844 | uint32_t alloc_len, mbox_tmo; |
| 5845 | struct list_head *blk_list_head; |
| 5846 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5847 | LPFC_MBOXQ_t *mbox; |
| 5848 | void *virtaddr = NULL; |
| 5849 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5850 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5851 | union lpfc_sli4_cfg_shdr *shdr; |
| 5852 | |
| 5853 | switch (type) { |
| 5854 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5855 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 5856 | break; |
| 5857 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5858 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5859 | break; |
| 5860 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5861 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5862 | break; |
| 5863 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5864 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5865 | break; |
| 5866 | default: |
| 5867 | return -EIO; |
| 5868 | } |
| 5869 | |
| 5870 | /* Count the number of extents currently allocatd for this type. */ |
| 5871 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 5872 | if (curr_blks == 0) { |
| 5873 | /* |
| 5874 | * The GET_ALLOCATED mailbox does not return the size, |
| 5875 | * just the count. The size should be just the size |
| 5876 | * stored in the current allocated block and all sizes |
| 5877 | * for an extent type are the same so set the return |
| 5878 | * value now. |
| 5879 | */ |
| 5880 | *extnt_size = rsrc_blk->rsrc_size; |
| 5881 | } |
| 5882 | curr_blks++; |
| 5883 | } |
| 5884 | |
| 5885 | /* Calculate the total requested length of the dma memory. */ |
| 5886 | req_len = curr_blks * sizeof(uint16_t); |
| 5887 | |
| 5888 | /* |
| 5889 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5890 | * accounts for extents-specific word. |
| 5891 | */ |
| 5892 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5893 | sizeof(uint32_t); |
| 5894 | |
| 5895 | /* |
| 5896 | * Presume the allocation and response will fit into an embedded |
| 5897 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5898 | */ |
| 5899 | emb = LPFC_SLI4_MBX_EMBED; |
| 5900 | req_len = emb_len; |
| 5901 | if (req_len > emb_len) { |
| 5902 | req_len = curr_blks * sizeof(uint16_t) + |
| 5903 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5904 | sizeof(uint32_t); |
| 5905 | emb = LPFC_SLI4_MBX_NEMBED; |
| 5906 | } |
| 5907 | |
| 5908 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5909 | if (!mbox) |
| 5910 | return -ENOMEM; |
| 5911 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 5912 | |
| 5913 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5914 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 5915 | req_len, emb); |
| 5916 | if (alloc_len < req_len) { |
| 5917 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5918 | "2983 Allocated DMA memory size (x%x) is " |
| 5919 | "less than the requested DMA memory " |
| 5920 | "size (x%x)\n", alloc_len, req_len); |
| 5921 | rc = -ENOMEM; |
| 5922 | goto err_exit; |
| 5923 | } |
| 5924 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 5925 | if (unlikely(rc)) { |
| 5926 | rc = -EIO; |
| 5927 | goto err_exit; |
| 5928 | } |
| 5929 | |
| 5930 | if (!phba->sli4_hba.intr_enable) |
| 5931 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5932 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5933 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5934 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5935 | } |
| 5936 | |
| 5937 | if (unlikely(rc)) { |
| 5938 | rc = -EIO; |
| 5939 | goto err_exit; |
| 5940 | } |
| 5941 | |
| 5942 | /* |
| 5943 | * Figure out where the response is located. Then get local pointers |
| 5944 | * to the response data. The port does not guarantee to respond to |
| 5945 | * all extents counts request so update the local variable with the |
| 5946 | * allocated count from the port. |
| 5947 | */ |
| 5948 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5949 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5950 | shdr = &rsrc_ext->header.cfg_shdr; |
| 5951 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5952 | } else { |
| 5953 | virtaddr = mbox->sge_array->addr[0]; |
| 5954 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5955 | shdr = &n_rsrc->cfg_shdr; |
| 5956 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5957 | } |
| 5958 | |
| 5959 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 5960 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5961 | "2984 Failed to read allocated resources " |
| 5962 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 5963 | type, |
| 5964 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 5965 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 5966 | rc = -EIO; |
| 5967 | goto err_exit; |
| 5968 | } |
| 5969 | err_exit: |
| 5970 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5971 | return rc; |
| 5972 | } |
| 5973 | |
| 5974 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5975 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 5976 | * @phba: pointer to lpfc hba data structure. |
| 5977 | * |
| 5978 | * This routine walks the list of els buffers that have been allocated and |
| 5979 | * repost them to the port by using SGL block post. This is needed after a |
| 5980 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 5981 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 5982 | * SGL block post mailbox commands to post them to the port. For single els |
| 5983 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 5984 | * mailbox command for posting. |
| 5985 | * |
| 5986 | * Returns: 0 = success, non-zero failure. |
| 5987 | **/ |
| 5988 | static int |
| 5989 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 5990 | { |
| 5991 | struct lpfc_sglq *sglq_entry = NULL; |
| 5992 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 5993 | struct lpfc_sglq *sglq_entry_first = NULL; |
| 5994 | int status, post_cnt = 0, num_posted = 0, block_cnt = 0; |
| 5995 | int last_xritag = NO_XRI; |
| 5996 | LIST_HEAD(prep_sgl_list); |
| 5997 | LIST_HEAD(blck_sgl_list); |
| 5998 | LIST_HEAD(allc_sgl_list); |
| 5999 | LIST_HEAD(post_sgl_list); |
| 6000 | LIST_HEAD(free_sgl_list); |
| 6001 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame^] | 6002 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6003 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame^] | 6004 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6005 | |
| 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); |
| 6057 | spin_lock_irq(&phba->hbalock); |
| 6058 | phba->sli4_hba.els_xri_cnt--; |
| 6059 | spin_unlock_irq(&phba->hbalock); |
| 6060 | } |
| 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | /* continue until a nembed page worth of sgls */ |
| 6065 | if (post_cnt == 0) |
| 6066 | continue; |
| 6067 | |
| 6068 | /* post the els buffer list sgls as a block */ |
| 6069 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 6070 | post_cnt); |
| 6071 | |
| 6072 | if (!status) { |
| 6073 | /* success, put sgl list to posted sgl list */ |
| 6074 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6075 | } else { |
| 6076 | /* Failure, put sgl list to free sgl list */ |
| 6077 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6078 | struct lpfc_sglq, |
| 6079 | list); |
| 6080 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6081 | "3160 Failed to post els sgl-list, " |
| 6082 | "xritag:x%x-x%x\n", |
| 6083 | sglq_entry_first->sli4_xritag, |
| 6084 | (sglq_entry_first->sli4_xritag + |
| 6085 | post_cnt - 1)); |
| 6086 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
| 6087 | spin_lock_irq(&phba->hbalock); |
| 6088 | phba->sli4_hba.els_xri_cnt -= post_cnt; |
| 6089 | spin_unlock_irq(&phba->hbalock); |
| 6090 | } |
| 6091 | |
| 6092 | /* don't reset xirtag due to hole in xri block */ |
| 6093 | if (block_cnt == 0) |
| 6094 | last_xritag = NO_XRI; |
| 6095 | |
| 6096 | /* reset els sgl post count for next round of posting */ |
| 6097 | post_cnt = 0; |
| 6098 | } |
| 6099 | |
| 6100 | /* free the els sgls failed to post */ |
| 6101 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6102 | |
| 6103 | /* push els sgls posted to the availble list */ |
| 6104 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame^] | 6105 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6106 | list_splice_init(&post_sgl_list, |
| 6107 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame^] | 6108 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6109 | } else { |
| 6110 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6111 | "3161 Failure to post els sgl to port.\n"); |
| 6112 | return -EIO; |
| 6113 | } |
| 6114 | return 0; |
| 6115 | } |
| 6116 | |
| 6117 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6118 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6119 | * @phba: Pointer to HBA context object. |
| 6120 | * |
| 6121 | * This function is the main SLI4 device intialization PCI function. This |
| 6122 | * function is called by the HBA intialization code, HBA reset code and |
| 6123 | * HBA error attention handler code. Caller is not required to hold any |
| 6124 | * locks. |
| 6125 | **/ |
| 6126 | int |
| 6127 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6128 | { |
| 6129 | int rc; |
| 6130 | LPFC_MBOXQ_t *mboxq; |
| 6131 | struct lpfc_mqe *mqe; |
| 6132 | uint8_t *vpd; |
| 6133 | uint32_t vpd_size; |
| 6134 | uint32_t ftr_rsp = 0; |
| 6135 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6136 | struct lpfc_vport *vport = phba->pport; |
| 6137 | struct lpfc_dmabuf *mp; |
| 6138 | |
| 6139 | /* Perform a PCI function reset to start from clean */ |
| 6140 | rc = lpfc_pci_function_reset(phba); |
| 6141 | if (unlikely(rc)) |
| 6142 | return -ENODEV; |
| 6143 | |
| 6144 | /* Check the HBA Host Status Register for readyness */ |
| 6145 | rc = lpfc_sli4_post_status_check(phba); |
| 6146 | if (unlikely(rc)) |
| 6147 | return -ENODEV; |
| 6148 | else { |
| 6149 | spin_lock_irq(&phba->hbalock); |
| 6150 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6151 | spin_unlock_irq(&phba->hbalock); |
| 6152 | } |
| 6153 | |
| 6154 | /* |
| 6155 | * Allocate a single mailbox container for initializing the |
| 6156 | * port. |
| 6157 | */ |
| 6158 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6159 | if (!mboxq) |
| 6160 | return -ENOMEM; |
| 6161 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6162 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6163 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6164 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6165 | if (!vpd) { |
| 6166 | rc = -ENOMEM; |
| 6167 | goto out_free_mbox; |
| 6168 | } |
| 6169 | |
| 6170 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6171 | if (unlikely(rc)) { |
| 6172 | kfree(vpd); |
| 6173 | goto out_free_mbox; |
| 6174 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6175 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6176 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
| 6177 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6178 | phba->hba_flag |= HBA_FCOE_MODE; |
| 6179 | else |
| 6180 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6181 | |
| 6182 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6183 | LPFC_DCBX_CEE_MODE) |
| 6184 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6185 | else |
| 6186 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6187 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6188 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6189 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6190 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6191 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6192 | "0376 READ_REV Error. SLI Level %d " |
| 6193 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6194 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6195 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6196 | kfree(vpd); |
| 6197 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6198 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6199 | |
| 6200 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6201 | * Continue initialization with default values even if driver failed |
| 6202 | * to read FCoE param config regions, only read parameters if the |
| 6203 | * board is FCoE |
| 6204 | */ |
| 6205 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6206 | lpfc_sli4_read_fcoe_params(phba)) |
| 6207 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6208 | "2570 Failed to read FCoE parameters\n"); |
| 6209 | |
| 6210 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6211 | * Retrieve sli4 device physical port name, failure of doing it |
| 6212 | * is considered as non-fatal. |
| 6213 | */ |
| 6214 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6215 | if (!rc) |
| 6216 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6217 | "3080 Successful retrieving SLI4 device " |
| 6218 | "physical port name: %s.\n", phba->Port); |
| 6219 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6220 | /* |
| 6221 | * Evaluate the read rev and vpd data. Populate the driver |
| 6222 | * state with the results. If this routine fails, the failure |
| 6223 | * is not fatal as the driver will use generic values. |
| 6224 | */ |
| 6225 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6226 | if (unlikely(!rc)) { |
| 6227 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6228 | "0377 Error %d parsing vpd. " |
| 6229 | "Using defaults.\n", rc); |
| 6230 | rc = 0; |
| 6231 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6232 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6233 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6234 | /* Save information as VPD data */ |
| 6235 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6236 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6237 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6238 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6239 | &mqe->un.read_rev); |
| 6240 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6241 | &mqe->un.read_rev); |
| 6242 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6243 | &mqe->un.read_rev); |
| 6244 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6245 | &mqe->un.read_rev); |
| 6246 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6247 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6248 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6249 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6250 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6251 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6252 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6253 | "(%d):0380 READ_REV Status x%x " |
| 6254 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6255 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6256 | bf_get(lpfc_mqe_status, mqe), |
| 6257 | phba->vpd.rev.opFwName, |
| 6258 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6259 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6260 | |
| 6261 | /* |
| 6262 | * Discover the port's supported feature set and match it against the |
| 6263 | * hosts requests. |
| 6264 | */ |
| 6265 | lpfc_request_features(phba, mboxq); |
| 6266 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6267 | if (unlikely(rc)) { |
| 6268 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6269 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | /* |
| 6273 | * The port must support FCP initiator mode as this is the |
| 6274 | * only mode running in the host. |
| 6275 | */ |
| 6276 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6277 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6278 | "0378 No support for fcpi mode.\n"); |
| 6279 | ftr_rsp++; |
| 6280 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6281 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6282 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6283 | else |
| 6284 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6285 | /* |
| 6286 | * If the port cannot support the host's requested features |
| 6287 | * then turn off the global config parameters to disable the |
| 6288 | * feature in the driver. This is not a fatal error. |
| 6289 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6290 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6291 | if (phba->cfg_enable_bg) { |
| 6292 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6293 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6294 | else |
| 6295 | ftr_rsp++; |
| 6296 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6297 | |
| 6298 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6299 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6300 | ftr_rsp++; |
| 6301 | |
| 6302 | if (ftr_rsp) { |
| 6303 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6304 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6305 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6306 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6307 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6308 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6309 | phba->cfg_enable_bg = 0; |
| 6310 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6311 | phba->cfg_enable_npiv = 0; |
| 6312 | } |
| 6313 | |
| 6314 | /* These SLI3 features are assumed in SLI4 */ |
| 6315 | spin_lock_irq(&phba->hbalock); |
| 6316 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6317 | spin_unlock_irq(&phba->hbalock); |
| 6318 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6319 | /* |
| 6320 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6321 | * calls depends on these resources to complete port setup. |
| 6322 | */ |
| 6323 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6324 | if (rc) { |
| 6325 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6326 | "2920 Failed to alloc Resource IDs " |
| 6327 | "rc = x%x\n", rc); |
| 6328 | goto out_free_mbox; |
| 6329 | } |
| 6330 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6331 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6332 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6333 | if (rc) { |
| 6334 | phba->link_state = LPFC_HBA_ERROR; |
| 6335 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6336 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6337 | } |
| 6338 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6339 | mboxq->vport = vport; |
| 6340 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6341 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6342 | if (rc == MBX_SUCCESS) { |
| 6343 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6344 | rc = 0; |
| 6345 | } |
| 6346 | |
| 6347 | /* |
| 6348 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6349 | * it to the mbuf pool. |
| 6350 | */ |
| 6351 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6352 | kfree(mp); |
| 6353 | mboxq->context1 = NULL; |
| 6354 | if (unlikely(rc)) { |
| 6355 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6356 | "0382 READ_SPARAM command failed " |
| 6357 | "status %d, mbxStatus x%x\n", |
| 6358 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6359 | phba->link_state = LPFC_HBA_ERROR; |
| 6360 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6361 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6362 | } |
| 6363 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6364 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6365 | |
| 6366 | /* Update the fc_host data structures with new wwn. */ |
| 6367 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6368 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6369 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6370 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6371 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6372 | if (unlikely(rc)) { |
| 6373 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6374 | "1400 Failed to update xri-sgl size and " |
| 6375 | "mapping: %d\n", rc); |
| 6376 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6377 | } |
| 6378 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6379 | /* register the els sgl pool to the port */ |
| 6380 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6381 | if (unlikely(rc)) { |
| 6382 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6383 | "0582 Error %d during els sgl post " |
| 6384 | "operation\n", rc); |
| 6385 | rc = -ENODEV; |
| 6386 | goto out_free_mbox; |
| 6387 | } |
| 6388 | |
| 6389 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6390 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6391 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6392 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6393 | "0383 Error %d during scsi sgl post " |
| 6394 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6395 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6396 | /* A pci function reset will repost them */ |
| 6397 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6398 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | /* Post the rpi header region to the device. */ |
| 6402 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6403 | if (unlikely(rc)) { |
| 6404 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6405 | "0393 Error %d during rpi post operation\n", |
| 6406 | rc); |
| 6407 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6408 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6409 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6410 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6411 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6412 | /* Create all the SLI4 queues */ |
| 6413 | rc = lpfc_sli4_queue_create(phba); |
| 6414 | if (rc) { |
| 6415 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6416 | "3089 Failed to allocate queues\n"); |
| 6417 | rc = -ENODEV; |
| 6418 | goto out_stop_timers; |
| 6419 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6420 | /* Set up all the queues to the device */ |
| 6421 | rc = lpfc_sli4_queue_setup(phba); |
| 6422 | if (unlikely(rc)) { |
| 6423 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6424 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6425 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6426 | } |
| 6427 | |
| 6428 | /* Arm the CQs and then EQs on device */ |
| 6429 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6430 | |
| 6431 | /* Indicate device interrupt mode */ |
| 6432 | phba->sli4_hba.intr_enable = 1; |
| 6433 | |
| 6434 | /* Allow asynchronous mailbox command to go through */ |
| 6435 | spin_lock_irq(&phba->hbalock); |
| 6436 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6437 | spin_unlock_irq(&phba->hbalock); |
| 6438 | |
| 6439 | /* Post receive buffers to the device */ |
| 6440 | lpfc_sli4_rb_setup(phba); |
| 6441 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6442 | /* Reset HBA FCF states after HBA reset */ |
| 6443 | phba->fcf.fcf_flag = 0; |
| 6444 | phba->fcf.current_rec.flag = 0; |
| 6445 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6446 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6447 | mod_timer(&vport->els_tmofunc, |
| 6448 | jiffies + HZ * (phba->fc_ratov * 2)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6449 | |
| 6450 | /* Start heart beat timer */ |
| 6451 | mod_timer(&phba->hb_tmofunc, |
| 6452 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 6453 | phba->hb_outstanding = 0; |
| 6454 | phba->last_completion_time = jiffies; |
| 6455 | |
| 6456 | /* Start error attention (ERATT) polling timer */ |
| 6457 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| 6458 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6459 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6460 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6461 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6462 | if (!rc) { |
| 6463 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6464 | "2829 This device supports " |
| 6465 | "Advanced Error Reporting (AER)\n"); |
| 6466 | spin_lock_irq(&phba->hbalock); |
| 6467 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6468 | spin_unlock_irq(&phba->hbalock); |
| 6469 | } else { |
| 6470 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6471 | "2830 This device does not support " |
| 6472 | "Advanced Error Reporting (AER)\n"); |
| 6473 | phba->cfg_aer_support = 0; |
| 6474 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6475 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6476 | } |
| 6477 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6478 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6479 | /* |
| 6480 | * The FC Port needs to register FCFI (index 0) |
| 6481 | */ |
| 6482 | lpfc_reg_fcfi(phba, mboxq); |
| 6483 | mboxq->vport = phba->pport; |
| 6484 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6485 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6486 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6487 | rc = 0; |
| 6488 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6489 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6490 | |
| 6491 | /* Check if the port is configured to be disabled */ |
| 6492 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6493 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6494 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6495 | /* |
| 6496 | * The port is ready, set the host's link state to LINK_DOWN |
| 6497 | * in preparation for link interrupts. |
| 6498 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6499 | spin_lock_irq(&phba->hbalock); |
| 6500 | phba->link_state = LPFC_LINK_DOWN; |
| 6501 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6502 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6503 | (phba->hba_flag & LINK_DISABLED)) { |
| 6504 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6505 | "3103 Adapter Link is disabled.\n"); |
| 6506 | lpfc_down_link(phba, mboxq); |
| 6507 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6508 | if (rc != MBX_SUCCESS) { |
| 6509 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6510 | "3104 Adapter failed to issue " |
| 6511 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6512 | goto out_unset_queue; |
| 6513 | } |
| 6514 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6515 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6516 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6517 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6518 | if (rc) |
| 6519 | goto out_unset_queue; |
| 6520 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6521 | } |
| 6522 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6523 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6524 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6525 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6526 | lpfc_sli4_queue_unset(phba); |
| 6527 | out_destroy_queue: |
| 6528 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6529 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6530 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6531 | out_free_mbox: |
| 6532 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6533 | return rc; |
| 6534 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6535 | |
| 6536 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6537 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6538 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6539 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6540 | * This is the callback function for mailbox timer. The mailbox |
| 6541 | * timer is armed when a new mailbox command is issued and the timer |
| 6542 | * is deleted when the mailbox complete. The function is called by |
| 6543 | * the kernel timer code when a mailbox does not complete within |
| 6544 | * expected time. This function wakes up the worker thread to |
| 6545 | * process the mailbox timeout and returns. All the processing is |
| 6546 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6547 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6548 | void |
| 6549 | lpfc_mbox_timeout(unsigned long ptr) |
| 6550 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6551 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6552 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6553 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6554 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6555 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6556 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6557 | if (!tmo_posted) |
| 6558 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6559 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6560 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6561 | if (!tmo_posted) |
| 6562 | lpfc_worker_wake_up(phba); |
| 6563 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6564 | } |
| 6565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6566 | |
| 6567 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6568 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6569 | * @phba: Pointer to HBA context object. |
| 6570 | * |
| 6571 | * This function is called from worker thread when a mailbox command times out. |
| 6572 | * The caller is not required to hold any locks. This function will reset the |
| 6573 | * HBA and recover all the pending commands. |
| 6574 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6575 | void |
| 6576 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6577 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6578 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6579 | MAILBOX_t *mb = &pmbox->u.mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6580 | struct lpfc_sli *psli = &phba->sli; |
| 6581 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6582 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6583 | /* Check the pmbox pointer first. There is a race condition |
| 6584 | * between the mbox timeout handler getting executed in the |
| 6585 | * worklist and the mailbox actually completing. When this |
| 6586 | * race condition occurs, the mbox_active will be NULL. |
| 6587 | */ |
| 6588 | spin_lock_irq(&phba->hbalock); |
| 6589 | if (pmbox == NULL) { |
| 6590 | lpfc_printf_log(phba, KERN_WARNING, |
| 6591 | LOG_MBOX | LOG_SLI, |
| 6592 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6593 | "exiting\n"); |
| 6594 | spin_unlock_irq(&phba->hbalock); |
| 6595 | return; |
| 6596 | } |
| 6597 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6598 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6599 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6600 | "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] | 6601 | mb->mbxCommand, |
| 6602 | phba->pport->port_state, |
| 6603 | phba->sli.sli_flag, |
| 6604 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6605 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6606 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6607 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6608 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6609 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6610 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6611 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6612 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6613 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6614 | spin_lock_irq(&phba->hbalock); |
| 6615 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6616 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6617 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6618 | |
| 6619 | pring = &psli->ring[psli->fcp_ring]; |
| 6620 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 6621 | |
| 6622 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6623 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6624 | |
| 6625 | /* Reset the HBA device */ |
| 6626 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6627 | } |
| 6628 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6629 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6630 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6631 | * @phba: Pointer to HBA context object. |
| 6632 | * @pmbox: Pointer to mailbox object. |
| 6633 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6634 | * |
| 6635 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6636 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6637 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6638 | * The mailbox command can be submitted in polling mode, in which case |
| 6639 | * this function will wait in a polling loop for the completion of the |
| 6640 | * mailbox. |
| 6641 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6642 | * function will submit the command and returns immediately without waiting |
| 6643 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6644 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6645 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6646 | * mailbox is issued in polling mode and there is already a mailbox |
| 6647 | * pending, then the function will return an error. If the mailbox is issued |
| 6648 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6649 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6650 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6651 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6652 | * return codes the caller owns the mailbox command after the return of |
| 6653 | * the function. |
| 6654 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6655 | static int |
| 6656 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6657 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6658 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6659 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6660 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6661 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6662 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6663 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6664 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6665 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6666 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6667 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6668 | int processing_queue = 0; |
| 6669 | |
| 6670 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6671 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6672 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6673 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6674 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6675 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6676 | return MBX_SUCCESS; |
| 6677 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6678 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6679 | pmbox = lpfc_mbox_get(phba); |
| 6680 | if (!pmbox) { |
| 6681 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6682 | return MBX_SUCCESS; |
| 6683 | } |
| 6684 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6685 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6686 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6687 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6688 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6689 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6690 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6691 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6692 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6693 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6694 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6695 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6696 | } |
| 6697 | } |
| 6698 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6699 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6700 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6701 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6702 | goto out_not_finished; |
| 6703 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6704 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6705 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6706 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6707 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6708 | goto out_not_finished; |
| 6709 | } |
| 6710 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6711 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6712 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6713 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6714 | status = MBX_SUCCESS; |
| 6715 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6716 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6717 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6718 | |
| 6719 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6720 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6721 | "(%d):0311 Mailbox command x%x cannot " |
| 6722 | "issue Data: x%x x%x\n", |
| 6723 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6724 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6725 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6726 | } |
| 6727 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6728 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6729 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6730 | !(hc_copy & HC_MBINT_ENA)) { |
| 6731 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6732 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6733 | "(%d):2528 Mailbox command x%x cannot " |
| 6734 | "issue Data: x%x x%x\n", |
| 6735 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6736 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6737 | goto out_not_finished; |
| 6738 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6739 | } |
| 6740 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6741 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6742 | /* Polling for a mbox command when another one is already active |
| 6743 | * is not allowed in SLI. Also, the driver must have established |
| 6744 | * SLI2 mode to queue and process multiple mbox commands. |
| 6745 | */ |
| 6746 | |
| 6747 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6748 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6749 | |
| 6750 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6751 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6752 | "(%d):2529 Mailbox command x%x " |
| 6753 | "cannot issue Data: x%x x%x\n", |
| 6754 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6755 | pmbox->u.mb.mbxCommand, |
| 6756 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6757 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6758 | } |
| 6759 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6760 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6761 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6762 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6763 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6764 | "(%d):2530 Mailbox command x%x " |
| 6765 | "cannot issue Data: x%x x%x\n", |
| 6766 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6767 | pmbox->u.mb.mbxCommand, |
| 6768 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6769 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6770 | } |
| 6771 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6772 | /* Another mailbox command is still being processed, queue this |
| 6773 | * command to be processed later. |
| 6774 | */ |
| 6775 | lpfc_mbox_put(phba, pmbox); |
| 6776 | |
| 6777 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6778 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6779 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6780 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6781 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6782 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6783 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6784 | |
| 6785 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6786 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6787 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6788 | if (pmbox->vport) { |
| 6789 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6790 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6791 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6792 | (uint32_t)mbx->mbxCommand, |
| 6793 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6794 | } |
| 6795 | else { |
| 6796 | lpfc_debugfs_disc_trc(phba->pport, |
| 6797 | LPFC_DISC_TRC_MBOX, |
| 6798 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6799 | (uint32_t)mbx->mbxCommand, |
| 6800 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6801 | } |
| 6802 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6803 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6804 | } |
| 6805 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6806 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6807 | |
| 6808 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 6809 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6810 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6811 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6812 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6813 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6814 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6815 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6816 | "(%d):2531 Mailbox command x%x " |
| 6817 | "cannot issue Data: x%x x%x\n", |
| 6818 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6819 | pmbox->u.mb.mbxCommand, |
| 6820 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6821 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6822 | } |
| 6823 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 6824 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6825 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6826 | } |
| 6827 | |
| 6828 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6829 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6830 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6831 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6832 | pmbox->vport ? pmbox->vport->vpi : 0, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6833 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6834 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6835 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6836 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6837 | if (pmbox->vport) { |
| 6838 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6839 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6840 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6841 | (uint32_t)mbx->mbxCommand, |
| 6842 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6843 | } |
| 6844 | else { |
| 6845 | lpfc_debugfs_disc_trc(phba->pport, |
| 6846 | LPFC_DISC_TRC_MBOX, |
| 6847 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6848 | (uint32_t)mbx->mbxCommand, |
| 6849 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6850 | } |
| 6851 | } |
| 6852 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6853 | psli->slistat.mbox_cmd++; |
| 6854 | evtctr = psli->slistat.mbox_event; |
| 6855 | |
| 6856 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6857 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6858 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6859 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6860 | /* Populate mbox extension offset word. */ |
| 6861 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6862 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6863 | = (uint8_t *)phba->mbox_ext |
| 6864 | - (uint8_t *)phba->mbox; |
| 6865 | } |
| 6866 | |
| 6867 | /* Copy the mailbox extension data */ |
| 6868 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6869 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 6870 | (uint8_t *)phba->mbox_ext, |
| 6871 | pmbox->in_ext_byte_len); |
| 6872 | } |
| 6873 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6874 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6875 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6876 | /* Populate mbox extension offset word. */ |
| 6877 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6878 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6879 | = MAILBOX_HBA_EXT_OFFSET; |
| 6880 | |
| 6881 | /* Copy the mailbox extension data */ |
| 6882 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6883 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 6884 | MAILBOX_HBA_EXT_OFFSET, |
| 6885 | pmbox->context2, pmbox->in_ext_byte_len); |
| 6886 | |
| 6887 | } |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6888 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6889 | /* copy command data into host mbox for cmpl */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6890 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | /* First copy mbox command data to HBA SLIM, skip past first |
| 6894 | word */ |
| 6895 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6896 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6897 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 6898 | |
| 6899 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6900 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6901 | to_slim = phba->MBslimaddr; |
| 6902 | writel(ldata, to_slim); |
| 6903 | readl(to_slim); /* flush */ |
| 6904 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6905 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6906 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6907 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6912 | |
| 6913 | switch (flag) { |
| 6914 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6915 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6916 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6917 | /* Interrupt board to do it */ |
| 6918 | writel(CA_MBATT, phba->CAregaddr); |
| 6919 | readl(phba->CAregaddr); /* flush */ |
| 6920 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6921 | break; |
| 6922 | |
| 6923 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6924 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6925 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6926 | /* Interrupt board to do it */ |
| 6927 | writel(CA_MBATT, phba->CAregaddr); |
| 6928 | readl(phba->CAregaddr); /* flush */ |
| 6929 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6930 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6931 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6932 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6933 | word0 = le32_to_cpu(word0); |
| 6934 | } else { |
| 6935 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6936 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 6937 | spin_unlock_irqrestore(&phba->hbalock, |
| 6938 | drvr_flag); |
| 6939 | goto out_not_finished; |
| 6940 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6941 | } |
| 6942 | |
| 6943 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6944 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6945 | spin_unlock_irqrestore(&phba->hbalock, |
| 6946 | drvr_flag); |
| 6947 | goto out_not_finished; |
| 6948 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6949 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 6950 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6951 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6952 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6953 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 6954 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6955 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6956 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6957 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6958 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6959 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6960 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6961 | } |
| 6962 | |
| 6963 | /* Check if we took a mbox interrupt while we were |
| 6964 | polling */ |
| 6965 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 6966 | && (evtctr != psli->slistat.mbox_event)) |
| 6967 | break; |
| 6968 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6969 | if (i++ > 10) { |
| 6970 | spin_unlock_irqrestore(&phba->hbalock, |
| 6971 | drvr_flag); |
| 6972 | msleep(1); |
| 6973 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6974 | } |
| 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) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6977 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6978 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6979 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6980 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6981 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6982 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6983 | /* Check real SLIM for any errors */ |
| 6984 | slimword0 = readl(phba->MBslimaddr); |
| 6985 | slimmb = (MAILBOX_t *) & slimword0; |
| 6986 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 6987 | && slimmb->mbxStatus) { |
| 6988 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6989 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6990 | word0 = slimword0; |
| 6991 | } |
| 6992 | } |
| 6993 | } else { |
| 6994 | /* First copy command data */ |
| 6995 | word0 = readl(phba->MBslimaddr); |
| 6996 | } |
| 6997 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6998 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6999 | spin_unlock_irqrestore(&phba->hbalock, |
| 7000 | drvr_flag); |
| 7001 | goto out_not_finished; |
| 7002 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7003 | } |
| 7004 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7005 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7006 | /* copy results back to user */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7007 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7008 | /* Copy the mailbox extension data */ |
| 7009 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7010 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7011 | pmbox->context2, |
| 7012 | pmbox->out_ext_byte_len); |
| 7013 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7014 | } else { |
| 7015 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7016 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7017 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7018 | /* Copy the mailbox extension data */ |
| 7019 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7020 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7021 | phba->MBslimaddr + |
| 7022 | MAILBOX_HBA_EXT_OFFSET, |
| 7023 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7024 | } |
| 7025 | } |
| 7026 | |
| 7027 | writel(HA_MBATT, phba->HAregaddr); |
| 7028 | readl(phba->HAregaddr); /* flush */ |
| 7029 | |
| 7030 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7031 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7032 | } |
| 7033 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7034 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7035 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7036 | |
| 7037 | out_not_finished: |
| 7038 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7039 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7040 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7041 | } |
| 7042 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7043 | } |
| 7044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7045 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7046 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7047 | * @phba: Pointer to HBA context object. |
| 7048 | * |
| 7049 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7050 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7051 | * possible outstanding mailbox command before return. |
| 7052 | * |
| 7053 | * Returns: |
| 7054 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7055 | * the outstanding mailbox command timed out. |
| 7056 | **/ |
| 7057 | static int |
| 7058 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7059 | { |
| 7060 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7061 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7062 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7063 | |
| 7064 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7065 | spin_lock_irq(&phba->hbalock); |
| 7066 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7067 | /* Determine how long we might wait for the active mailbox |
| 7068 | * command to be gracefully completed by firmware. |
| 7069 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7070 | if (phba->sli.mbox_active) |
| 7071 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7072 | phba->sli.mbox_active) * |
| 7073 | 1000) + jiffies; |
| 7074 | spin_unlock_irq(&phba->hbalock); |
| 7075 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7076 | /* Wait for the outstnading mailbox command to complete */ |
| 7077 | while (phba->sli.mbox_active) { |
| 7078 | /* Check active mailbox complete status every 2ms */ |
| 7079 | msleep(2); |
| 7080 | if (time_after(jiffies, timeout)) { |
| 7081 | /* Timeout, marked the outstanding cmd not complete */ |
| 7082 | rc = 1; |
| 7083 | break; |
| 7084 | } |
| 7085 | } |
| 7086 | |
| 7087 | /* Can not cleanly block async mailbox command, fails it */ |
| 7088 | if (rc) { |
| 7089 | spin_lock_irq(&phba->hbalock); |
| 7090 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7091 | spin_unlock_irq(&phba->hbalock); |
| 7092 | } |
| 7093 | return rc; |
| 7094 | } |
| 7095 | |
| 7096 | /** |
| 7097 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7098 | * @phba: Pointer to HBA context object. |
| 7099 | * |
| 7100 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7101 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7102 | * that there is no outstanding mailbox command before resuming posting |
| 7103 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7104 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7105 | * mailbox command posting. |
| 7106 | **/ |
| 7107 | static void |
| 7108 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7109 | { |
| 7110 | struct lpfc_sli *psli = &phba->sli; |
| 7111 | |
| 7112 | spin_lock_irq(&phba->hbalock); |
| 7113 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7114 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7115 | spin_unlock_irq(&phba->hbalock); |
| 7116 | return; |
| 7117 | } |
| 7118 | |
| 7119 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7120 | * successful or timeout, after timing-out the outstanding mailbox |
| 7121 | * command shall always be removed, so just unblock posting async |
| 7122 | * mailbox command and resume |
| 7123 | */ |
| 7124 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7125 | spin_unlock_irq(&phba->hbalock); |
| 7126 | |
| 7127 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7128 | lpfc_worker_wake_up(phba); |
| 7129 | } |
| 7130 | |
| 7131 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7132 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7133 | * @phba: Pointer to HBA context object. |
| 7134 | * @mboxq: Pointer to mailbox object. |
| 7135 | * |
| 7136 | * The function waits for the bootstrap mailbox register ready bit from |
| 7137 | * port for twice the regular mailbox command timeout value. |
| 7138 | * |
| 7139 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7140 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7141 | **/ |
| 7142 | static int |
| 7143 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7144 | { |
| 7145 | uint32_t db_ready; |
| 7146 | unsigned long timeout; |
| 7147 | struct lpfc_register bmbx_reg; |
| 7148 | |
| 7149 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7150 | * 1000) + jiffies; |
| 7151 | |
| 7152 | do { |
| 7153 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7154 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7155 | if (!db_ready) |
| 7156 | msleep(2); |
| 7157 | |
| 7158 | if (time_after(jiffies, timeout)) |
| 7159 | return MBXERR_ERROR; |
| 7160 | } while (!db_ready); |
| 7161 | |
| 7162 | return 0; |
| 7163 | } |
| 7164 | |
| 7165 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7166 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7167 | * @phba: Pointer to HBA context object. |
| 7168 | * @mboxq: Pointer to mailbox object. |
| 7169 | * |
| 7170 | * The function posts a mailbox to the port. The mailbox is expected |
| 7171 | * to be comletely filled in and ready for the port to operate on it. |
| 7172 | * This routine executes a synchronous completion operation on the |
| 7173 | * mailbox by polling for its completion. |
| 7174 | * |
| 7175 | * The caller must not be holding any locks when calling this routine. |
| 7176 | * |
| 7177 | * Returns: |
| 7178 | * MBX_SUCCESS - mailbox posted successfully |
| 7179 | * Any of the MBX error values. |
| 7180 | **/ |
| 7181 | static int |
| 7182 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7183 | { |
| 7184 | int rc = MBX_SUCCESS; |
| 7185 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7186 | uint32_t mcqe_status; |
| 7187 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7188 | struct lpfc_sli *psli = &phba->sli; |
| 7189 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7190 | struct lpfc_bmbx_create *mbox_rgn; |
| 7191 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7192 | |
| 7193 | /* |
| 7194 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7195 | * at a time and there is no queueing provided. |
| 7196 | */ |
| 7197 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7198 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7199 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7200 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7201 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7202 | "cannot issue Data: x%x x%x\n", |
| 7203 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7204 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7205 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7206 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7207 | psli->sli_flag, MBX_POLL); |
| 7208 | return MBXERR_ERROR; |
| 7209 | } |
| 7210 | /* The server grabs the token and owns it until release */ |
| 7211 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7212 | phba->sli.mbox_active = mboxq; |
| 7213 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7214 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7215 | /* wait for bootstrap mbox register for readyness */ |
| 7216 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7217 | if (rc) |
| 7218 | goto exit; |
| 7219 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7220 | /* |
| 7221 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7222 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7223 | * the bmbx mailbox region. |
| 7224 | */ |
| 7225 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7226 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7227 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7228 | sizeof(struct lpfc_mqe)); |
| 7229 | |
| 7230 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7231 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7232 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7233 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7234 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7235 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7236 | if (rc) |
| 7237 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7238 | |
| 7239 | /* Post the low mailbox dma address to the port. */ |
| 7240 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7241 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7242 | /* wait for bootstrap mbox register for low address write done */ |
| 7243 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7244 | if (rc) |
| 7245 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7246 | |
| 7247 | /* |
| 7248 | * Read the CQ to ensure the mailbox has completed. |
| 7249 | * If so, update the mailbox status so that the upper layers |
| 7250 | * can complete the request normally. |
| 7251 | */ |
| 7252 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7253 | sizeof(struct lpfc_mqe)); |
| 7254 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7255 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7256 | sizeof(struct lpfc_mcqe)); |
| 7257 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7258 | /* |
| 7259 | * When the CQE status indicates a failure and the mailbox status |
| 7260 | * indicates success then copy the CQE status into the mailbox status |
| 7261 | * (and prefix it with x4000). |
| 7262 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7263 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7264 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7265 | bf_set(lpfc_mqe_status, mb, |
| 7266 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7267 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7268 | } else |
| 7269 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7270 | |
| 7271 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7272 | "(%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] | 7273 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7274 | " 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] | 7275 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7276 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7277 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7278 | bf_get(lpfc_mqe_status, mb), |
| 7279 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7280 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7281 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7282 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7283 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7284 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7285 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7286 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7287 | mboxq->mcqe.trailer); |
| 7288 | exit: |
| 7289 | /* We are holding the token, no needed for lock when release */ |
| 7290 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7291 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7292 | phba->sli.mbox_active = NULL; |
| 7293 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7294 | return rc; |
| 7295 | } |
| 7296 | |
| 7297 | /** |
| 7298 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7299 | * @phba: Pointer to HBA context object. |
| 7300 | * @pmbox: Pointer to mailbox object. |
| 7301 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7302 | * |
| 7303 | * This function is called by discovery code and HBA management code to submit |
| 7304 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7305 | * |
| 7306 | * Return codes the caller owns the mailbox command after the return of the |
| 7307 | * function. |
| 7308 | **/ |
| 7309 | static int |
| 7310 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7311 | uint32_t flag) |
| 7312 | { |
| 7313 | struct lpfc_sli *psli = &phba->sli; |
| 7314 | unsigned long iflags; |
| 7315 | int rc; |
| 7316 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7317 | /* dump from issue mailbox command if setup */ |
| 7318 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7319 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7320 | rc = lpfc_mbox_dev_check(phba); |
| 7321 | if (unlikely(rc)) { |
| 7322 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7323 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7324 | "cannot issue Data: x%x x%x\n", |
| 7325 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7326 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7327 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7328 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7329 | psli->sli_flag, flag); |
| 7330 | goto out_not_finished; |
| 7331 | } |
| 7332 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7333 | /* Detect polling mode and jump to a handler */ |
| 7334 | if (!phba->sli4_hba.intr_enable) { |
| 7335 | if (flag == MBX_POLL) |
| 7336 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7337 | else |
| 7338 | rc = -EIO; |
| 7339 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7340 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7341 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7342 | "(x%x/x%x) failure: " |
| 7343 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7344 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7345 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7346 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7347 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7348 | mboxq), |
| 7349 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7350 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7351 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7352 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7353 | bf_get(lpfc_mcqe_ext_status, |
| 7354 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7355 | psli->sli_flag, flag); |
| 7356 | return rc; |
| 7357 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7358 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7359 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7360 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7361 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7362 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7363 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7364 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7365 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7366 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7367 | /* Try to block the asynchronous mailbox posting */ |
| 7368 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7369 | if (!rc) { |
| 7370 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7371 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7372 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7373 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7374 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7375 | "(%d):2597 Sync Mailbox command " |
| 7376 | "x%x (x%x/x%x) failure: " |
| 7377 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7378 | "Data: x%x x%x\n,", |
| 7379 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7380 | mboxq->u.mb.mbxCommand, |
| 7381 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7382 | mboxq), |
| 7383 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7384 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7385 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7386 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7387 | bf_get(lpfc_mcqe_ext_status, |
| 7388 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7389 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7390 | /* Unblock the async mailbox posting afterward */ |
| 7391 | lpfc_sli4_async_mbox_unblock(phba); |
| 7392 | } |
| 7393 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7394 | } |
| 7395 | |
| 7396 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7397 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7398 | if (rc) { |
| 7399 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7400 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7401 | "cannot issue Data: x%x x%x\n", |
| 7402 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7403 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7404 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7405 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7406 | psli->sli_flag, flag); |
| 7407 | goto out_not_finished; |
| 7408 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7409 | |
| 7410 | /* Put the mailbox command to the driver internal FIFO */ |
| 7411 | psli->slistat.mbox_busy++; |
| 7412 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7413 | lpfc_mbox_put(phba, mboxq); |
| 7414 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7415 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7416 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7417 | "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] | 7418 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7419 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7420 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7421 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7422 | phba->pport->port_state, |
| 7423 | psli->sli_flag, MBX_NOWAIT); |
| 7424 | /* Wake up worker thread to transport mailbox command from head */ |
| 7425 | lpfc_worker_wake_up(phba); |
| 7426 | |
| 7427 | return MBX_BUSY; |
| 7428 | |
| 7429 | out_not_finished: |
| 7430 | return MBX_NOT_FINISHED; |
| 7431 | } |
| 7432 | |
| 7433 | /** |
| 7434 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7435 | * @phba: Pointer to HBA context object. |
| 7436 | * |
| 7437 | * This function is called by worker thread to send a mailbox command to |
| 7438 | * SLI4 HBA firmware. |
| 7439 | * |
| 7440 | **/ |
| 7441 | int |
| 7442 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7443 | { |
| 7444 | struct lpfc_sli *psli = &phba->sli; |
| 7445 | LPFC_MBOXQ_t *mboxq; |
| 7446 | int rc = MBX_SUCCESS; |
| 7447 | unsigned long iflags; |
| 7448 | struct lpfc_mqe *mqe; |
| 7449 | uint32_t mbx_cmnd; |
| 7450 | |
| 7451 | /* Check interrupt mode before post async mailbox command */ |
| 7452 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7453 | return MBX_NOT_FINISHED; |
| 7454 | |
| 7455 | /* Check for mailbox command service token */ |
| 7456 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7457 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7458 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7459 | return MBX_NOT_FINISHED; |
| 7460 | } |
| 7461 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7462 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7463 | return MBX_NOT_FINISHED; |
| 7464 | } |
| 7465 | if (unlikely(phba->sli.mbox_active)) { |
| 7466 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7467 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7468 | "0384 There is pending active mailbox cmd\n"); |
| 7469 | return MBX_NOT_FINISHED; |
| 7470 | } |
| 7471 | /* Take the mailbox command service token */ |
| 7472 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7473 | |
| 7474 | /* Get the next mailbox command from head of queue */ |
| 7475 | mboxq = lpfc_mbox_get(phba); |
| 7476 | |
| 7477 | /* If no more mailbox command waiting for post, we're done */ |
| 7478 | if (!mboxq) { |
| 7479 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7480 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7481 | return MBX_SUCCESS; |
| 7482 | } |
| 7483 | phba->sli.mbox_active = mboxq; |
| 7484 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7485 | |
| 7486 | /* Check device readiness for posting mailbox command */ |
| 7487 | rc = lpfc_mbox_dev_check(phba); |
| 7488 | if (unlikely(rc)) |
| 7489 | /* Driver clean routine will clean up pending mailbox */ |
| 7490 | goto out_not_finished; |
| 7491 | |
| 7492 | /* Prepare the mbox command to be posted */ |
| 7493 | mqe = &mboxq->u.mqe; |
| 7494 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7495 | |
| 7496 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7497 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7498 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7499 | |
| 7500 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7501 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7502 | "x%x x%x\n", |
| 7503 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7504 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7505 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7506 | phba->pport->port_state, psli->sli_flag); |
| 7507 | |
| 7508 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7509 | if (mboxq->vport) { |
| 7510 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7511 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7512 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7513 | mbx_cmnd, mqe->un.mb_words[0], |
| 7514 | mqe->un.mb_words[1]); |
| 7515 | } else { |
| 7516 | lpfc_debugfs_disc_trc(phba->pport, |
| 7517 | LPFC_DISC_TRC_MBOX, |
| 7518 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7519 | mbx_cmnd, mqe->un.mb_words[0], |
| 7520 | mqe->un.mb_words[1]); |
| 7521 | } |
| 7522 | } |
| 7523 | psli->slistat.mbox_cmd++; |
| 7524 | |
| 7525 | /* Post the mailbox command to the port */ |
| 7526 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7527 | if (rc != MBX_SUCCESS) { |
| 7528 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7529 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7530 | "cannot issue Data: x%x x%x\n", |
| 7531 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7532 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7533 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7534 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7535 | psli->sli_flag, MBX_NOWAIT); |
| 7536 | goto out_not_finished; |
| 7537 | } |
| 7538 | |
| 7539 | return rc; |
| 7540 | |
| 7541 | out_not_finished: |
| 7542 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7543 | if (phba->sli.mbox_active) { |
| 7544 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7545 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7546 | /* Release the token */ |
| 7547 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7548 | phba->sli.mbox_active = NULL; |
| 7549 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7550 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7551 | |
| 7552 | return MBX_NOT_FINISHED; |
| 7553 | } |
| 7554 | |
| 7555 | /** |
| 7556 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7557 | * @phba: Pointer to HBA context object. |
| 7558 | * @pmbox: Pointer to mailbox object. |
| 7559 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7560 | * |
| 7561 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7562 | * the API jump table function pointer from the lpfc_hba struct. |
| 7563 | * |
| 7564 | * Return codes the caller owns the mailbox command after the return of the |
| 7565 | * function. |
| 7566 | **/ |
| 7567 | int |
| 7568 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7569 | { |
| 7570 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7571 | } |
| 7572 | |
| 7573 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7574 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7575 | * @phba: The hba struct for which this call is being executed. |
| 7576 | * @dev_grp: The HBA PCI-Device group number. |
| 7577 | * |
| 7578 | * This routine sets up the mbox interface API function jump table in @phba |
| 7579 | * struct. |
| 7580 | * Returns: 0 - success, -ENODEV - failure. |
| 7581 | **/ |
| 7582 | int |
| 7583 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7584 | { |
| 7585 | |
| 7586 | switch (dev_grp) { |
| 7587 | case LPFC_PCI_DEV_LP: |
| 7588 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7589 | phba->lpfc_sli_handle_slow_ring_event = |
| 7590 | lpfc_sli_handle_slow_ring_event_s3; |
| 7591 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7592 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7593 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7594 | break; |
| 7595 | case LPFC_PCI_DEV_OC: |
| 7596 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7597 | phba->lpfc_sli_handle_slow_ring_event = |
| 7598 | lpfc_sli_handle_slow_ring_event_s4; |
| 7599 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7600 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7601 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7602 | break; |
| 7603 | default: |
| 7604 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7605 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7606 | dev_grp); |
| 7607 | return -ENODEV; |
| 7608 | break; |
| 7609 | } |
| 7610 | return 0; |
| 7611 | } |
| 7612 | |
| 7613 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7614 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7615 | * @phba: Pointer to HBA context object. |
| 7616 | * @pring: Pointer to driver SLI ring object. |
| 7617 | * @piocb: Pointer to address of newly added command iocb. |
| 7618 | * |
| 7619 | * This function is called with hbalock held to add a command |
| 7620 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7621 | * to the ring. |
| 7622 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7623 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7624 | __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] | 7625 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7626 | { |
| 7627 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7628 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7629 | } |
| 7630 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7631 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7632 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7633 | * @phba: Pointer to HBA context object. |
| 7634 | * @pring: Pointer to driver SLI ring object. |
| 7635 | * @piocb: Pointer to address of newly added command iocb. |
| 7636 | * |
| 7637 | * This function is called with hbalock held before a new |
| 7638 | * iocb is submitted to the firmware. This function checks |
| 7639 | * txq to flush the iocbs in txq to Firmware before |
| 7640 | * submitting new iocbs to the Firmware. |
| 7641 | * If there are iocbs in the txq which need to be submitted |
| 7642 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7643 | * of the txq after dequeuing it from txq. |
| 7644 | * If there is no iocb in the txq then the function will return |
| 7645 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7646 | * *piocb to find if there are more commands in the txq. |
| 7647 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7648 | static struct lpfc_iocbq * |
| 7649 | 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] | 7650 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7651 | { |
| 7652 | struct lpfc_iocbq * nextiocb; |
| 7653 | |
| 7654 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7655 | if (!nextiocb) { |
| 7656 | nextiocb = *piocb; |
| 7657 | *piocb = NULL; |
| 7658 | } |
| 7659 | |
| 7660 | return nextiocb; |
| 7661 | } |
| 7662 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7663 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7664 | * __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] | 7665 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7666 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7667 | * @piocb: Pointer to command iocb. |
| 7668 | * @flag: Flag indicating if this command can be put into txq. |
| 7669 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7670 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7671 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7672 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7673 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7674 | * this function allows only iocbs for posting buffers. This function finds |
| 7675 | * next available slot in the command ring and posts the command to the |
| 7676 | * available slot and writes the port attention register to request HBA start |
| 7677 | * processing new iocb. If there is no slot available in the ring and |
| 7678 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7679 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7680 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7681 | * This function is called with hbalock held. The function will return success |
| 7682 | * after it successfully submit the iocb to firmware or after adding to the |
| 7683 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7684 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7685 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7686 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7687 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7688 | { |
| 7689 | struct lpfc_iocbq *nextiocb; |
| 7690 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7691 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7692 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7693 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7694 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7695 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7696 | lpfc_printf_log(phba, KERN_ERR, |
| 7697 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7698 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7699 | piocb->iocb.ulpCommand); |
| 7700 | dump_stack(); |
| 7701 | return IOCB_ERROR; |
| 7702 | } |
| 7703 | |
| 7704 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7705 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7706 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7707 | return IOCB_ERROR; |
| 7708 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7709 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7710 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7711 | return IOCB_ERROR; |
| 7712 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7713 | /* |
| 7714 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7715 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7716 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7717 | return IOCB_ERROR; |
| 7718 | |
| 7719 | /* |
| 7720 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7721 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7722 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7723 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7724 | goto iocb_busy; |
| 7725 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7726 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7727 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7728 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7729 | * can be issued if the link is not up. |
| 7730 | */ |
| 7731 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7732 | case CMD_GEN_REQUEST64_CR: |
| 7733 | case CMD_GEN_REQUEST64_CX: |
| 7734 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 7735 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7736 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7737 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 7738 | MENLO_TRANSPORT_TYPE)) |
| 7739 | |
| 7740 | goto iocb_busy; |
| 7741 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7742 | case CMD_QUE_RING_BUF_CN: |
| 7743 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7744 | /* |
| 7745 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 7746 | * completion, iocb_cmpl MUST be 0. |
| 7747 | */ |
| 7748 | if (piocb->iocb_cmpl) |
| 7749 | piocb->iocb_cmpl = NULL; |
| 7750 | /*FALLTHROUGH*/ |
| 7751 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7752 | case CMD_CLOSE_XRI_CN: |
| 7753 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7754 | break; |
| 7755 | default: |
| 7756 | goto iocb_busy; |
| 7757 | } |
| 7758 | |
| 7759 | /* |
| 7760 | * For FCP commands, we must be in a state where we can process link |
| 7761 | * attention events. |
| 7762 | */ |
| 7763 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7764 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7765 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7766 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7767 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7768 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 7769 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 7770 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 7771 | |
| 7772 | if (iocb) |
| 7773 | lpfc_sli_update_ring(phba, pring); |
| 7774 | else |
| 7775 | lpfc_sli_update_full_ring(phba, pring); |
| 7776 | |
| 7777 | if (!piocb) |
| 7778 | return IOCB_SUCCESS; |
| 7779 | |
| 7780 | goto out_busy; |
| 7781 | |
| 7782 | iocb_busy: |
| 7783 | pring->stats.iocb_cmd_delay++; |
| 7784 | |
| 7785 | out_busy: |
| 7786 | |
| 7787 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7788 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7789 | return IOCB_SUCCESS; |
| 7790 | } |
| 7791 | |
| 7792 | return IOCB_BUSY; |
| 7793 | } |
| 7794 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7795 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7796 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 7797 | * @phba: Pointer to HBA context object. |
| 7798 | * @piocb: Pointer to command iocb. |
| 7799 | * @sglq: Pointer to the scatter gather queue object. |
| 7800 | * |
| 7801 | * This routine converts the bpl or bde that is in the IOCB |
| 7802 | * to a sgl list for the sli4 hardware. The physical address |
| 7803 | * of the bpl/bde is converted back to a virtual address. |
| 7804 | * If the IOCB contains a BPL then the list of BDE's is |
| 7805 | * converted to sli4_sge's. If the IOCB contains a single |
| 7806 | * BDE then it is converted to a single sli_sge. |
| 7807 | * The IOCB is still in cpu endianess so the contents of |
| 7808 | * the bpl can be used without byte swapping. |
| 7809 | * |
| 7810 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 7811 | **/ |
| 7812 | static uint16_t |
| 7813 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 7814 | struct lpfc_sglq *sglq) |
| 7815 | { |
| 7816 | uint16_t xritag = NO_XRI; |
| 7817 | struct ulp_bde64 *bpl = NULL; |
| 7818 | struct ulp_bde64 bde; |
| 7819 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7820 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7821 | IOCB_t *icmd; |
| 7822 | int numBdes = 0; |
| 7823 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7824 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 7825 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7826 | |
| 7827 | if (!piocbq || !sglq) |
| 7828 | return xritag; |
| 7829 | |
| 7830 | sgl = (struct sli4_sge *)sglq->sgl; |
| 7831 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7832 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 7833 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7834 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 7835 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 7836 | sizeof(struct ulp_bde64); |
| 7837 | /* The addrHigh and addrLow fields within the IOCB |
| 7838 | * have not been byteswapped yet so there is no |
| 7839 | * need to swap them back. |
| 7840 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7841 | if (piocbq->context3) |
| 7842 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 7843 | else |
| 7844 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7845 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7846 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7847 | if (!bpl) |
| 7848 | return xritag; |
| 7849 | |
| 7850 | for (i = 0; i < numBdes; i++) { |
| 7851 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7852 | sgl->addr_hi = bpl->addrHigh; |
| 7853 | sgl->addr_lo = bpl->addrLow; |
| 7854 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7855 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7856 | if ((i+1) == numBdes) |
| 7857 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7858 | else |
| 7859 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7860 | /* swap the size field back to the cpu so we |
| 7861 | * can assign it to the sgl. |
| 7862 | */ |
| 7863 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 7864 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7865 | /* The offsets in the sgl need to be accumulated |
| 7866 | * separately for the request and reply lists. |
| 7867 | * The request is always first, the reply follows. |
| 7868 | */ |
| 7869 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 7870 | /* add up the reply sg entries */ |
| 7871 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 7872 | inbound++; |
| 7873 | /* first inbound? reset the offset */ |
| 7874 | if (inbound == 1) |
| 7875 | offset = 0; |
| 7876 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 7877 | bf_set(lpfc_sli4_sge_type, sgl, |
| 7878 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7879 | offset += bde.tus.f.bdeSize; |
| 7880 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7881 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7882 | bpl++; |
| 7883 | sgl++; |
| 7884 | } |
| 7885 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 7886 | /* The addrHigh and addrLow fields of the BDE have not |
| 7887 | * been byteswapped yet so they need to be swapped |
| 7888 | * before putting them in the sgl. |
| 7889 | */ |
| 7890 | sgl->addr_hi = |
| 7891 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 7892 | sgl->addr_lo = |
| 7893 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7894 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7895 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7896 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7897 | sgl->sge_len = |
| 7898 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7899 | } |
| 7900 | return sglq->sli4_xritag; |
| 7901 | } |
| 7902 | |
| 7903 | /** |
| 7904 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 7905 | * @phba: Pointer to HBA context object. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7906 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 7907 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7908 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 7909 | * held. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7910 | * |
| 7911 | * Return: index into SLI4 fast-path FCP queue index. |
| 7912 | **/ |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7913 | static inline uint32_t |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7914 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7915 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7916 | int i; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7917 | |
James Smart | 49aa143 | 2012-08-03 12:36:42 -0400 | [diff] [blame] | 7918 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU) |
| 7919 | i = smp_processor_id(); |
| 7920 | else |
| 7921 | i = atomic_add_return(1, &phba->fcp_qidx); |
| 7922 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7923 | i = (i % phba->cfg_fcp_io_channel); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7924 | return i; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7925 | } |
| 7926 | |
| 7927 | /** |
| 7928 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 7929 | * @phba: Pointer to HBA context object. |
| 7930 | * @piocb: Pointer to command iocb. |
| 7931 | * @wqe: Pointer to the work queue entry. |
| 7932 | * |
| 7933 | * This routine converts the iocb command to its Work Queue Entry |
| 7934 | * equivalent. The wqe pointer should not have any fields set when |
| 7935 | * this routine is called because it will memcpy over them. |
| 7936 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 7937 | * wqe. |
| 7938 | * |
| 7939 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 7940 | **/ |
| 7941 | static int |
| 7942 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 7943 | union lpfc_wqe *wqe) |
| 7944 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7945 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7946 | uint8_t ct = 0; |
| 7947 | uint32_t fip; |
| 7948 | uint32_t abort_tag; |
| 7949 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 7950 | uint8_t cmnd; |
| 7951 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 7952 | uint16_t abrt_iotag; |
| 7953 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7954 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7955 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7956 | int numBdes, i; |
| 7957 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7958 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7959 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7960 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7961 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7962 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7963 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7964 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7965 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7966 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7967 | command_type = ELS_COMMAND_FIP; |
| 7968 | else |
| 7969 | command_type = ELS_COMMAND_NON_FIP; |
| 7970 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7971 | /* Some of the fields are in the right position already */ |
| 7972 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
| 7973 | abort_tag = (uint32_t) iocbq->iotag; |
| 7974 | xritag = iocbq->sli4_xritag; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7975 | 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] | 7976 | /* words0-2 bpl convert bde */ |
| 7977 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7978 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 7979 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7980 | bpl = (struct ulp_bde64 *) |
| 7981 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 7982 | if (!bpl) |
| 7983 | return IOCB_ERROR; |
| 7984 | |
| 7985 | /* Should already be byte swapped. */ |
| 7986 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 7987 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 7988 | /* swap the size field back to the cpu so we |
| 7989 | * can assign it to the sgl. |
| 7990 | */ |
| 7991 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7992 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 7993 | total_len = 0; |
| 7994 | for (i = 0; i < numBdes; i++) { |
| 7995 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 7996 | total_len += bde.tus.f.bdeSize; |
| 7997 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7998 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7999 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8000 | |
| 8001 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8002 | cmnd = iocbq->iocb.ulpCommand; |
| 8003 | |
| 8004 | switch (iocbq->iocb.ulpCommand) { |
| 8005 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8006 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8007 | ndlp = iocbq->context_un.ndlp; |
| 8008 | else |
| 8009 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8010 | if (!iocbq->iocb.ulpLe) { |
| 8011 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8012 | "2007 Only Limited Edition cmd Format" |
| 8013 | " supported 0x%x\n", |
| 8014 | iocbq->iocb.ulpCommand); |
| 8015 | return IOCB_ERROR; |
| 8016 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8017 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8018 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8019 | /* Els_reguest64 has a TMO */ |
| 8020 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8021 | iocbq->iocb.ulpTimeout); |
| 8022 | /* Need a VF for word 4 set the vf bit*/ |
| 8023 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8024 | /* And a VFID for word 12 */ |
| 8025 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8026 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8027 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8028 | iocbq->iocb.ulpContext); |
| 8029 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8030 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8031 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8032 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8033 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8034 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8035 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8036 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8037 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8038 | &phba->sli4_hba.sli_intf); |
| 8039 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8040 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8041 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8042 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8043 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8044 | *pcmd == ELS_CMD_PLOGI)) { |
| 8045 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8046 | bf_set(els_req64_sid, &wqe->els_req, |
| 8047 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8048 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8049 | !(phba->fc_topology == |
| 8050 | LPFC_TOPOLOGY_LOOP)) |
| 8051 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8052 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8053 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8054 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8055 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8056 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8057 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8058 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8059 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8060 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8061 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8062 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8063 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8064 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8065 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8066 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8067 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8068 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8069 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8070 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8071 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8072 | iocbq->iocb.un.ulpWord[3]); |
| 8073 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8074 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8075 | /* The entire sequence is transmitted for this IOCB */ |
| 8076 | xmit_len = total_len; |
| 8077 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8078 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8079 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8080 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8081 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8082 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8083 | /* word4 relative_offset memcpy */ |
| 8084 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8085 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8086 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8087 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8088 | LPFC_WQE_IOD_WRITE); |
| 8089 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8090 | LPFC_WQE_LENLOC_WORD12); |
| 8091 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8092 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8093 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8094 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8095 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8096 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8097 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8098 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8099 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8100 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8101 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8102 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8103 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8104 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8105 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8106 | LPFC_WQE_LENLOC_WORD3); |
| 8107 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8108 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8109 | case CMD_FCP_IWRITE64_CR: |
| 8110 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8111 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8112 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8113 | wqe->fcp_iwrite.payload_offset_len = |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8114 | xmit_len + sizeof(struct fcp_rsp); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8115 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8116 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8117 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8118 | iocbq->iocb.ulpFCP2Rcvy); |
| 8119 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8120 | /* Always open the exchange */ |
| 8121 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8122 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8123 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8124 | LPFC_WQE_LENLOC_WORD4); |
| 8125 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); |
| 8126 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8127 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8128 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8129 | case CMD_FCP_IREAD64_CR: |
| 8130 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8131 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8132 | wqe->fcp_iread.payload_offset_len = |
| 8133 | xmit_len + sizeof(struct fcp_rsp); |
| 8134 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8135 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8136 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8137 | iocbq->iocb.ulpFCP2Rcvy); |
| 8138 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8139 | /* Always open the exchange */ |
| 8140 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8141 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8142 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8143 | LPFC_WQE_LENLOC_WORD4); |
| 8144 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); |
| 8145 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8146 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8147 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8148 | case CMD_FCP_ICMND64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8149 | /* word3 iocb=IO_TAG wqe=reserved */ |
| 8150 | wqe->fcp_icmd.rsrvd3 = 0; |
| 8151 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8152 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8153 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
| 8154 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8155 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8156 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8157 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8158 | LPFC_WQE_LENLOC_NONE); |
| 8159 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8160 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8161 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8162 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8163 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8164 | /* For this command calculate the xmit length of the |
| 8165 | * request bde. |
| 8166 | */ |
| 8167 | xmit_len = 0; |
| 8168 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8169 | sizeof(struct ulp_bde64); |
| 8170 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8171 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8172 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8173 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8174 | xmit_len += bde.tus.f.bdeSize; |
| 8175 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8176 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8177 | wqe->gen_req.request_payload_len = xmit_len; |
| 8178 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8179 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8180 | /* word6 context tag copied in memcpy */ |
| 8181 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8182 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8183 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8184 | "2015 Invalid CT %x command 0x%x\n", |
| 8185 | ct, iocbq->iocb.ulpCommand); |
| 8186 | return IOCB_ERROR; |
| 8187 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8188 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8189 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8190 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8191 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8192 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8193 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8194 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8195 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8196 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8197 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8198 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8199 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8200 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8201 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8202 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8203 | /* word4 */ |
| 8204 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8205 | /* word5 iocb=rsvd wge=did */ |
| 8206 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8207 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8208 | |
| 8209 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8210 | &phba->sli4_hba.sli_intf); |
| 8211 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8212 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8213 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8214 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8215 | iocbq->vport->fc_myDID); |
| 8216 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8217 | bf_set(wqe_els_did, |
| 8218 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8219 | } |
| 8220 | } |
| 8221 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8222 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8223 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8224 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8225 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8226 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8227 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8228 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8229 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8230 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8231 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8232 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8233 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8234 | LPFC_WQE_LENLOC_WORD3); |
| 8235 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8236 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8237 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8238 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8239 | iocbq->context2)->virt); |
| 8240 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8241 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8242 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8243 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8244 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8245 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8246 | phba->vpi_ids[phba->pport->vpi]); |
| 8247 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8248 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8249 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8250 | case CMD_CLOSE_XRI_CN: |
| 8251 | case CMD_ABORT_XRI_CN: |
| 8252 | case CMD_ABORT_XRI_CX: |
| 8253 | /* words 0-2 memcpy should be 0 rserved */ |
| 8254 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8255 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8256 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8257 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8258 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8259 | } else |
| 8260 | fip = 0; |
| 8261 | |
| 8262 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8263 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8264 | * The link is down, or the command was ELS_FIP |
| 8265 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8266 | * on the wire. |
| 8267 | */ |
| 8268 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8269 | else |
| 8270 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8271 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8272 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8273 | wqe->abort_cmd.rsrvd5 = 0; |
| 8274 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8275 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8276 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8277 | /* |
| 8278 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8279 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8280 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8281 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8282 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8283 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8284 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8285 | cmnd = CMD_ABORT_XRI_CX; |
| 8286 | command_type = OTHER_COMMAND; |
| 8287 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8288 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8289 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8290 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8291 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8292 | * we re-construct this WQE here based on information in |
| 8293 | * iocbq from scratch. |
| 8294 | */ |
| 8295 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8296 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8297 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8298 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8299 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8300 | LPFC_ABTS_UNSOL_INT) { |
| 8301 | /* ABTS sent by initiator to CT exchange, the |
| 8302 | * RX_ID field will be filled with the newly |
| 8303 | * allocated responder XRI. |
| 8304 | */ |
| 8305 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8306 | iocbq->sli4_xritag); |
| 8307 | } else { |
| 8308 | /* ABTS sent by responder to CT exchange, the |
| 8309 | * RX_ID field will be filled with the responder |
| 8310 | * RX_ID from ABTS. |
| 8311 | */ |
| 8312 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8313 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8314 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8315 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8316 | 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] | 8317 | |
| 8318 | /* Use CT=VPI */ |
| 8319 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8320 | ndlp->nlp_DID); |
| 8321 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8322 | iocbq->iocb.ulpContext); |
| 8323 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8324 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8325 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8326 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8327 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8328 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8329 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8330 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8331 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8332 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8333 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8334 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8335 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8336 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8337 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8338 | } |
| 8339 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8340 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8341 | case CMD_XRI_ABORTED_CX: |
| 8342 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8343 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8344 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8345 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8346 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8347 | default: |
| 8348 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8349 | "2014 Invalid command 0x%x\n", |
| 8350 | iocbq->iocb.ulpCommand); |
| 8351 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8352 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8353 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8354 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 8355 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 8356 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 8357 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 8358 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 8359 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 8360 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 8361 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 8362 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8363 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8364 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8365 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8366 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8367 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8368 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8369 | 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] | 8370 | return 0; |
| 8371 | } |
| 8372 | |
| 8373 | /** |
| 8374 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8375 | * @phba: Pointer to HBA context object. |
| 8376 | * @ring_number: SLI ring number to issue iocb on. |
| 8377 | * @piocb: Pointer to command iocb. |
| 8378 | * @flag: Flag indicating if this command can be put into txq. |
| 8379 | * |
| 8380 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8381 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8382 | * |
| 8383 | * This function is called with hbalock held. The function will return success |
| 8384 | * after it successfully submit the iocb to firmware or after adding to the |
| 8385 | * txq. |
| 8386 | **/ |
| 8387 | static int |
| 8388 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8389 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8390 | { |
| 8391 | struct lpfc_sglq *sglq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8392 | union lpfc_wqe wqe; |
| 8393 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8394 | |
| 8395 | if (piocb->sli4_xritag == NO_XRI) { |
| 8396 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8397 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8398 | sglq = NULL; |
| 8399 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8400 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8401 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8402 | __lpfc_sli_ringtx_put(phba, |
| 8403 | pring, piocb); |
| 8404 | return IOCB_SUCCESS; |
| 8405 | } else { |
| 8406 | return IOCB_BUSY; |
| 8407 | } |
| 8408 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8409 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8410 | if (!sglq) { |
| 8411 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8412 | __lpfc_sli_ringtx_put(phba, |
| 8413 | pring, |
| 8414 | piocb); |
| 8415 | return IOCB_SUCCESS; |
| 8416 | } else |
| 8417 | return IOCB_BUSY; |
| 8418 | } |
| 8419 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8420 | } |
| 8421 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8422 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8423 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8424 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8425 | /* |
| 8426 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8427 | * sglq is on the active list |
| 8428 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 8429 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8430 | if (!sglq) |
| 8431 | return IOCB_ERROR; |
| 8432 | } |
| 8433 | |
| 8434 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8435 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8436 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8437 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8438 | return IOCB_ERROR; |
| 8439 | } |
| 8440 | |
| 8441 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
| 8442 | return IOCB_ERROR; |
| 8443 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8444 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 8445 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8446 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
| 8447 | &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8448 | return IOCB_ERROR; |
| 8449 | } else { |
| 8450 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 8451 | return IOCB_ERROR; |
| 8452 | } |
| 8453 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8454 | |
| 8455 | return 0; |
| 8456 | } |
| 8457 | |
| 8458 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8459 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8460 | * |
| 8461 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8462 | * pointer from the lpfc_hba struct. |
| 8463 | * |
| 8464 | * Return codes: |
| 8465 | * IOCB_ERROR - Error |
| 8466 | * IOCB_SUCCESS - Success |
| 8467 | * IOCB_BUSY - Busy |
| 8468 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8469 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8470 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8471 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8472 | { |
| 8473 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8474 | } |
| 8475 | |
| 8476 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8477 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8478 | * @phba: The hba struct for which this call is being executed. |
| 8479 | * @dev_grp: The HBA PCI-Device group number. |
| 8480 | * |
| 8481 | * This routine sets up the SLI interface API function jump table in @phba |
| 8482 | * struct. |
| 8483 | * Returns: 0 - success, -ENODEV - failure. |
| 8484 | **/ |
| 8485 | int |
| 8486 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8487 | { |
| 8488 | |
| 8489 | switch (dev_grp) { |
| 8490 | case LPFC_PCI_DEV_LP: |
| 8491 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8492 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8493 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8494 | case LPFC_PCI_DEV_OC: |
| 8495 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8496 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8497 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8498 | default: |
| 8499 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8500 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8501 | dev_grp); |
| 8502 | return -ENODEV; |
| 8503 | break; |
| 8504 | } |
| 8505 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8506 | return 0; |
| 8507 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8509 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8510 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8511 | * @phba: Pointer to HBA context object. |
| 8512 | * @pring: Pointer to driver SLI ring object. |
| 8513 | * @piocb: Pointer to command iocb. |
| 8514 | * @flag: Flag indicating if this command can be put into txq. |
| 8515 | * |
| 8516 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8517 | * function. This function gets the hbalock and calls |
| 8518 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8519 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8520 | * functions which do not hold hbalock. |
| 8521 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8522 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8523 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8524 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8525 | { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8526 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8527 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8528 | struct lpfc_queue *fpeq; |
| 8529 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8530 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8531 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8532 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8533 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8534 | if (piocb->iocb_flag & LPFC_IO_FCP) { |
| 8535 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8536 | return IOCB_ERROR; |
| 8537 | idx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
| 8538 | piocb->fcp_wqidx = idx; |
| 8539 | ring_number = MAX_SLI3_CONFIGURED_RINGS + idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8540 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8541 | pring = &phba->sli.ring[ring_number]; |
| 8542 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8543 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 8544 | flag); |
| 8545 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8546 | |
| 8547 | if (lpfc_fcp_look_ahead) { |
| 8548 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; |
| 8549 | |
| 8550 | if (atomic_dec_and_test(&fcp_eq_hdl-> |
| 8551 | fcp_eq_in_use)) { |
| 8552 | |
| 8553 | /* Get associated EQ with this index */ |
| 8554 | fpeq = phba->sli4_hba.hba_eq[idx]; |
| 8555 | |
| 8556 | /* Turn off interrupts from this EQ */ |
| 8557 | lpfc_sli4_eq_clr_intr(fpeq); |
| 8558 | |
| 8559 | /* |
| 8560 | * Process all the events on FCP EQ |
| 8561 | */ |
| 8562 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 8563 | lpfc_sli4_hba_handle_eqe(phba, |
| 8564 | eqe, idx); |
| 8565 | fpeq->EQ_processed++; |
| 8566 | } |
| 8567 | |
| 8568 | /* Always clear and re-arm the EQ */ |
| 8569 | lpfc_sli4_eq_release(fpeq, |
| 8570 | LPFC_QUEUE_REARM); |
| 8571 | } |
| 8572 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 8573 | } |
| 8574 | } else { |
| 8575 | pring = &phba->sli.ring[ring_number]; |
| 8576 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8577 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 8578 | flag); |
| 8579 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8580 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8581 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8582 | } else { |
| 8583 | /* For now, SLI2/3 will still use hbalock */ |
| 8584 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8585 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8586 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8587 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8588 | return rc; |
| 8589 | } |
| 8590 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8591 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8592 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8593 | * @phba: Pointer to HBA context object. |
| 8594 | * |
| 8595 | * This function is called while driver attaches with the |
| 8596 | * HBA to setup the extra ring. The extra ring is used |
| 8597 | * only when driver needs to support target mode functionality |
| 8598 | * or IP over FC functionalities. |
| 8599 | * |
| 8600 | * This function is called with no lock held. |
| 8601 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8602 | static int |
| 8603 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 8604 | { |
| 8605 | struct lpfc_sli *psli; |
| 8606 | struct lpfc_sli_ring *pring; |
| 8607 | |
| 8608 | psli = &phba->sli; |
| 8609 | |
| 8610 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8611 | |
| 8612 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8613 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8614 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8615 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8616 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8617 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8618 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8619 | /* and give them to the extra ring */ |
| 8620 | pring = &psli->ring[psli->extra_ring]; |
| 8621 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8622 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8623 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8624 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8625 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8626 | |
| 8627 | /* Setup default profile for this ring */ |
| 8628 | pring->iotag_max = 4096; |
| 8629 | pring->num_mask = 1; |
| 8630 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8631 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 8632 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8633 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 8634 | return 0; |
| 8635 | } |
| 8636 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8637 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 8638 | * @phba: Pointer to HBA context object. |
| 8639 | * @iocbq: Pointer to iocb object. |
| 8640 | * |
| 8641 | * The async_event handler calls this routine when it receives |
| 8642 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 8643 | * this event when an Abort Sequence request to an rport fails |
| 8644 | * twice in succession. The abort could be originated by the |
| 8645 | * driver or by the port. The ABTS could have been for an ELS |
| 8646 | * or FCP IO. The port only generates this event when an ABTS |
| 8647 | * fails to complete after one retry. |
| 8648 | */ |
| 8649 | static void |
| 8650 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 8651 | struct lpfc_iocbq *iocbq) |
| 8652 | { |
| 8653 | struct lpfc_nodelist *ndlp = NULL; |
| 8654 | uint16_t rpi = 0, vpi = 0; |
| 8655 | struct lpfc_vport *vport = NULL; |
| 8656 | |
| 8657 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 8658 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 8659 | rpi = iocbq->iocb.ulpContext; |
| 8660 | |
| 8661 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8662 | "3092 Port generated ABTS async event " |
| 8663 | "on vpi %d rpi %d status 0x%x\n", |
| 8664 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 8665 | |
| 8666 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 8667 | if (!vport) |
| 8668 | goto err_exit; |
| 8669 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 8670 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8671 | goto err_exit; |
| 8672 | |
| 8673 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 8674 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8675 | return; |
| 8676 | |
| 8677 | err_exit: |
| 8678 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8679 | "3095 Event Context not found, no " |
| 8680 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 8681 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 8682 | vpi, rpi); |
| 8683 | } |
| 8684 | |
| 8685 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 8686 | * @phba: pointer to HBA context object. |
| 8687 | * @ndlp: nodelist pointer for the impacted rport. |
| 8688 | * @axri: pointer to the wcqe containing the failed exchange. |
| 8689 | * |
| 8690 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 8691 | * port. The port generates this event when an abort exchange request to an |
| 8692 | * rport fails twice in succession with no reply. The abort could be originated |
| 8693 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 8694 | */ |
| 8695 | void |
| 8696 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 8697 | struct lpfc_nodelist *ndlp, |
| 8698 | struct sli4_wcqe_xri_aborted *axri) |
| 8699 | { |
| 8700 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8701 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8702 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8703 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8704 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8705 | "3115 Node Context not found, driver " |
| 8706 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8707 | return; |
| 8708 | } |
| 8709 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8710 | vport = ndlp->vport; |
| 8711 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8712 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8713 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8714 | ndlp->vport->vpi, ndlp->nlp_rpi, |
| 8715 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8716 | bf_get(lpfc_wcqe_xa_status, axri), |
| 8717 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8718 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8719 | /* |
| 8720 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 8721 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 8722 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 8723 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 8724 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8725 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 8726 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8727 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8728 | } |
| 8729 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8730 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8731 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8732 | * @phba: Pointer to HBA context object. |
| 8733 | * @pring: Pointer to driver SLI ring object. |
| 8734 | * @iocbq: Pointer to iocb object. |
| 8735 | * |
| 8736 | * This function is called by the slow ring event handler |
| 8737 | * function when there is an ASYNC event iocb in the ring. |
| 8738 | * This function is called with no lock held. |
| 8739 | * Currently this function handles only temperature related |
| 8740 | * ASYNC events. The function decodes the temperature sensor |
| 8741 | * event message and posts events for the management applications. |
| 8742 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8743 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8744 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 8745 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 8746 | { |
| 8747 | IOCB_t *icmd; |
| 8748 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8749 | struct temp_event temp_event_data; |
| 8750 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8751 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8752 | |
| 8753 | icmd = &iocbq->iocb; |
| 8754 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8755 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8756 | switch (evt_code) { |
| 8757 | case ASYNC_TEMP_WARN: |
| 8758 | case ASYNC_TEMP_SAFE: |
| 8759 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 8760 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 8761 | if (evt_code == ASYNC_TEMP_WARN) { |
| 8762 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 8763 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8764 | "0347 Adapter is very hot, please take " |
| 8765 | "corrective action. temperature : %d Celsius\n", |
| 8766 | (uint32_t) icmd->ulpContext); |
| 8767 | } else { |
| 8768 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 8769 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8770 | "0340 Adapter temperature is OK now. " |
| 8771 | "temperature : %d Celsius\n", |
| 8772 | (uint32_t) icmd->ulpContext); |
| 8773 | } |
| 8774 | |
| 8775 | /* Send temperature change event to applications */ |
| 8776 | shost = lpfc_shost_from_vport(phba->pport); |
| 8777 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 8778 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 8779 | LPFC_NL_VENDOR_ID); |
| 8780 | break; |
| 8781 | case ASYNC_STATUS_CN: |
| 8782 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 8783 | break; |
| 8784 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8785 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8786 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8787 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 8788 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8789 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 8790 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 8791 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 8792 | "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] | 8793 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8794 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 8795 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 8796 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 8797 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 8798 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8799 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8800 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8801 | } |
| 8802 | |
| 8803 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8804 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8805 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8806 | * @phba: Pointer to HBA context object. |
| 8807 | * |
| 8808 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 8809 | * number of iocbs per ring and iotags. This function is |
| 8810 | * called while driver attach to the HBA and before the |
| 8811 | * interrupts are enabled. So there is no need for locking. |
| 8812 | * |
| 8813 | * This function always returns 0. |
| 8814 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8815 | int |
| 8816 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 8817 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8818 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8819 | struct lpfc_sli *psli = &phba->sli; |
| 8820 | struct lpfc_sli_ring *pring; |
| 8821 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8822 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| 8823 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8824 | psli->num_rings += phba->cfg_fcp_io_channel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8825 | psli->sli_flag = 0; |
| 8826 | psli->fcp_ring = LPFC_FCP_RING; |
| 8827 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8828 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8829 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8830 | psli->iocbq_lookup = NULL; |
| 8831 | psli->iocbq_lookup_len = 0; |
| 8832 | psli->last_iotag = 0; |
| 8833 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8834 | for (i = 0; i < psli->num_rings; i++) { |
| 8835 | pring = &psli->ring[i]; |
| 8836 | switch (i) { |
| 8837 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 8838 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8839 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 8840 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 8841 | pring->sli.sli3.numCiocb += |
| 8842 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8843 | pring->sli.sli3.numRiocb += |
| 8844 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8845 | pring->sli.sli3.numCiocb += |
| 8846 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8847 | pring->sli.sli3.numRiocb += |
| 8848 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8849 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8850 | SLI3_IOCB_CMD_SIZE : |
| 8851 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8852 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8853 | SLI3_IOCB_RSP_SIZE : |
| 8854 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8855 | pring->iotag_ctr = 0; |
| 8856 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8857 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8858 | pring->fast_iotag = pring->iotag_max; |
| 8859 | pring->num_mask = 0; |
| 8860 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8861 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8862 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8863 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 8864 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 8865 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8866 | SLI3_IOCB_CMD_SIZE : |
| 8867 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8868 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8869 | SLI3_IOCB_RSP_SIZE : |
| 8870 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8871 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8872 | pring->num_mask = 0; |
| 8873 | break; |
| 8874 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 8875 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8876 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 8877 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 8878 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8879 | SLI3_IOCB_CMD_SIZE : |
| 8880 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8881 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8882 | SLI3_IOCB_RSP_SIZE : |
| 8883 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8884 | pring->fast_iotag = 0; |
| 8885 | pring->iotag_ctr = 0; |
| 8886 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8887 | pring->lpfc_sli_rcv_async_status = |
| 8888 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8889 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8890 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8891 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 8892 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8893 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8894 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8895 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8896 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 8897 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8898 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8899 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8900 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 8901 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8902 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8903 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8904 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8905 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8906 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8907 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 8908 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8909 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8910 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8911 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8912 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8913 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8914 | break; |
| 8915 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8916 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 8917 | pring->sli.sli3.sizeCiocb) + |
| 8918 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8919 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8920 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8921 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8922 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 8923 | "SLI2 SLIM Data: x%x x%lx\n", |
| 8924 | phba->brd_no, totiocbsize, |
| 8925 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8926 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8927 | if (phba->cfg_multi_ring_support == 2) |
| 8928 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8929 | |
| 8930 | return 0; |
| 8931 | } |
| 8932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8934 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8935 | * @phba: Pointer to HBA context object. |
| 8936 | * |
| 8937 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 8938 | * ring. This function also initializes ring indices of each ring. |
| 8939 | * This function is called during the initialization of the SLI |
| 8940 | * interface of an HBA. |
| 8941 | * This function is called with no lock held and always returns |
| 8942 | * 1. |
| 8943 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8944 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8945 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8946 | { |
| 8947 | struct lpfc_sli *psli; |
| 8948 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8949 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8950 | |
| 8951 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8952 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8953 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8954 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8955 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 8956 | for (i = 0; i < psli->num_rings; i++) { |
| 8957 | pring = &psli->ring[i]; |
| 8958 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8959 | pring->sli.sli3.next_cmdidx = 0; |
| 8960 | pring->sli.sli3.local_getidx = 0; |
| 8961 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8962 | INIT_LIST_HEAD(&pring->txq); |
| 8963 | INIT_LIST_HEAD(&pring->txcmplq); |
| 8964 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 8965 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8966 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8967 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8968 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8969 | spin_unlock_irq(&phba->hbalock); |
| 8970 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8971 | } |
| 8972 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8973 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8974 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 8975 | * @phba: Pointer to HBA context object. |
| 8976 | * |
| 8977 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 8978 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 8979 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 8980 | * command; and completed mailbox command queue. It is caller's responsibility |
| 8981 | * to make sure that the driver is in the proper state to flush the mailbox |
| 8982 | * command sub-system. Namely, the posting of mailbox commands into the |
| 8983 | * pending mailbox command queue from the various clients must be stopped; |
| 8984 | * either the HBA is in a state that it will never works on the outstanding |
| 8985 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 8986 | * mailbox command has been completed. |
| 8987 | **/ |
| 8988 | static void |
| 8989 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 8990 | { |
| 8991 | LIST_HEAD(completions); |
| 8992 | struct lpfc_sli *psli = &phba->sli; |
| 8993 | LPFC_MBOXQ_t *pmb; |
| 8994 | unsigned long iflag; |
| 8995 | |
| 8996 | /* Flush all the mailbox commands in the mbox system */ |
| 8997 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8998 | /* The pending mailbox command queue */ |
| 8999 | list_splice_init(&phba->sli.mboxq, &completions); |
| 9000 | /* The outstanding active mailbox command */ |
| 9001 | if (psli->mbox_active) { |
| 9002 | list_add_tail(&psli->mbox_active->list, &completions); |
| 9003 | psli->mbox_active = NULL; |
| 9004 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9005 | } |
| 9006 | /* The completed mailbox command queue */ |
| 9007 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 9008 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9009 | |
| 9010 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 9011 | while (!list_empty(&completions)) { |
| 9012 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 9013 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9014 | if (pmb->mbox_cmpl) |
| 9015 | pmb->mbox_cmpl(phba, pmb); |
| 9016 | } |
| 9017 | } |
| 9018 | |
| 9019 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9020 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9021 | * @vport: Pointer to virtual port object. |
| 9022 | * |
| 9023 | * lpfc_sli_host_down is called to clean up the resources |
| 9024 | * associated with a vport before destroying virtual |
| 9025 | * port data structures. |
| 9026 | * This function does following operations: |
| 9027 | * - Free discovery resources associated with this virtual |
| 9028 | * port. |
| 9029 | * - Free iocbs associated with this virtual port in |
| 9030 | * the txq. |
| 9031 | * - Send abort for all iocb commands associated with this |
| 9032 | * vport in txcmplq. |
| 9033 | * |
| 9034 | * This function is called with no lock held and always returns 1. |
| 9035 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9036 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9037 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 9038 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9039 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9040 | struct lpfc_hba *phba = vport->phba; |
| 9041 | struct lpfc_sli *psli = &phba->sli; |
| 9042 | struct lpfc_sli_ring *pring; |
| 9043 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9044 | int i; |
| 9045 | unsigned long flags = 0; |
| 9046 | uint16_t prev_pring_flag; |
| 9047 | |
| 9048 | lpfc_cleanup_discovery_resources(vport); |
| 9049 | |
| 9050 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9051 | for (i = 0; i < psli->num_rings; i++) { |
| 9052 | pring = &psli->ring[i]; |
| 9053 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9054 | /* Only slow rings */ |
| 9055 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9056 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9057 | /* Set the lpfc data pending flag */ |
| 9058 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9059 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9060 | /* |
| 9061 | * Error everything on the txq since these iocbs have not been |
| 9062 | * given to the FW yet. |
| 9063 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9064 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 9065 | if (iocb->vport != vport) |
| 9066 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9067 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9068 | } |
| 9069 | |
| 9070 | /* Next issue ABTS for everything on the txcmplq */ |
| 9071 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 9072 | list) { |
| 9073 | if (iocb->vport != vport) |
| 9074 | continue; |
| 9075 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 9076 | } |
| 9077 | |
| 9078 | pring->flag = prev_pring_flag; |
| 9079 | } |
| 9080 | |
| 9081 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9082 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9083 | /* Cancel all the IOCBs from the completions list */ |
| 9084 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9085 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9086 | return 1; |
| 9087 | } |
| 9088 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9089 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9090 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9091 | * @phba: Pointer to HBA context object. |
| 9092 | * |
| 9093 | * This function cleans up all iocb, buffers, mailbox commands |
| 9094 | * while shutting down the HBA. This function is called with no |
| 9095 | * lock held and always returns 1. |
| 9096 | * This function does the following to cleanup driver resources: |
| 9097 | * - Free discovery resources for each virtual port |
| 9098 | * - Cleanup any pending fabric iocbs |
| 9099 | * - Iterate through the iocb txq and free each entry |
| 9100 | * in the list. |
| 9101 | * - Free up any buffer posted to the HBA |
| 9102 | * - Free mailbox commands in the mailbox queue. |
| 9103 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9104 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9105 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9106 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9107 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9108 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9109 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9110 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9111 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9112 | int i; |
| 9113 | |
| 9114 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9115 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9116 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9117 | lpfc_hba_down_prep(phba); |
| 9118 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9119 | lpfc_fabric_abort_hba(phba); |
| 9120 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9121 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9122 | for (i = 0; i < psli->num_rings; i++) { |
| 9123 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9124 | /* Only slow rings */ |
| 9125 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9126 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9127 | /* Set the lpfc data pending flag */ |
| 9128 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9129 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9130 | |
| 9131 | /* |
| 9132 | * Error everything on the txq since these iocbs have not been |
| 9133 | * given to the FW yet. |
| 9134 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9135 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9136 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9137 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9138 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9139 | /* Cancel all the IOCBs from the completions list */ |
| 9140 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9141 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9142 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9143 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9144 | list_splice_init(&phba->elsbuf, &completions); |
| 9145 | phba->elsbuf_cnt = 0; |
| 9146 | phba->elsbuf_prev_cnt = 0; |
| 9147 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9148 | |
| 9149 | while (!list_empty(&completions)) { |
| 9150 | list_remove_head(&completions, buf_ptr, |
| 9151 | struct lpfc_dmabuf, list); |
| 9152 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9153 | kfree(buf_ptr); |
| 9154 | } |
| 9155 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9156 | /* Return any active mbox cmds */ |
| 9157 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9158 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9159 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9160 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9161 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9162 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9163 | return 1; |
| 9164 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9165 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9167 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9168 | * @srcp: Source memory pointer. |
| 9169 | * @destp: Destination memory pointer. |
| 9170 | * @cnt: Number of words required to be copied. |
| 9171 | * |
| 9172 | * This function is used for copying data between driver memory |
| 9173 | * and the SLI memory. This function also changes the endianness |
| 9174 | * of each word if native endianness is different from SLI |
| 9175 | * endianness. This function can be called with or without |
| 9176 | * lock. |
| 9177 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9178 | void |
| 9179 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9180 | { |
| 9181 | uint32_t *src = srcp; |
| 9182 | uint32_t *dest = destp; |
| 9183 | uint32_t ldata; |
| 9184 | int i; |
| 9185 | |
| 9186 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9187 | ldata = *src; |
| 9188 | ldata = le32_to_cpu(ldata); |
| 9189 | *dest = ldata; |
| 9190 | src++; |
| 9191 | dest++; |
| 9192 | } |
| 9193 | } |
| 9194 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9195 | |
| 9196 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9197 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9198 | * @srcp: Source memory pointer. |
| 9199 | * @destp: Destination memory pointer. |
| 9200 | * @cnt: Number of words required to be copied. |
| 9201 | * |
| 9202 | * This function is used for copying data between a data structure |
| 9203 | * with big endian representation to local endianness. |
| 9204 | * This function can be called with or without lock. |
| 9205 | **/ |
| 9206 | void |
| 9207 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9208 | { |
| 9209 | uint32_t *src = srcp; |
| 9210 | uint32_t *dest = destp; |
| 9211 | uint32_t ldata; |
| 9212 | int i; |
| 9213 | |
| 9214 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9215 | ldata = *src; |
| 9216 | ldata = be32_to_cpu(ldata); |
| 9217 | *dest = ldata; |
| 9218 | src++; |
| 9219 | dest++; |
| 9220 | } |
| 9221 | } |
| 9222 | |
| 9223 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9224 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9225 | * @phba: Pointer to HBA context object. |
| 9226 | * @pring: Pointer to driver SLI ring object. |
| 9227 | * @mp: Pointer to driver buffer object. |
| 9228 | * |
| 9229 | * This function is called with no lock held. |
| 9230 | * It always return zero after adding the buffer to the postbufq |
| 9231 | * buffer list. |
| 9232 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9233 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9234 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9235 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9236 | { |
| 9237 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9238 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9239 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9240 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9241 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9242 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9243 | return 0; |
| 9244 | } |
| 9245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9246 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9247 | * 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] | 9248 | * @phba: Pointer to HBA context object. |
| 9249 | * |
| 9250 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9251 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9252 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9253 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9254 | * The function returns the allocated tag. The function is called with |
| 9255 | * no locks held. |
| 9256 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9257 | uint32_t |
| 9258 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9259 | { |
| 9260 | spin_lock_irq(&phba->hbalock); |
| 9261 | phba->buffer_tag_count++; |
| 9262 | /* |
| 9263 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9264 | * a tag assigned by HBQ. |
| 9265 | */ |
| 9266 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9267 | spin_unlock_irq(&phba->hbalock); |
| 9268 | return phba->buffer_tag_count; |
| 9269 | } |
| 9270 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9271 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9272 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9273 | * @phba: Pointer to HBA context object. |
| 9274 | * @pring: Pointer to driver SLI ring object. |
| 9275 | * @tag: Buffer tag. |
| 9276 | * |
| 9277 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9278 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9279 | * iocb is posted to the response ring with the tag of the buffer. |
| 9280 | * This function searches the pring->postbufq list using the tag |
| 9281 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9282 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9283 | * buffer is returned to the caller else NULL is returned. |
| 9284 | * This function is called with no lock held. |
| 9285 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9286 | struct lpfc_dmabuf * |
| 9287 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9288 | uint32_t tag) |
| 9289 | { |
| 9290 | struct lpfc_dmabuf *mp, *next_mp; |
| 9291 | struct list_head *slp = &pring->postbufq; |
| 9292 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9293 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9294 | spin_lock_irq(&phba->hbalock); |
| 9295 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9296 | if (mp->buffer_tag == tag) { |
| 9297 | list_del_init(&mp->list); |
| 9298 | pring->postbufq_cnt--; |
| 9299 | spin_unlock_irq(&phba->hbalock); |
| 9300 | return mp; |
| 9301 | } |
| 9302 | } |
| 9303 | |
| 9304 | spin_unlock_irq(&phba->hbalock); |
| 9305 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9306 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9307 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9308 | pring->ringno, (unsigned long) tag, |
| 9309 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9310 | |
| 9311 | return NULL; |
| 9312 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9313 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9314 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9315 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9316 | * @phba: Pointer to HBA context object. |
| 9317 | * @pring: Pointer to driver SLI ring object. |
| 9318 | * @phys: DMA address of the buffer. |
| 9319 | * |
| 9320 | * This function searches the buffer list using the dma_address |
| 9321 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9322 | * corresponding to the dma_address. The function returns the |
| 9323 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9324 | * This function is called by the ct and els unsolicited event |
| 9325 | * handlers to get the buffer associated with the unsolicited |
| 9326 | * event. |
| 9327 | * |
| 9328 | * This function is called with no lock held. |
| 9329 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9330 | struct lpfc_dmabuf * |
| 9331 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9332 | dma_addr_t phys) |
| 9333 | { |
| 9334 | struct lpfc_dmabuf *mp, *next_mp; |
| 9335 | struct list_head *slp = &pring->postbufq; |
| 9336 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9337 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9338 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9339 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9340 | if (mp->phys == phys) { |
| 9341 | list_del_init(&mp->list); |
| 9342 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9343 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9344 | return mp; |
| 9345 | } |
| 9346 | } |
| 9347 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9348 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9349 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9350 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9351 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9352 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9353 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9354 | return NULL; |
| 9355 | } |
| 9356 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9357 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9358 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9359 | * @phba: Pointer to HBA context object. |
| 9360 | * @cmdiocb: Pointer to driver command iocb object. |
| 9361 | * @rspiocb: Pointer to driver response iocb object. |
| 9362 | * |
| 9363 | * This function is the completion handler for the abort iocbs for |
| 9364 | * ELS commands. This function is called from the ELS ring event |
| 9365 | * handler with no lock held. This function frees memory resources |
| 9366 | * associated with the abort iocb. |
| 9367 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9368 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9369 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9370 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9371 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9372 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9373 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9374 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9375 | |
| 9376 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9377 | |
| 9378 | /* |
| 9379 | * Assume that the port already completed and returned, or |
| 9380 | * will return the iocb. Just Log the message. |
| 9381 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9382 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9383 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9384 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9385 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9386 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9387 | if (abort_iotag != 0 && |
| 9388 | abort_iotag <= phba->sli.last_iotag) |
| 9389 | abort_iocb = |
| 9390 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9391 | } else |
| 9392 | /* For sli4 the abort_tag is the XRI, |
| 9393 | * so the abort routine puts the iotag of the iocb |
| 9394 | * being aborted in the context field of the abort |
| 9395 | * IOCB. |
| 9396 | */ |
| 9397 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9398 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9399 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9400 | "0327 Cannot abort els iocb %p " |
| 9401 | "with tag %x context %x, abort status %x, " |
| 9402 | "abort code %x\n", |
| 9403 | abort_iocb, abort_iotag, abort_context, |
| 9404 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9405 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9406 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9407 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9408 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9409 | return; |
| 9410 | } |
| 9411 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9412 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9413 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9414 | * @phba: Pointer to HBA context object. |
| 9415 | * @cmdiocb: Pointer to driver command iocb object. |
| 9416 | * @rspiocb: Pointer to driver response iocb object. |
| 9417 | * |
| 9418 | * The function is called from SLI ring event handler with no |
| 9419 | * lock held. This function is the completion handler for ELS commands |
| 9420 | * which are aborted. The function frees memory resources used for |
| 9421 | * the aborted ELS commands. |
| 9422 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9423 | static void |
| 9424 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9425 | struct lpfc_iocbq *rspiocb) |
| 9426 | { |
| 9427 | IOCB_t *irsp = &rspiocb->iocb; |
| 9428 | |
| 9429 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9430 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9431 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9432 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9433 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9434 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9435 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9436 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9437 | else |
| 9438 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9439 | return; |
| 9440 | } |
| 9441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9442 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9443 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9444 | * @phba: Pointer to HBA context object. |
| 9445 | * @pring: Pointer to driver SLI ring object. |
| 9446 | * @cmdiocb: Pointer to driver command iocb object. |
| 9447 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9448 | * This function issues an abort iocb for the provided command iocb down to |
| 9449 | * the port. Other than the case the outstanding command iocb is an abort |
| 9450 | * request, this function issues abort out unconditionally. This function is |
| 9451 | * called with hbalock held. The function returns 0 when it fails due to |
| 9452 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9453 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9454 | static int |
| 9455 | 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] | 9456 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9457 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9458 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9459 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9460 | IOCB_t *icmd = NULL; |
| 9461 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9462 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9463 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9464 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9465 | /* |
| 9466 | * There are certain command types we don't want to abort. And we |
| 9467 | * don't want to abort commands that are already in the process of |
| 9468 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9469 | */ |
| 9470 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9471 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9472 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9473 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9474 | return 0; |
| 9475 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9476 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9477 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9478 | if (abtsiocbp == NULL) |
| 9479 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9480 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9481 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9482 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9483 | */ |
| 9484 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9485 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9486 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9487 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9488 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9489 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9490 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9491 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9492 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9493 | else |
| 9494 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9495 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9496 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9497 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9498 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9499 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9500 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9501 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9502 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9503 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9504 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9505 | else |
| 9506 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9507 | |
| 9508 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9509 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9510 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9511 | "0339 Abort xri x%x, original iotag x%x, " |
| 9512 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9513 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9514 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9515 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9516 | |
| 9517 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9518 | /* Note: both hbalock and ring_lock need to be set here */ |
| 9519 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9520 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9521 | abtsiocbp, 0); |
| 9522 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 9523 | } else { |
| 9524 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9525 | abtsiocbp, 0); |
| 9526 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9527 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9528 | if (retval) |
| 9529 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9530 | |
| 9531 | /* |
| 9532 | * Caller to this routine should check for IOCB_ERROR |
| 9533 | * and handle it properly. This routine no longer removes |
| 9534 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9535 | */ |
| 9536 | return retval; |
| 9537 | } |
| 9538 | |
| 9539 | /** |
| 9540 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9541 | * @phba: Pointer to HBA context object. |
| 9542 | * @pring: Pointer to driver SLI ring object. |
| 9543 | * @cmdiocb: Pointer to driver command iocb object. |
| 9544 | * |
| 9545 | * This function issues an abort iocb for the provided command iocb. In case |
| 9546 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9547 | * ring. Instead, the callback function shall be changed to those commands |
| 9548 | * so that nothing happens when them finishes. This function is called with |
| 9549 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9550 | * request. |
| 9551 | **/ |
| 9552 | int |
| 9553 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9554 | struct lpfc_iocbq *cmdiocb) |
| 9555 | { |
| 9556 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9557 | int retval = IOCB_ERROR; |
| 9558 | IOCB_t *icmd = NULL; |
| 9559 | |
| 9560 | /* |
| 9561 | * There are certain command types we don't want to abort. And we |
| 9562 | * don't want to abort commands that are already in the process of |
| 9563 | * being aborted. |
| 9564 | */ |
| 9565 | icmd = &cmdiocb->iocb; |
| 9566 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 9567 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9568 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 9569 | return 0; |
| 9570 | |
| 9571 | /* |
| 9572 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 9573 | * the callback so that nothing happens when it finishes. |
| 9574 | */ |
| 9575 | if ((vport->load_flag & FC_UNLOADING) && |
| 9576 | (pring->ringno == LPFC_ELS_RING)) { |
| 9577 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 9578 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9579 | else |
| 9580 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9581 | goto abort_iotag_exit; |
| 9582 | } |
| 9583 | |
| 9584 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 9585 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 9586 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9587 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9588 | /* |
| 9589 | * Caller to this routine should check for IOCB_ERROR |
| 9590 | * and handle it properly. This routine no longer removes |
| 9591 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9592 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9593 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9594 | } |
| 9595 | |
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 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring |
| 9598 | * @phba: Pointer to HBA context object. |
| 9599 | * @pring: Pointer to driver SLI ring object. |
| 9600 | * |
| 9601 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 9602 | * objects in txq. This function issues abort iocbs unconditionally for all |
| 9603 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed |
| 9604 | * to complete before the return of this function. The caller is not required |
| 9605 | * to hold any locks. |
| 9606 | **/ |
| 9607 | static void |
| 9608 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 9609 | { |
| 9610 | LIST_HEAD(completions); |
| 9611 | struct lpfc_iocbq *iocb, *next_iocb; |
| 9612 | |
| 9613 | if (pring->ringno == LPFC_ELS_RING) |
| 9614 | lpfc_fabric_abort_hba(phba); |
| 9615 | |
| 9616 | spin_lock_irq(&phba->hbalock); |
| 9617 | |
| 9618 | /* Take off all the iocbs on txq for cancelling */ |
| 9619 | list_splice_init(&pring->txq, &completions); |
| 9620 | pring->txq_cnt = 0; |
| 9621 | |
| 9622 | /* Next issue ABTS for everything on the txcmplq */ |
| 9623 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 9624 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); |
| 9625 | |
| 9626 | spin_unlock_irq(&phba->hbalock); |
| 9627 | |
| 9628 | /* Cancel all the IOCBs from the completions list */ |
| 9629 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9630 | IOERR_SLI_ABORTED); |
| 9631 | } |
| 9632 | |
| 9633 | /** |
| 9634 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 9635 | * @phba: pointer to lpfc HBA data structure. |
| 9636 | * |
| 9637 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 9638 | **/ |
| 9639 | void |
| 9640 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 9641 | { |
| 9642 | struct lpfc_sli *psli = &phba->sli; |
| 9643 | struct lpfc_sli_ring *pring; |
| 9644 | int i; |
| 9645 | |
| 9646 | for (i = 0; i < psli->num_rings; i++) { |
| 9647 | pring = &psli->ring[i]; |
| 9648 | lpfc_sli_iocb_ring_abort(phba, pring); |
| 9649 | } |
| 9650 | } |
| 9651 | |
| 9652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9653 | * 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] | 9654 | * @iocbq: Pointer to driver iocb object. |
| 9655 | * @vport: Pointer to driver virtual port object. |
| 9656 | * @tgt_id: SCSI ID of the target. |
| 9657 | * @lun_id: LUN ID of the scsi device. |
| 9658 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 9659 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9660 | * 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] | 9661 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 9662 | * 0 if the filtering criteria is met for the given iocb and will return |
| 9663 | * 1 if the filtering criteria is not met. |
| 9664 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 9665 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 9666 | * lun_id parameter. |
| 9667 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 9668 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 9669 | * parameters. |
| 9670 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 9671 | * given iocb is for the SCSI host associated with the given vport. |
| 9672 | * This function is called with no locks held. |
| 9673 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9674 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9675 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 9676 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9677 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9678 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9679 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9680 | int rc = 1; |
| 9681 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9682 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 9683 | return rc; |
| 9684 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9685 | if (iocbq->vport != vport) |
| 9686 | return rc; |
| 9687 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9688 | 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] | 9689 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9690 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9691 | return rc; |
| 9692 | |
| 9693 | switch (ctx_cmd) { |
| 9694 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9695 | if ((lpfc_cmd->rdata->pnode) && |
| 9696 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 9697 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9698 | rc = 0; |
| 9699 | break; |
| 9700 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9701 | if ((lpfc_cmd->rdata->pnode) && |
| 9702 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9703 | rc = 0; |
| 9704 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9705 | case LPFC_CTX_HOST: |
| 9706 | rc = 0; |
| 9707 | break; |
| 9708 | default: |
| 9709 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 9710 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9711 | break; |
| 9712 | } |
| 9713 | |
| 9714 | return rc; |
| 9715 | } |
| 9716 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9717 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9718 | * 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] | 9719 | * @vport: Pointer to virtual port. |
| 9720 | * @tgt_id: SCSI ID of the target. |
| 9721 | * @lun_id: LUN ID of the scsi device. |
| 9722 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9723 | * |
| 9724 | * This function returns number of FCP commands pending for the vport. |
| 9725 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 9726 | * commands pending on the vport associated with SCSI device specified |
| 9727 | * by tgt_id and lun_id parameters. |
| 9728 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 9729 | * commands pending on the vport associated with SCSI target specified |
| 9730 | * by tgt_id parameter. |
| 9731 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 9732 | * commands pending on the vport. |
| 9733 | * This function returns the number of iocbs which satisfy the filter. |
| 9734 | * This function is called without any lock held. |
| 9735 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9736 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9737 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 9738 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9739 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9740 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9741 | struct lpfc_iocbq *iocbq; |
| 9742 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9743 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9744 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 9745 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9746 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9747 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 9748 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9749 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9750 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9751 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9752 | return sum; |
| 9753 | } |
| 9754 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9755 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9756 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9757 | * @phba: Pointer to HBA context object |
| 9758 | * @cmdiocb: Pointer to command iocb object. |
| 9759 | * @rspiocb: Pointer to response iocb object. |
| 9760 | * |
| 9761 | * This function is called when an aborted FCP iocb completes. This |
| 9762 | * function is called by the ring event handler with no lock held. |
| 9763 | * This function frees the iocb. |
| 9764 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9765 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9766 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9767 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9768 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9769 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9770 | "3096 ABORT_XRI_CN completing on xri x%x " |
| 9771 | "original iotag x%x, abort cmd iotag x%x " |
| 9772 | "status 0x%x, reason 0x%x\n", |
| 9773 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 9774 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 9775 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 9776 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9777 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9778 | return; |
| 9779 | } |
| 9780 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9781 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9782 | * 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] | 9783 | * @vport: Pointer to virtual port. |
| 9784 | * @pring: Pointer to driver SLI ring object. |
| 9785 | * @tgt_id: SCSI ID of the target. |
| 9786 | * @lun_id: LUN ID of the scsi device. |
| 9787 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9788 | * |
| 9789 | * This function sends an abort command for every SCSI command |
| 9790 | * associated with the given virtual port pending on the ring |
| 9791 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 9792 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 9793 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 9794 | * parameters |
| 9795 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 9796 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 9797 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 9798 | * FCP iocbs associated with virtual port. |
| 9799 | * This function returns number of iocbs it failed to abort. |
| 9800 | * This function is called with no locks held. |
| 9801 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9802 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9803 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 9804 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9805 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9806 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9807 | struct lpfc_iocbq *iocbq; |
| 9808 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9809 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9810 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9811 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9812 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9813 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 9814 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9815 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9816 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9817 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9818 | continue; |
| 9819 | |
| 9820 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9821 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9822 | if (abtsiocb == NULL) { |
| 9823 | errcnt++; |
| 9824 | continue; |
| 9825 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9826 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9827 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9828 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9829 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9830 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9831 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 9832 | else |
| 9833 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9834 | abtsiocb->iocb.ulpLe = 1; |
| 9835 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9836 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9837 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9838 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9839 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9840 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 9841 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9842 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9843 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9844 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 9845 | else |
| 9846 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 9847 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9848 | /* Setup callback routine and issue the command. */ |
| 9849 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9850 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9851 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9852 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9853 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9854 | errcnt++; |
| 9855 | continue; |
| 9856 | } |
| 9857 | } |
| 9858 | |
| 9859 | return errcnt; |
| 9860 | } |
| 9861 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9862 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9863 | * 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] | 9864 | * @phba: Pointer to HBA context object. |
| 9865 | * @cmdiocbq: Pointer to command iocb. |
| 9866 | * @rspiocbq: Pointer to response iocb. |
| 9867 | * |
| 9868 | * This function is the completion handler for iocbs issued using |
| 9869 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 9870 | * ring event handler function without any lock held. This function |
| 9871 | * can be called from both worker thread context and interrupt |
| 9872 | * context. This function also can be called from other thread which |
| 9873 | * cleans up the SLI layer objects. |
| 9874 | * This function copy the contents of the response iocb to the |
| 9875 | * response iocb memory object provided by the caller of |
| 9876 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 9877 | * sleeps for the iocb completion. |
| 9878 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9879 | static void |
| 9880 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 9881 | struct lpfc_iocbq *cmdiocbq, |
| 9882 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9883 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9884 | wait_queue_head_t *pdone_q; |
| 9885 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9886 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9887 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9888 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9889 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 9890 | if (cmdiocbq->context2 && rspiocbq) |
| 9891 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 9892 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 9893 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9894 | /* Set the exchange busy flag for task management commands */ |
| 9895 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 9896 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 9897 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 9898 | cur_iocbq); |
| 9899 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 9900 | } |
| 9901 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9902 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9903 | if (pdone_q) |
| 9904 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9905 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9906 | return; |
| 9907 | } |
| 9908 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9909 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9910 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 9911 | * @phba: Pointer to HBA context object.. |
| 9912 | * @piocbq: Pointer to command iocb. |
| 9913 | * @flag: Flag to test. |
| 9914 | * |
| 9915 | * This routine grabs the hbalock and then test the iocb_flag to |
| 9916 | * see if the passed in flag is set. |
| 9917 | * Returns: |
| 9918 | * 1 if flag is set. |
| 9919 | * 0 if flag is not set. |
| 9920 | **/ |
| 9921 | static int |
| 9922 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 9923 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 9924 | { |
| 9925 | unsigned long iflags; |
| 9926 | int ret; |
| 9927 | |
| 9928 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9929 | ret = piocbq->iocb_flag & flag; |
| 9930 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9931 | return ret; |
| 9932 | |
| 9933 | } |
| 9934 | |
| 9935 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9936 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9937 | * @phba: Pointer to HBA context object.. |
| 9938 | * @pring: Pointer to sli ring. |
| 9939 | * @piocb: Pointer to command iocb. |
| 9940 | * @prspiocbq: Pointer to response iocb. |
| 9941 | * @timeout: Timeout in number of seconds. |
| 9942 | * |
| 9943 | * This function issues the iocb to firmware and waits for the |
| 9944 | * iocb to complete. If the iocb command is not |
| 9945 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 9946 | * Caller should not free the iocb resources if this function |
| 9947 | * returns IOCB_TIMEDOUT. |
| 9948 | * The function waits for the iocb completion using an |
| 9949 | * non-interruptible wait. |
| 9950 | * This function will sleep while waiting for iocb completion. |
| 9951 | * So, this function should not be called from any context which |
| 9952 | * does not allow sleeping. Due to the same reason, this function |
| 9953 | * cannot be called with interrupt disabled. |
| 9954 | * This function assumes that the iocb completions occur while |
| 9955 | * this function sleep. So, this function cannot be called from |
| 9956 | * the thread which process iocb completion for this ring. |
| 9957 | * This function clears the iocb_flag of the iocb object before |
| 9958 | * issuing the iocb and the iocb completion handler sets this |
| 9959 | * flag and wakes this thread when the iocb completes. |
| 9960 | * The contents of the response iocb will be copied to prspiocbq |
| 9961 | * by the completion handler when the command completes. |
| 9962 | * This function returns IOCB_SUCCESS when success. |
| 9963 | * This function is called with no lock held. |
| 9964 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9965 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9966 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9967 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9968 | struct lpfc_iocbq *piocb, |
| 9969 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9970 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9971 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9972 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9973 | long timeleft, timeout_req = 0; |
| 9974 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9975 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9976 | struct lpfc_iocbq *iocb; |
| 9977 | int txq_cnt = 0; |
| 9978 | int txcmplq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9979 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9980 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9981 | * If the caller has provided a response iocbq buffer, then context2 |
| 9982 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9983 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9984 | if (prspiocbq) { |
| 9985 | if (piocb->context2) |
| 9986 | return IOCB_ERROR; |
| 9987 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9988 | } |
| 9989 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9990 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 9991 | piocb->context_un.wait_queue = &done_q; |
| 9992 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9993 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9994 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9995 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9996 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9997 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 9998 | writel(creg_val, phba->HCregaddr); |
| 9999 | readl(phba->HCregaddr); /* flush */ |
| 10000 | } |
| 10001 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10002 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 10003 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10004 | if (retval == IOCB_SUCCESS) { |
| 10005 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10006 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10007 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10008 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10009 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10010 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 10011 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10012 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10013 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10014 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10015 | "0338 IOCB wait timeout error - no " |
| 10016 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10017 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10018 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10019 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10020 | "0330 IOCB wake NOT set, " |
| 10021 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10022 | timeout, (timeleft / jiffies)); |
| 10023 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10024 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10025 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10026 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 10027 | list_for_each_entry(iocb, &pring->txq, list) { |
| 10028 | txq_cnt++; |
| 10029 | } |
| 10030 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 10031 | txcmplq_cnt++; |
| 10032 | } |
| 10033 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10034 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 10035 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 10036 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10037 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10038 | } else { |
| 10039 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10040 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10041 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10042 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10043 | } |
| 10044 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10045 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10046 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10047 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10048 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 10049 | writel(creg_val, phba->HCregaddr); |
| 10050 | readl(phba->HCregaddr); /* flush */ |
| 10051 | } |
| 10052 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10053 | if (prspiocbq) |
| 10054 | piocb->context2 = NULL; |
| 10055 | |
| 10056 | piocb->context_un.wait_queue = NULL; |
| 10057 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10058 | return retval; |
| 10059 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10060 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10061 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10062 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10063 | * @phba: Pointer to HBA context object. |
| 10064 | * @pmboxq: Pointer to driver mailbox object. |
| 10065 | * @timeout: Timeout in number of seconds. |
| 10066 | * |
| 10067 | * This function issues the mailbox to firmware and waits for the |
| 10068 | * mailbox command to complete. If the mailbox command is not |
| 10069 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 10070 | * The function waits for the mailbox completion using an |
| 10071 | * interruptible wait. If the thread is woken up due to a |
| 10072 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 10073 | * should not free the mailbox resources, if this function returns |
| 10074 | * MBX_TIMEOUT. |
| 10075 | * This function will sleep while waiting for mailbox completion. |
| 10076 | * So, this function should not be called from any context which |
| 10077 | * does not allow sleeping. Due to the same reason, this function |
| 10078 | * cannot be called with interrupt disabled. |
| 10079 | * This function assumes that the mailbox completion occurs while |
| 10080 | * this function sleep. So, this function cannot be called from |
| 10081 | * the worker thread which processes mailbox completion. |
| 10082 | * This function is called in the context of HBA management |
| 10083 | * applications. |
| 10084 | * This function returns MBX_SUCCESS when successful. |
| 10085 | * This function is called with no lock held. |
| 10086 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10087 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10088 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10089 | uint32_t timeout) |
| 10090 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10091 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10092 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10093 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10094 | |
| 10095 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10096 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10097 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10098 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10099 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10100 | /* setup wake call as IOCB callback */ |
| 10101 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 10102 | /* setup context field to pass wait_queue pointer to wake function */ |
| 10103 | pmboxq->context1 = &done_q; |
| 10104 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10105 | /* now issue the command */ |
| 10106 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10107 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10108 | wait_event_interruptible_timeout(done_q, |
| 10109 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 10110 | timeout * HZ); |
| 10111 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10112 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10113 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10114 | /* |
| 10115 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10116 | * else do not free the resources. |
| 10117 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10118 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10119 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10120 | lpfc_sli4_swap_str(phba, pmboxq); |
| 10121 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10122 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10123 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10124 | } |
| 10125 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10126 | } |
| 10127 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10128 | return retval; |
| 10129 | } |
| 10130 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10131 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10132 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10133 | * @phba: Pointer to HBA context. |
| 10134 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10135 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10136 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10137 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10138 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10139 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10140 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10141 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10142 | * as with offline or HBA function reset), this routine will wait for the |
| 10143 | * outstanding mailbox command to complete before invoking the mailbox |
| 10144 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10145 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10146 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10147 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10148 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10149 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10150 | unsigned long timeout; |
| 10151 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10152 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10153 | /* delay 100ms for port state */ |
| 10154 | msleep(100); |
| 10155 | lpfc_sli_mbox_sys_flush(phba); |
| 10156 | return; |
| 10157 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10158 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10159 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10160 | spin_lock_irq(&phba->hbalock); |
| 10161 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10162 | |
| 10163 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10164 | /* Determine how long we might wait for the active mailbox |
| 10165 | * command to be gracefully completed by firmware. |
| 10166 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10167 | if (phba->sli.mbox_active) |
| 10168 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10169 | phba->sli.mbox_active) * |
| 10170 | 1000) + jiffies; |
| 10171 | spin_unlock_irq(&phba->hbalock); |
| 10172 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10173 | while (phba->sli.mbox_active) { |
| 10174 | /* Check active mailbox complete status every 2ms */ |
| 10175 | msleep(2); |
| 10176 | if (time_after(jiffies, timeout)) |
| 10177 | /* Timeout, let the mailbox flush routine to |
| 10178 | * forcefully release active mailbox command |
| 10179 | */ |
| 10180 | break; |
| 10181 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10182 | } else |
| 10183 | spin_unlock_irq(&phba->hbalock); |
| 10184 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10185 | lpfc_sli_mbox_sys_flush(phba); |
| 10186 | } |
| 10187 | |
| 10188 | /** |
| 10189 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10190 | * @phba: Pointer to HBA context. |
| 10191 | * |
| 10192 | * This function is called to read the SLI3 device error attention registers |
| 10193 | * for possible error attention events. The caller must hold the hostlock |
| 10194 | * with spin_lock_irq(). |
| 10195 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10196 | * 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] | 10197 | * Register and returns 0 otherwise. |
| 10198 | **/ |
| 10199 | static int |
| 10200 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10201 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10202 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10203 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10204 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10205 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10206 | goto unplug_err; |
| 10207 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10208 | if (ha_copy & HA_ERATT) { |
| 10209 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10210 | if (lpfc_sli_read_hs(phba)) |
| 10211 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10212 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10213 | /* Check if there is a deferred error condition is active */ |
| 10214 | if ((HS_FFER1 & phba->work_hs) && |
| 10215 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10216 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10217 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10218 | /* Clear all interrupt enable conditions */ |
| 10219 | writel(0, phba->HCregaddr); |
| 10220 | readl(phba->HCregaddr); |
| 10221 | } |
| 10222 | |
| 10223 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10224 | phba->work_ha |= HA_ERATT; |
| 10225 | /* Indicate polling handles this ERATT */ |
| 10226 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10227 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10228 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10229 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10230 | |
| 10231 | unplug_err: |
| 10232 | /* Set the driver HS work bitmap */ |
| 10233 | phba->work_hs |= UNPLUG_ERR; |
| 10234 | /* Set the driver HA work bitmap */ |
| 10235 | phba->work_ha |= HA_ERATT; |
| 10236 | /* Indicate polling handles this ERATT */ |
| 10237 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10238 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10239 | } |
| 10240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10241 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10242 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10243 | * @phba: Pointer to HBA context. |
| 10244 | * |
| 10245 | * This function is called to read the SLI4 device error attention registers |
| 10246 | * for possible error attention events. The caller must hold the hostlock |
| 10247 | * with spin_lock_irq(). |
| 10248 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10249 | * 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] | 10250 | * Register and returns 0 otherwise. |
| 10251 | **/ |
| 10252 | static int |
| 10253 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10254 | { |
| 10255 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10256 | uint32_t if_type, portsmphr; |
| 10257 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10258 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10259 | /* |
| 10260 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10261 | * registers for error attention. This can be changed later. |
| 10262 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10263 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10264 | switch (if_type) { |
| 10265 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10266 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10267 | &uerr_sta_lo) || |
| 10268 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10269 | &uerr_sta_hi)) { |
| 10270 | phba->work_hs |= UNPLUG_ERR; |
| 10271 | phba->work_ha |= HA_ERATT; |
| 10272 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10273 | return 1; |
| 10274 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10275 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10276 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10277 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10278 | "1423 HBA Unrecoverable error: " |
| 10279 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10280 | "ue_mask_lo_reg=0x%x, " |
| 10281 | "ue_mask_hi_reg=0x%x\n", |
| 10282 | uerr_sta_lo, uerr_sta_hi, |
| 10283 | phba->sli4_hba.ue_mask_lo, |
| 10284 | phba->sli4_hba.ue_mask_hi); |
| 10285 | phba->work_status[0] = uerr_sta_lo; |
| 10286 | phba->work_status[1] = uerr_sta_hi; |
| 10287 | phba->work_ha |= HA_ERATT; |
| 10288 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10289 | return 1; |
| 10290 | } |
| 10291 | break; |
| 10292 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10293 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10294 | &portstat_reg.word0) || |
| 10295 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10296 | &portsmphr)){ |
| 10297 | phba->work_hs |= UNPLUG_ERR; |
| 10298 | phba->work_ha |= HA_ERATT; |
| 10299 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10300 | return 1; |
| 10301 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10302 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10303 | phba->work_status[0] = |
| 10304 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10305 | phba->work_status[1] = |
| 10306 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10307 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10308 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10309 | "port status reg 0x%x, " |
| 10310 | "port smphr reg 0x%x, " |
| 10311 | "error 1=0x%x, error 2=0x%x\n", |
| 10312 | portstat_reg.word0, |
| 10313 | portsmphr, |
| 10314 | phba->work_status[0], |
| 10315 | phba->work_status[1]); |
| 10316 | phba->work_ha |= HA_ERATT; |
| 10317 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10318 | return 1; |
| 10319 | } |
| 10320 | break; |
| 10321 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10322 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10324 | "2886 HBA Error Attention on unsupported " |
| 10325 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10326 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10327 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10328 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10329 | return 0; |
| 10330 | } |
| 10331 | |
| 10332 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10333 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -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 from timer soft interrupt context to check HBA's |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10337 | * error attention register bit for error attention events. |
| 10338 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10339 | * 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] | 10340 | * Register and returns 0 otherwise. |
| 10341 | **/ |
| 10342 | int |
| 10343 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10344 | { |
| 10345 | uint32_t ha_copy; |
| 10346 | |
| 10347 | /* If somebody is waiting to handle an eratt, don't process it |
| 10348 | * here. The brdkill function will do this. |
| 10349 | */ |
| 10350 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10351 | return 0; |
| 10352 | |
| 10353 | /* Check if interrupt handler handles this ERATT */ |
| 10354 | spin_lock_irq(&phba->hbalock); |
| 10355 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10356 | /* Interrupt handler has handled ERATT */ |
| 10357 | spin_unlock_irq(&phba->hbalock); |
| 10358 | return 0; |
| 10359 | } |
| 10360 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10361 | /* |
| 10362 | * If there is deferred error attention, do not check for error |
| 10363 | * attention |
| 10364 | */ |
| 10365 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10366 | spin_unlock_irq(&phba->hbalock); |
| 10367 | return 0; |
| 10368 | } |
| 10369 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10370 | /* If PCI channel is offline, don't process it */ |
| 10371 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10372 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10373 | return 0; |
| 10374 | } |
| 10375 | |
| 10376 | switch (phba->sli_rev) { |
| 10377 | case LPFC_SLI_REV2: |
| 10378 | case LPFC_SLI_REV3: |
| 10379 | /* Read chip Host Attention (HA) register */ |
| 10380 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10381 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10382 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10383 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10384 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10385 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10386 | default: |
| 10387 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10388 | "0299 Invalid SLI revision (%d)\n", |
| 10389 | phba->sli_rev); |
| 10390 | ha_copy = 0; |
| 10391 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10392 | } |
| 10393 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10394 | |
| 10395 | return ha_copy; |
| 10396 | } |
| 10397 | |
| 10398 | /** |
| 10399 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10400 | * @phba: Pointer to HBA context. |
| 10401 | * |
| 10402 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10403 | * that the interrupt should be handled. |
| 10404 | * |
| 10405 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10406 | * interrupt should be handled, otherwise -EIO. |
| 10407 | */ |
| 10408 | static inline int |
| 10409 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10410 | { |
| 10411 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10412 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10413 | return -EIO; |
| 10414 | |
| 10415 | /* Update device level interrupt statistics */ |
| 10416 | phba->sli.slistat.sli_intr++; |
| 10417 | |
| 10418 | /* Ignore all interrupts during initialization. */ |
| 10419 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 10420 | return -EIO; |
| 10421 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10422 | return 0; |
| 10423 | } |
| 10424 | |
| 10425 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10426 | * 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] | 10427 | * @irq: Interrupt number. |
| 10428 | * @dev_id: The device context pointer. |
| 10429 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10430 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10431 | * service routine when device with SLI-3 interface spec is enabled with |
| 10432 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 10433 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 10434 | * interrupt mode, this function is called as part of the device-level |
| 10435 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 10436 | * is undergoing initialization, the interrupt handler will not process |
| 10437 | * the interrupt. The link attention and ELS ring attention events are |
| 10438 | * handled by the worker thread. The interrupt handler signals the worker |
| 10439 | * thread and returns for these events. This function is called without |
| 10440 | * 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] | 10441 | * structures. |
| 10442 | * |
| 10443 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10444 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10445 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10446 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10447 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10448 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10449 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10450 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10451 | uint32_t work_ha_copy; |
| 10452 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10453 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10454 | uint32_t control; |
| 10455 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10456 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10457 | struct lpfc_vport *vport; |
| 10458 | struct lpfc_nodelist *ndlp; |
| 10459 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10460 | LPFC_MBOXQ_t *pmb; |
| 10461 | int rc; |
| 10462 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10463 | /* |
| 10464 | * Get the driver's phba structure from the dev_id and |
| 10465 | * assume the HBA is not interrupting. |
| 10466 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10467 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10468 | |
| 10469 | if (unlikely(!phba)) |
| 10470 | return IRQ_NONE; |
| 10471 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10472 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10473 | * Stuff needs to be attented to when this function is invoked as an |
| 10474 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10475 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10476 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10477 | /* Check device state for handling interrupt */ |
| 10478 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10479 | return IRQ_NONE; |
| 10480 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10481 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10482 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10483 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10484 | /* If somebody is waiting to handle an eratt don't process it |
| 10485 | * here. The brdkill function will do this. |
| 10486 | */ |
| 10487 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10488 | ha_copy &= ~HA_ERATT; |
| 10489 | /* Check the need for handling ERATT in interrupt handler */ |
| 10490 | if (ha_copy & HA_ERATT) { |
| 10491 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10492 | /* ERATT polling has handled ERATT */ |
| 10493 | ha_copy &= ~HA_ERATT; |
| 10494 | else |
| 10495 | /* Indicate interrupt handler handles ERATT */ |
| 10496 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10497 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10498 | |
| 10499 | /* |
| 10500 | * If there is deferred error attention, do not check for any |
| 10501 | * interrupt. |
| 10502 | */ |
| 10503 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10504 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10505 | return IRQ_NONE; |
| 10506 | } |
| 10507 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10508 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10509 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 10510 | goto unplug_error; |
| 10511 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10512 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 10513 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10514 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10515 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 10516 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10517 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10518 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10519 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10520 | } else |
| 10521 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10522 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10523 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 10524 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10525 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10526 | if (work_ha_copy & HA_LATT) { |
| 10527 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 10528 | /* |
| 10529 | * Turn off Link Attention interrupts |
| 10530 | * until CLEAR_LA done |
| 10531 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10532 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10533 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10534 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10535 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10536 | control &= ~HC_LAINT_ENA; |
| 10537 | writel(control, phba->HCregaddr); |
| 10538 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10539 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10540 | } |
| 10541 | else |
| 10542 | work_ha_copy &= ~HA_LATT; |
| 10543 | } |
| 10544 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10545 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10546 | /* |
| 10547 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 10548 | * the only slow ring. |
| 10549 | */ |
| 10550 | status = (work_ha_copy & |
| 10551 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10552 | status >>= (4*LPFC_ELS_RING); |
| 10553 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10554 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10555 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10556 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10557 | |
| 10558 | lpfc_debugfs_slow_ring_trc(phba, |
| 10559 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 10560 | control, status, |
| 10561 | (uint32_t)phba->sli.slistat.sli_intr); |
| 10562 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10563 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10564 | lpfc_debugfs_slow_ring_trc(phba, |
| 10565 | "ISR Disable ring:" |
| 10566 | "pwork:x%x hawork:x%x wait:x%x", |
| 10567 | phba->work_ha, work_ha_copy, |
| 10568 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10569 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10570 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10571 | control &= |
| 10572 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10573 | writel(control, phba->HCregaddr); |
| 10574 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10575 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10576 | else { |
| 10577 | lpfc_debugfs_slow_ring_trc(phba, |
| 10578 | "ISR slow ring: pwork:" |
| 10579 | "x%x hawork:x%x wait:x%x", |
| 10580 | phba->work_ha, work_ha_copy, |
| 10581 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10582 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10583 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10584 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10585 | } |
| 10586 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10587 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10588 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10589 | if (lpfc_sli_read_hs(phba)) |
| 10590 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10591 | /* |
| 10592 | * Check if there is a deferred error condition |
| 10593 | * is active |
| 10594 | */ |
| 10595 | if ((HS_FFER1 & phba->work_hs) && |
| 10596 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10597 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 10598 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10599 | phba->hba_flag |= DEFER_ERATT; |
| 10600 | /* Clear all interrupt enable conditions */ |
| 10601 | writel(0, phba->HCregaddr); |
| 10602 | readl(phba->HCregaddr); |
| 10603 | } |
| 10604 | } |
| 10605 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10606 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10607 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10608 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10609 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10610 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10611 | |
| 10612 | /* First check out the status word */ |
| 10613 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 10614 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10615 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10616 | /* |
| 10617 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 10618 | * mbxStatus <status> |
| 10619 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10620 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10621 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10622 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10623 | "Interrupt mbxCommand x%x " |
| 10624 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10625 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10626 | pmbox->mbxCommand, |
| 10627 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10628 | /* clear mailbox attention bit */ |
| 10629 | work_ha_copy &= ~HA_MBATT; |
| 10630 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10631 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10632 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10633 | phba->last_completion_time = jiffies; |
| 10634 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10635 | if (pmb->mbox_cmpl) { |
| 10636 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 10637 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 10638 | if (pmb->out_ext_byte_len && |
| 10639 | pmb->context2) |
| 10640 | lpfc_sli_pcimem_bcopy( |
| 10641 | phba->mbox_ext, |
| 10642 | pmb->context2, |
| 10643 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10644 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10645 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10646 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10647 | |
| 10648 | lpfc_debugfs_disc_trc(vport, |
| 10649 | LPFC_DISC_TRC_MBOX_VPORT, |
| 10650 | "MBOX dflt rpi: : " |
| 10651 | "status:x%x rpi:x%x", |
| 10652 | (uint32_t)pmbox->mbxStatus, |
| 10653 | pmbox->un.varWords[0], 0); |
| 10654 | |
| 10655 | if (!pmbox->mbxStatus) { |
| 10656 | mp = (struct lpfc_dmabuf *) |
| 10657 | (pmb->context1); |
| 10658 | ndlp = (struct lpfc_nodelist *) |
| 10659 | pmb->context2; |
| 10660 | |
| 10661 | /* Reg_LOGIN of dflt RPI was |
| 10662 | * successful. new lets get |
| 10663 | * rid of the RPI using the |
| 10664 | * same mbox buffer. |
| 10665 | */ |
| 10666 | lpfc_unreg_login(phba, |
| 10667 | vport->vpi, |
| 10668 | pmbox->un.varWords[0], |
| 10669 | pmb); |
| 10670 | pmb->mbox_cmpl = |
| 10671 | lpfc_mbx_cmpl_dflt_rpi; |
| 10672 | pmb->context1 = mp; |
| 10673 | pmb->context2 = ndlp; |
| 10674 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10675 | rc = lpfc_sli_issue_mbox(phba, |
| 10676 | pmb, |
| 10677 | MBX_NOWAIT); |
| 10678 | if (rc != MBX_BUSY) |
| 10679 | lpfc_printf_log(phba, |
| 10680 | KERN_ERR, |
| 10681 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10682 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10683 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10684 | if (rc != MBX_NOT_FINISHED) |
| 10685 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10686 | } |
| 10687 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10688 | spin_lock_irqsave( |
| 10689 | &phba->pport->work_port_lock, |
| 10690 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10691 | phba->pport->work_port_events &= |
| 10692 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10693 | spin_unlock_irqrestore( |
| 10694 | &phba->pport->work_port_lock, |
| 10695 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10696 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10697 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10698 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10699 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10700 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10701 | if ((work_ha_copy & HA_MBATT) && |
| 10702 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10703 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10704 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10705 | do { |
| 10706 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 10707 | MBX_NOWAIT); |
| 10708 | } while (rc == MBX_NOT_FINISHED); |
| 10709 | if (rc != MBX_SUCCESS) |
| 10710 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10711 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10712 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10713 | } |
| 10714 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10715 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10716 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10717 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10718 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10719 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10720 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10721 | unplug_error: |
| 10722 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10723 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10724 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10725 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10726 | |
| 10727 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10728 | * 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] | 10729 | * @irq: Interrupt number. |
| 10730 | * @dev_id: The device context pointer. |
| 10731 | * |
| 10732 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10733 | * service routine when device with SLI-3 interface spec is enabled with |
| 10734 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 10735 | * ring event in the HBA. However, when the device is enabled with either |
| 10736 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 10737 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 10738 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 10739 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 10740 | * the intrrupt context. This function is called without any lock held. |
| 10741 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10742 | * |
| 10743 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10744 | * returns IRQ_NONE. |
| 10745 | **/ |
| 10746 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10747 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10748 | { |
| 10749 | struct lpfc_hba *phba; |
| 10750 | uint32_t ha_copy; |
| 10751 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10752 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10753 | |
| 10754 | /* Get the driver's phba structure from the dev_id and |
| 10755 | * assume the HBA is not interrupting. |
| 10756 | */ |
| 10757 | phba = (struct lpfc_hba *) dev_id; |
| 10758 | |
| 10759 | if (unlikely(!phba)) |
| 10760 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10761 | |
| 10762 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10763 | * Stuff needs to be attented to when this function is invoked as an |
| 10764 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10765 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10766 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10767 | /* Check device state for handling interrupt */ |
| 10768 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10769 | return IRQ_NONE; |
| 10770 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10771 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10772 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10773 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10774 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10775 | /* |
| 10776 | * If there is deferred error attention, do not check for |
| 10777 | * any interrupt. |
| 10778 | */ |
| 10779 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10780 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10781 | return IRQ_NONE; |
| 10782 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10783 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 10784 | phba->HAregaddr); |
| 10785 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10786 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10787 | } else |
| 10788 | ha_copy = phba->ha_copy; |
| 10789 | |
| 10790 | /* |
| 10791 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 10792 | */ |
| 10793 | ha_copy &= ~(phba->work_ha_mask); |
| 10794 | |
| 10795 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10796 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10797 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10798 | lpfc_sli_handle_fast_ring_event(phba, |
| 10799 | &phba->sli.ring[LPFC_FCP_RING], |
| 10800 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10801 | |
| 10802 | if (phba->cfg_multi_ring_support == 2) { |
| 10803 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10804 | * Process all events on extra ring. Take the optimized path |
| 10805 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10806 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10807 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10808 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10809 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10810 | lpfc_sli_handle_fast_ring_event(phba, |
| 10811 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 10812 | status); |
| 10813 | } |
| 10814 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10815 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10816 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10817 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10818 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10819 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10820 | * @irq: Interrupt number. |
| 10821 | * @dev_id: The device context pointer. |
| 10822 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10823 | * This function is the HBA device-level interrupt handler to device with |
| 10824 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 10825 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 10826 | * requires driver attention. This function invokes the slow-path interrupt |
| 10827 | * attention handling function and fast-path interrupt attention handling |
| 10828 | * function in turn to process the relevant HBA attention events. This |
| 10829 | * function is called without any lock held. It gets the hbalock to access |
| 10830 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10831 | * |
| 10832 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 10833 | * returns IRQ_NONE. |
| 10834 | **/ |
| 10835 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10836 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10837 | { |
| 10838 | struct lpfc_hba *phba; |
| 10839 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 10840 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10841 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10842 | |
| 10843 | /* |
| 10844 | * Get the driver's phba structure from the dev_id and |
| 10845 | * assume the HBA is not interrupting. |
| 10846 | */ |
| 10847 | phba = (struct lpfc_hba *) dev_id; |
| 10848 | |
| 10849 | if (unlikely(!phba)) |
| 10850 | return IRQ_NONE; |
| 10851 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10852 | /* Check device state for handling interrupt */ |
| 10853 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10854 | return IRQ_NONE; |
| 10855 | |
| 10856 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10857 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 10858 | spin_unlock(&phba->hbalock); |
| 10859 | return IRQ_HANDLED; |
| 10860 | } |
| 10861 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10862 | if (unlikely(!phba->ha_copy)) { |
| 10863 | spin_unlock(&phba->hbalock); |
| 10864 | return IRQ_NONE; |
| 10865 | } else if (phba->ha_copy & HA_ERATT) { |
| 10866 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10867 | /* ERATT polling has handled ERATT */ |
| 10868 | phba->ha_copy &= ~HA_ERATT; |
| 10869 | else |
| 10870 | /* Indicate interrupt handler handles ERATT */ |
| 10871 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10872 | } |
| 10873 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10874 | /* |
| 10875 | * If there is deferred error attention, do not check for any interrupt. |
| 10876 | */ |
| 10877 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 10878 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10879 | return IRQ_NONE; |
| 10880 | } |
| 10881 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10882 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10883 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 10884 | spin_unlock(&phba->hbalock); |
| 10885 | return IRQ_HANDLED; |
| 10886 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10887 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 10888 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10889 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10890 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10891 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10892 | readl(phba->HAregaddr); /* flush */ |
| 10893 | spin_unlock(&phba->hbalock); |
| 10894 | |
| 10895 | /* |
| 10896 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 10897 | */ |
| 10898 | |
| 10899 | /* status of events with mailbox and link attention */ |
| 10900 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 10901 | |
| 10902 | /* status of events with ELS ring */ |
| 10903 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10904 | status2 >>= (4*LPFC_ELS_RING); |
| 10905 | |
| 10906 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10907 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10908 | else |
| 10909 | sp_irq_rc = IRQ_NONE; |
| 10910 | |
| 10911 | /* |
| 10912 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 10913 | */ |
| 10914 | |
| 10915 | /* status of events with FCP ring */ |
| 10916 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 10917 | status1 >>= (4*LPFC_FCP_RING); |
| 10918 | |
| 10919 | /* status of events with extra ring */ |
| 10920 | if (phba->cfg_multi_ring_support == 2) { |
| 10921 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 10922 | status2 >>= (4*LPFC_EXTRA_RING); |
| 10923 | } else |
| 10924 | status2 = 0; |
| 10925 | |
| 10926 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10927 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10928 | else |
| 10929 | fp_irq_rc = IRQ_NONE; |
| 10930 | |
| 10931 | /* Return device-level interrupt handling status */ |
| 10932 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10933 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10934 | |
| 10935 | /** |
| 10936 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 10937 | * @phba: pointer to lpfc hba data structure. |
| 10938 | * |
| 10939 | * This routine is invoked by the worker thread to process all the pending |
| 10940 | * SLI4 FCP abort XRI events. |
| 10941 | **/ |
| 10942 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10943 | { |
| 10944 | struct lpfc_cq_event *cq_event; |
| 10945 | |
| 10946 | /* First, declare the fcp xri abort event has been handled */ |
| 10947 | spin_lock_irq(&phba->hbalock); |
| 10948 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 10949 | spin_unlock_irq(&phba->hbalock); |
| 10950 | /* Now, handle all the fcp xri abort events */ |
| 10951 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 10952 | /* Get the first event from the head of the event queue */ |
| 10953 | spin_lock_irq(&phba->hbalock); |
| 10954 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10955 | cq_event, struct lpfc_cq_event, list); |
| 10956 | spin_unlock_irq(&phba->hbalock); |
| 10957 | /* Notify aborted XRI for FCP work queue */ |
| 10958 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10959 | /* Free the event processed back to the free pool */ |
| 10960 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10961 | } |
| 10962 | } |
| 10963 | |
| 10964 | /** |
| 10965 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 10966 | * @phba: pointer to lpfc hba data structure. |
| 10967 | * |
| 10968 | * This routine is invoked by the worker thread to process all the pending |
| 10969 | * SLI4 els abort xri events. |
| 10970 | **/ |
| 10971 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10972 | { |
| 10973 | struct lpfc_cq_event *cq_event; |
| 10974 | |
| 10975 | /* First, declare the els xri abort event has been handled */ |
| 10976 | spin_lock_irq(&phba->hbalock); |
| 10977 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 10978 | spin_unlock_irq(&phba->hbalock); |
| 10979 | /* Now, handle all the els xri abort events */ |
| 10980 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 10981 | /* Get the first event from the head of the event queue */ |
| 10982 | spin_lock_irq(&phba->hbalock); |
| 10983 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10984 | cq_event, struct lpfc_cq_event, list); |
| 10985 | spin_unlock_irq(&phba->hbalock); |
| 10986 | /* Notify aborted XRI for ELS work queue */ |
| 10987 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10988 | /* Free the event processed back to the free pool */ |
| 10989 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10990 | } |
| 10991 | } |
| 10992 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10993 | /** |
| 10994 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 10995 | * @phba: pointer to lpfc hba data structure |
| 10996 | * @pIocbIn: pointer to the rspiocbq |
| 10997 | * @pIocbOut: pointer to the cmdiocbq |
| 10998 | * @wcqe: pointer to the complete wcqe |
| 10999 | * |
| 11000 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 11001 | * by copying all the IOCB fields from command iocbq and transferring the |
| 11002 | * completion status information from the complete wcqe. |
| 11003 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11004 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11005 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 11006 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11007 | struct lpfc_iocbq *pIocbOut, |
| 11008 | struct lpfc_wcqe_complete *wcqe) |
| 11009 | { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11010 | unsigned long iflags; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11011 | uint32_t status; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11012 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 11013 | |
| 11014 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 11015 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11016 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11017 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 11018 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11019 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 11020 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 11021 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 11022 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 11023 | wcqe->total_data_placed; |
| 11024 | else |
| 11025 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11026 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11027 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11028 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
| 11029 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11030 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11031 | /* Convert BG errors for completion status */ |
| 11032 | if (status == CQE_STATUS_DI_ERROR) { |
| 11033 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 11034 | |
| 11035 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 11036 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 11037 | else |
| 11038 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 11039 | |
| 11040 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 11041 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 11042 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11043 | BGS_GUARD_ERR_MASK; |
| 11044 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 11045 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11046 | BGS_APPTAG_ERR_MASK; |
| 11047 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 11048 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11049 | BGS_REFTAG_ERR_MASK; |
| 11050 | |
| 11051 | /* Check to see if there was any good data before the error */ |
| 11052 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 11053 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11054 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 11055 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 11056 | wcqe->total_data_placed; |
| 11057 | } |
| 11058 | |
| 11059 | /* |
| 11060 | * Set ALL the error bits to indicate we don't know what |
| 11061 | * type of error it is. |
| 11062 | */ |
| 11063 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 11064 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11065 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 11066 | BGS_GUARD_ERR_MASK); |
| 11067 | } |
| 11068 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11069 | /* Pick up HBA exchange busy condition */ |
| 11070 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 11071 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11072 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 11073 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11074 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11075 | } |
| 11076 | |
| 11077 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11078 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 11079 | * @phba: Pointer to HBA context object. |
| 11080 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11081 | * |
| 11082 | * This routine handles an ELS work-queue completion event and construct |
| 11083 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 11084 | * discovery engine to handle. |
| 11085 | * |
| 11086 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 11087 | **/ |
| 11088 | static struct lpfc_iocbq * |
| 11089 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 11090 | struct lpfc_iocbq *irspiocbq) |
| 11091 | { |
| 11092 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 11093 | struct lpfc_iocbq *cmdiocbq; |
| 11094 | struct lpfc_wcqe_complete *wcqe; |
| 11095 | unsigned long iflags; |
| 11096 | |
| 11097 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11098 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11099 | pring->stats.iocb_event++; |
| 11100 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 11101 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11102 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11103 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11104 | |
| 11105 | if (unlikely(!cmdiocbq)) { |
| 11106 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11107 | "0386 ELS complete with no corresponding " |
| 11108 | "cmdiocb: iotag (%d)\n", |
| 11109 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11110 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 11111 | return NULL; |
| 11112 | } |
| 11113 | |
| 11114 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11115 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11116 | |
| 11117 | return irspiocbq; |
| 11118 | } |
| 11119 | |
| 11120 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11121 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11122 | * @phba: Pointer to HBA context object. |
| 11123 | * @cqe: Pointer to mailbox completion queue entry. |
| 11124 | * |
| 11125 | * This routine process a mailbox completion queue entry with asynchrous |
| 11126 | * event. |
| 11127 | * |
| 11128 | * Return: true if work posted to worker thread, otherwise false. |
| 11129 | **/ |
| 11130 | static bool |
| 11131 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11132 | { |
| 11133 | struct lpfc_cq_event *cq_event; |
| 11134 | unsigned long iflags; |
| 11135 | |
| 11136 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11137 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11138 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11139 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11140 | |
| 11141 | /* Allocate a new internal CQ_EVENT entry */ |
| 11142 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11143 | if (!cq_event) { |
| 11144 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11145 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11146 | return false; |
| 11147 | } |
| 11148 | |
| 11149 | /* Move the CQE into an asynchronous event entry */ |
| 11150 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11151 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11152 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11153 | /* Set the async event flag */ |
| 11154 | phba->hba_flag |= ASYNC_EVENT; |
| 11155 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11156 | |
| 11157 | return true; |
| 11158 | } |
| 11159 | |
| 11160 | /** |
| 11161 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11162 | * @phba: Pointer to HBA context object. |
| 11163 | * @cqe: Pointer to mailbox completion queue entry. |
| 11164 | * |
| 11165 | * This routine process a mailbox completion queue entry with mailbox |
| 11166 | * completion event. |
| 11167 | * |
| 11168 | * Return: true if work posted to worker thread, otherwise false. |
| 11169 | **/ |
| 11170 | static bool |
| 11171 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11172 | { |
| 11173 | uint32_t mcqe_status; |
| 11174 | MAILBOX_t *mbox, *pmbox; |
| 11175 | struct lpfc_mqe *mqe; |
| 11176 | struct lpfc_vport *vport; |
| 11177 | struct lpfc_nodelist *ndlp; |
| 11178 | struct lpfc_dmabuf *mp; |
| 11179 | unsigned long iflags; |
| 11180 | LPFC_MBOXQ_t *pmb; |
| 11181 | bool workposted = false; |
| 11182 | int rc; |
| 11183 | |
| 11184 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11185 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11186 | goto out_no_mqe_complete; |
| 11187 | |
| 11188 | /* Get the reference to the active mbox command */ |
| 11189 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11190 | pmb = phba->sli.mbox_active; |
| 11191 | if (unlikely(!pmb)) { |
| 11192 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11193 | "1832 No pending MBOX command to handle\n"); |
| 11194 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11195 | goto out_no_mqe_complete; |
| 11196 | } |
| 11197 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11198 | mqe = &pmb->u.mqe; |
| 11199 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11200 | mbox = phba->mbox; |
| 11201 | vport = pmb->vport; |
| 11202 | |
| 11203 | /* Reset heartbeat timer */ |
| 11204 | phba->last_completion_time = jiffies; |
| 11205 | del_timer(&phba->sli.mbox_tmo); |
| 11206 | |
| 11207 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11208 | if (pmb->mbox_cmpl && mbox) |
| 11209 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11210 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11211 | /* |
| 11212 | * For mcqe errors, conditionally move a modified error code to |
| 11213 | * the mbox so that the error will not be missed. |
| 11214 | */ |
| 11215 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11216 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11217 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11218 | bf_set(lpfc_mqe_status, mqe, |
| 11219 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11220 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11221 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11222 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11223 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11224 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11225 | mcqe_status, |
| 11226 | pmbox->un.varWords[0], 0); |
| 11227 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11228 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11229 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11230 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11231 | * RID of the PPI using the same mbox buffer. |
| 11232 | */ |
| 11233 | lpfc_unreg_login(phba, vport->vpi, |
| 11234 | pmbox->un.varWords[0], pmb); |
| 11235 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11236 | pmb->context1 = mp; |
| 11237 | pmb->context2 = ndlp; |
| 11238 | pmb->vport = vport; |
| 11239 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11240 | if (rc != MBX_BUSY) |
| 11241 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11242 | LOG_SLI, "0385 rc should " |
| 11243 | "have been MBX_BUSY\n"); |
| 11244 | if (rc != MBX_NOT_FINISHED) |
| 11245 | goto send_current_mbox; |
| 11246 | } |
| 11247 | } |
| 11248 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11249 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11250 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11251 | |
| 11252 | /* There is mailbox completion work to do */ |
| 11253 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11254 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11255 | phba->work_ha |= HA_MBATT; |
| 11256 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11257 | workposted = true; |
| 11258 | |
| 11259 | send_current_mbox: |
| 11260 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11261 | /* Release the mailbox command posting token */ |
| 11262 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11263 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11264 | phba->sli.mbox_active = NULL; |
| 11265 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11266 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11267 | lpfc_worker_wake_up(phba); |
| 11268 | out_no_mqe_complete: |
| 11269 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11270 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11271 | return workposted; |
| 11272 | } |
| 11273 | |
| 11274 | /** |
| 11275 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11276 | * @phba: Pointer to HBA context object. |
| 11277 | * @cqe: Pointer to mailbox completion queue entry. |
| 11278 | * |
| 11279 | * This routine process a mailbox completion queue entry, it invokes the |
| 11280 | * proper mailbox complete handling or asynchrous event handling routine |
| 11281 | * according to the MCQE's async bit. |
| 11282 | * |
| 11283 | * Return: true if work posted to worker thread, otherwise false. |
| 11284 | **/ |
| 11285 | static bool |
| 11286 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11287 | { |
| 11288 | struct lpfc_mcqe mcqe; |
| 11289 | bool workposted; |
| 11290 | |
| 11291 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11292 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11293 | |
| 11294 | /* Invoke the proper event handling routine */ |
| 11295 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11296 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11297 | else |
| 11298 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11299 | return workposted; |
| 11300 | } |
| 11301 | |
| 11302 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11303 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11304 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11305 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11306 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11307 | * |
| 11308 | * This routine handles an ELS work-queue completion event. |
| 11309 | * |
| 11310 | * Return: true if work posted to worker thread, otherwise false. |
| 11311 | **/ |
| 11312 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11313 | 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] | 11314 | struct lpfc_wcqe_complete *wcqe) |
| 11315 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11316 | struct lpfc_iocbq *irspiocbq; |
| 11317 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11318 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11319 | int txq_cnt = 0; |
| 11320 | int txcmplq_cnt = 0; |
| 11321 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11322 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11323 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11324 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 11325 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11326 | if (!list_empty(&pring->txq)) |
| 11327 | txq_cnt++; |
| 11328 | if (!list_empty(&pring->txcmplq)) |
| 11329 | txcmplq_cnt++; |
| 11330 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
| 11331 | fcp_txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11332 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11333 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 11334 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11335 | txq_cnt, phba->iocb_cnt, |
| 11336 | fcp_txcmplq_cnt, |
| 11337 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11338 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11339 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11340 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11341 | /* Save off the slow-path queue event for work thread to process */ |
| 11342 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11343 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11344 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11345 | &phba->sli4_hba.sp_queue_event); |
| 11346 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11347 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11348 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11349 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11350 | } |
| 11351 | |
| 11352 | /** |
| 11353 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11354 | * @phba: Pointer to HBA context object. |
| 11355 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11356 | * |
| 11357 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11358 | * proper WQ release routine to the slow-path WQ. |
| 11359 | **/ |
| 11360 | static void |
| 11361 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11362 | struct lpfc_wcqe_release *wcqe) |
| 11363 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11364 | /* sanity check on queue memory */ |
| 11365 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11366 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11367 | /* Check for the slow-path ELS work queue */ |
| 11368 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11369 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11370 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11371 | else |
| 11372 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11373 | "2579 Slow-path wqe consume event carries " |
| 11374 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11375 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11376 | phba->sli4_hba.els_wq->queue_id); |
| 11377 | } |
| 11378 | |
| 11379 | /** |
| 11380 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11381 | * @phba: Pointer to HBA context object. |
| 11382 | * @cq: Pointer to a WQ completion queue. |
| 11383 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11384 | * |
| 11385 | * This routine handles an XRI abort event. |
| 11386 | * |
| 11387 | * Return: true if work posted to worker thread, otherwise false. |
| 11388 | **/ |
| 11389 | static bool |
| 11390 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 11391 | struct lpfc_queue *cq, |
| 11392 | struct sli4_wcqe_xri_aborted *wcqe) |
| 11393 | { |
| 11394 | bool workposted = false; |
| 11395 | struct lpfc_cq_event *cq_event; |
| 11396 | unsigned long iflags; |
| 11397 | |
| 11398 | /* Allocate a new internal CQ_EVENT entry */ |
| 11399 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11400 | if (!cq_event) { |
| 11401 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11402 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 11403 | return false; |
| 11404 | } |
| 11405 | |
| 11406 | /* Move the CQE into the proper xri abort event list */ |
| 11407 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 11408 | switch (cq->subtype) { |
| 11409 | case LPFC_FCP: |
| 11410 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11411 | list_add_tail(&cq_event->list, |
| 11412 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 11413 | /* Set the fcp xri abort event flag */ |
| 11414 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 11415 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11416 | workposted = true; |
| 11417 | break; |
| 11418 | case LPFC_ELS: |
| 11419 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11420 | list_add_tail(&cq_event->list, |
| 11421 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 11422 | /* Set the els xri abort event flag */ |
| 11423 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 11424 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11425 | workposted = true; |
| 11426 | break; |
| 11427 | default: |
| 11428 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11429 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 11430 | cq->subtype); |
| 11431 | workposted = false; |
| 11432 | break; |
| 11433 | } |
| 11434 | return workposted; |
| 11435 | } |
| 11436 | |
| 11437 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11438 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11439 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11440 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11441 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11442 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11443 | * |
| 11444 | * Return: true if work posted to worker thread, otherwise false. |
| 11445 | **/ |
| 11446 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11447 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 11448 | { |
| 11449 | bool workposted = false; |
| 11450 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 11451 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 11452 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11453 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11454 | unsigned long iflags; |
| 11455 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11456 | /* sanity check on queue memory */ |
| 11457 | if (unlikely(!hrq) || unlikely(!drq)) |
| 11458 | return workposted; |
| 11459 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11460 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 11461 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 11462 | else |
| 11463 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 11464 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11465 | goto out; |
| 11466 | |
| 11467 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 11468 | switch (status) { |
| 11469 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 11470 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11471 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11472 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11473 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11474 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11475 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11476 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 11477 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11478 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11479 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11480 | goto out; |
| 11481 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11482 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11483 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 11484 | /* save off the frame for the word thread to process */ |
| 11485 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11486 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11487 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11488 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11489 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11490 | workposted = true; |
| 11491 | break; |
| 11492 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 11493 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11494 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11495 | /* Post more buffers if possible */ |
| 11496 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11497 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 11498 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11499 | workposted = true; |
| 11500 | break; |
| 11501 | } |
| 11502 | out: |
| 11503 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11504 | } |
| 11505 | |
| 11506 | /** |
| 11507 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 11508 | * @phba: Pointer to HBA context object. |
| 11509 | * @cq: Pointer to the completion queue. |
| 11510 | * @wcqe: Pointer to a completion queue entry. |
| 11511 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11512 | * 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] | 11513 | * entry. |
| 11514 | * |
| 11515 | * Return: true if work posted to worker thread, otherwise false. |
| 11516 | **/ |
| 11517 | static bool |
| 11518 | 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] | 11519 | struct lpfc_cqe *cqe) |
| 11520 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11521 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11522 | bool workposted = false; |
| 11523 | |
| 11524 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11525 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11526 | |
| 11527 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11528 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11529 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11530 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11531 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11532 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11533 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11534 | break; |
| 11535 | case CQE_CODE_RELEASE_WQE: |
| 11536 | /* Process the WQ release event */ |
| 11537 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11538 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11539 | break; |
| 11540 | case CQE_CODE_XRI_ABORTED: |
| 11541 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11542 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11543 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11544 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11545 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11546 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11547 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11548 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11549 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11550 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11551 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11552 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11553 | default: |
| 11554 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11555 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11556 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11557 | break; |
| 11558 | } |
| 11559 | return workposted; |
| 11560 | } |
| 11561 | |
| 11562 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11563 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 11564 | * @phba: Pointer to HBA context object. |
| 11565 | * @eqe: Pointer to fast-path event queue entry. |
| 11566 | * |
| 11567 | * This routine process a event queue entry from the slow-path event queue. |
| 11568 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11569 | * completion event on a completion queue, if not, an error shall be logged |
| 11570 | * and just return. Otherwise, it will get to the corresponding completion |
| 11571 | * queue and process all the entries on that completion queue, rearm the |
| 11572 | * completion queue, and then return. |
| 11573 | * |
| 11574 | **/ |
| 11575 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11576 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11577 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11578 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11579 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11580 | struct lpfc_cqe *cqe; |
| 11581 | bool workposted = false; |
| 11582 | int ecount = 0; |
| 11583 | uint16_t cqid; |
| 11584 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11585 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11586 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11587 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11588 | list_for_each_entry(childq, &speq->child_list, list) { |
| 11589 | if (childq->queue_id == cqid) { |
| 11590 | cq = childq; |
| 11591 | break; |
| 11592 | } |
| 11593 | } |
| 11594 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11595 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11596 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11597 | "0365 Slow-path CQ identifier " |
| 11598 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11599 | return; |
| 11600 | } |
| 11601 | |
| 11602 | /* Process all the entries to the CQ */ |
| 11603 | switch (cq->type) { |
| 11604 | case LPFC_MCQ: |
| 11605 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11606 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11607 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11608 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11609 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11610 | } |
| 11611 | break; |
| 11612 | case LPFC_WCQ: |
| 11613 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11614 | if (cq->subtype == LPFC_FCP) |
| 11615 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 11616 | cqe); |
| 11617 | else |
| 11618 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 11619 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11620 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11621 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11622 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11623 | |
| 11624 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11625 | if (ecount > cq->CQ_max_cqe) |
| 11626 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11627 | break; |
| 11628 | default: |
| 11629 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11630 | "0370 Invalid completion queue type (%d)\n", |
| 11631 | cq->type); |
| 11632 | return; |
| 11633 | } |
| 11634 | |
| 11635 | /* Catch the no cq entry condition, log an error */ |
| 11636 | if (unlikely(ecount == 0)) |
| 11637 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11638 | "0371 No entry from the CQ: identifier " |
| 11639 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 11640 | |
| 11641 | /* In any case, flash and re-arm the RCQ */ |
| 11642 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11643 | |
| 11644 | /* wake up worker thread if there are works to be done */ |
| 11645 | if (workposted) |
| 11646 | lpfc_worker_wake_up(phba); |
| 11647 | } |
| 11648 | |
| 11649 | /** |
| 11650 | * 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] | 11651 | * @phba: Pointer to HBA context object. |
| 11652 | * @cq: Pointer to associated CQ |
| 11653 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11654 | * |
| 11655 | * This routine process a fast-path work queue completion entry from fast-path |
| 11656 | * event queue for FCP command response completion. |
| 11657 | **/ |
| 11658 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11659 | 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] | 11660 | struct lpfc_wcqe_complete *wcqe) |
| 11661 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11662 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11663 | struct lpfc_iocbq *cmdiocbq; |
| 11664 | struct lpfc_iocbq irspiocbq; |
| 11665 | unsigned long iflags; |
| 11666 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11667 | /* Check for response status */ |
| 11668 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 11669 | /* If resource errors reported from HBA, reduce queue |
| 11670 | * depth of the SCSI device. |
| 11671 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11672 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 11673 | IOSTAT_LOCAL_REJECT)) && |
| 11674 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 11675 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11676 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11677 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11678 | /* Log the error status */ |
| 11679 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11680 | "0373 FCP complete error: status=x%x, " |
| 11681 | "hw_status=x%x, total_data_specified=%d, " |
| 11682 | "parameter=x%x, word3=x%x\n", |
| 11683 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 11684 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 11685 | wcqe->total_data_placed, wcqe->parameter, |
| 11686 | wcqe->word3); |
| 11687 | } |
| 11688 | |
| 11689 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11690 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11691 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11692 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11693 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11694 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11695 | if (unlikely(!cmdiocbq)) { |
| 11696 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11697 | "0374 FCP complete with no corresponding " |
| 11698 | "cmdiocb: iotag (%d)\n", |
| 11699 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11700 | return; |
| 11701 | } |
| 11702 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 11703 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11704 | "0375 FCP cmdiocb not callback function " |
| 11705 | "iotag: (%d)\n", |
| 11706 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11707 | return; |
| 11708 | } |
| 11709 | |
| 11710 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11711 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11712 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11713 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 11714 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11715 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11716 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11717 | } |
| 11718 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11719 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 11720 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 11721 | } |
| 11722 | |
| 11723 | /** |
| 11724 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 11725 | * @phba: Pointer to HBA context object. |
| 11726 | * @cq: Pointer to completion queue. |
| 11727 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11728 | * |
| 11729 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 11730 | * proper WQ release routine to the slow-path WQ. |
| 11731 | **/ |
| 11732 | static void |
| 11733 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11734 | struct lpfc_wcqe_release *wcqe) |
| 11735 | { |
| 11736 | struct lpfc_queue *childwq; |
| 11737 | bool wqid_matched = false; |
| 11738 | uint16_t fcp_wqid; |
| 11739 | |
| 11740 | /* Check for fast-path FCP work queue release */ |
| 11741 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 11742 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 11743 | if (childwq->queue_id == fcp_wqid) { |
| 11744 | lpfc_sli4_wq_release(childwq, |
| 11745 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11746 | wqid_matched = true; |
| 11747 | break; |
| 11748 | } |
| 11749 | } |
| 11750 | /* Report warning log message if no match found */ |
| 11751 | if (wqid_matched != true) |
| 11752 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11753 | "2580 Fast-path wqe consume event carries " |
| 11754 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 11755 | } |
| 11756 | |
| 11757 | /** |
| 11758 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 11759 | * @cq: Pointer to the completion queue. |
| 11760 | * @eqe: Pointer to fast-path completion queue entry. |
| 11761 | * |
| 11762 | * This routine process a fast-path work queue completion entry from fast-path |
| 11763 | * event queue for FCP command response completion. |
| 11764 | **/ |
| 11765 | static int |
| 11766 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11767 | struct lpfc_cqe *cqe) |
| 11768 | { |
| 11769 | struct lpfc_wcqe_release wcqe; |
| 11770 | bool workposted = false; |
| 11771 | |
| 11772 | /* Copy the work queue CQE and convert endian order if needed */ |
| 11773 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 11774 | |
| 11775 | /* Check and process for different type of WCQE and dispatch */ |
| 11776 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 11777 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11778 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11779 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11780 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11781 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11782 | (struct lpfc_wcqe_complete *)&wcqe); |
| 11783 | break; |
| 11784 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11785 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11786 | /* Process the WQ release event */ |
| 11787 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 11788 | (struct lpfc_wcqe_release *)&wcqe); |
| 11789 | break; |
| 11790 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11791 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11792 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11793 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11794 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 11795 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 11796 | break; |
| 11797 | default: |
| 11798 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11799 | "0144 Not a valid WCQE code: x%x\n", |
| 11800 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 11801 | break; |
| 11802 | } |
| 11803 | return workposted; |
| 11804 | } |
| 11805 | |
| 11806 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11807 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11808 | * @phba: Pointer to HBA context object. |
| 11809 | * @eqe: Pointer to fast-path event queue entry. |
| 11810 | * |
| 11811 | * This routine process a event queue entry from the fast-path event queue. |
| 11812 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11813 | * completion event on a completion queue, if not, an error shall be logged |
| 11814 | * and just return. Otherwise, it will get to the corresponding completion |
| 11815 | * queue and process all the entries on the completion queue, rearm the |
| 11816 | * completion queue, and then return. |
| 11817 | **/ |
| 11818 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11819 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11820 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11821 | { |
| 11822 | struct lpfc_queue *cq; |
| 11823 | struct lpfc_cqe *cqe; |
| 11824 | bool workposted = false; |
| 11825 | uint16_t cqid; |
| 11826 | int ecount = 0; |
| 11827 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11828 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11829 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11830 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11831 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11832 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11833 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11834 | return; |
| 11835 | } |
| 11836 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11837 | /* Get the reference to the corresponding CQ */ |
| 11838 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 11839 | |
| 11840 | /* Check if this is a Slow path event */ |
| 11841 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { |
| 11842 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 11843 | phba->sli4_hba.hba_eq[qidx]); |
| 11844 | return; |
| 11845 | } |
| 11846 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11847 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 11848 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11849 | "3146 Fast-path completion queues " |
| 11850 | "does not exist\n"); |
| 11851 | return; |
| 11852 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11853 | cq = phba->sli4_hba.fcp_cq[qidx]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11854 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11855 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11856 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11857 | "0367 Fast-path completion queue " |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11858 | "(%d) does not exist\n", qidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11859 | return; |
| 11860 | } |
| 11861 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11862 | if (unlikely(cqid != cq->queue_id)) { |
| 11863 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11864 | "0368 Miss-matched fast-path completion " |
| 11865 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 11866 | cqid, cq->queue_id); |
| 11867 | return; |
| 11868 | } |
| 11869 | |
| 11870 | /* Process all the entries to the CQ */ |
| 11871 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11872 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11873 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11874 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11875 | } |
| 11876 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11877 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11878 | if (ecount > cq->CQ_max_cqe) |
| 11879 | cq->CQ_max_cqe = ecount; |
| 11880 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11881 | /* Catch the no cq entry condition */ |
| 11882 | if (unlikely(ecount == 0)) |
| 11883 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11884 | "0369 No entry from fast-path completion " |
| 11885 | "queue fcpcqid=%d\n", cq->queue_id); |
| 11886 | |
| 11887 | /* In any case, flash and re-arm the CQ */ |
| 11888 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11889 | |
| 11890 | /* wake up worker thread if there are works to be done */ |
| 11891 | if (workposted) |
| 11892 | lpfc_worker_wake_up(phba); |
| 11893 | } |
| 11894 | |
| 11895 | static void |
| 11896 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 11897 | { |
| 11898 | struct lpfc_eqe *eqe; |
| 11899 | |
| 11900 | /* walk all the EQ entries and drop on the floor */ |
| 11901 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 11902 | ; |
| 11903 | |
| 11904 | /* Clear and re-arm the EQ */ |
| 11905 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 11906 | } |
| 11907 | |
| 11908 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11909 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11910 | * @irq: Interrupt number. |
| 11911 | * @dev_id: The device context pointer. |
| 11912 | * |
| 11913 | * This function is directly called from the PCI layer as an interrupt |
| 11914 | * service routine when device with SLI-4 interface spec is enabled with |
| 11915 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11916 | * ring event in the HBA. However, when the device is enabled with either |
| 11917 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11918 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11919 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11920 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11921 | * the intrrupt context. This function is called without any lock held. |
| 11922 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 11923 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 11924 | * equal to that of FCP CQ index. |
| 11925 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11926 | * The link attention and ELS ring attention events are handled |
| 11927 | * by the worker thread. The interrupt handler signals the worker thread |
| 11928 | * and returns for these events. This function is called without any lock |
| 11929 | * held. It gets the hbalock to access and update SLI data structures. |
| 11930 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11931 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11932 | * returns IRQ_NONE. |
| 11933 | **/ |
| 11934 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11935 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11936 | { |
| 11937 | struct lpfc_hba *phba; |
| 11938 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 11939 | struct lpfc_queue *fpeq; |
| 11940 | struct lpfc_eqe *eqe; |
| 11941 | unsigned long iflag; |
| 11942 | int ecount = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 11943 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11944 | |
| 11945 | /* Get the driver's phba structure from the dev_id */ |
| 11946 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 11947 | phba = fcp_eq_hdl->phba; |
| 11948 | fcp_eqidx = fcp_eq_hdl->idx; |
| 11949 | |
| 11950 | if (unlikely(!phba)) |
| 11951 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11952 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11953 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11954 | |
| 11955 | /* Get to the EQ struct associated with this vector */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11956 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11957 | if (unlikely(!fpeq)) |
| 11958 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11959 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 11960 | if (lpfc_fcp_look_ahead) { |
| 11961 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) |
| 11962 | lpfc_sli4_eq_clr_intr(fpeq); |
| 11963 | else { |
| 11964 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 11965 | return IRQ_NONE; |
| 11966 | } |
| 11967 | } |
| 11968 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11969 | /* Check device state for handling interrupt */ |
| 11970 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11971 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11972 | /* Check again for link_state with lock held */ |
| 11973 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11974 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11975 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11976 | lpfc_sli4_eq_flush(phba, fpeq); |
| 11977 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 11978 | if (lpfc_fcp_look_ahead) |
| 11979 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11980 | return IRQ_NONE; |
| 11981 | } |
| 11982 | |
| 11983 | /* |
| 11984 | * Process all the event on FCP fast-path EQ |
| 11985 | */ |
| 11986 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11987 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11988 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11989 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11990 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11991 | } |
| 11992 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11993 | /* Track the max number of EQEs processed in 1 intr */ |
| 11994 | if (ecount > fpeq->EQ_max_eqe) |
| 11995 | fpeq->EQ_max_eqe = ecount; |
| 11996 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11997 | /* Always clear and re-arm the fast-path EQ */ |
| 11998 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 11999 | |
| 12000 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12001 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12002 | |
| 12003 | if (lpfc_fcp_look_ahead) { |
| 12004 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12005 | return IRQ_NONE; |
| 12006 | } |
| 12007 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12008 | if (phba->intr_type == MSIX) |
| 12009 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12010 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12011 | "0358 MSI-X interrupt with no EQE\n"); |
| 12012 | else |
| 12013 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12014 | return IRQ_NONE; |
| 12015 | } |
| 12016 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12017 | if (lpfc_fcp_look_ahead) |
| 12018 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12019 | return IRQ_HANDLED; |
| 12020 | } /* lpfc_sli4_fp_intr_handler */ |
| 12021 | |
| 12022 | /** |
| 12023 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 12024 | * @irq: Interrupt number. |
| 12025 | * @dev_id: The device context pointer. |
| 12026 | * |
| 12027 | * This function is the device-level interrupt handler to device with SLI-4 |
| 12028 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 12029 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 12030 | * driver attention. This function invokes the slow-path interrupt attention |
| 12031 | * handling function and fast-path interrupt attention handling function in |
| 12032 | * turn to process the relevant HBA attention events. This function is called |
| 12033 | * without any lock held. It gets the hbalock to access and update SLI data |
| 12034 | * structures. |
| 12035 | * |
| 12036 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12037 | * returns IRQ_NONE. |
| 12038 | **/ |
| 12039 | irqreturn_t |
| 12040 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 12041 | { |
| 12042 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12043 | irqreturn_t hba_irq_rc; |
| 12044 | bool hba_handled = false; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12045 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12046 | |
| 12047 | /* Get the driver's phba structure from the dev_id */ |
| 12048 | phba = (struct lpfc_hba *)dev_id; |
| 12049 | |
| 12050 | if (unlikely(!phba)) |
| 12051 | return IRQ_NONE; |
| 12052 | |
| 12053 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12054 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12055 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12056 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 12057 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12058 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12059 | if (hba_irq_rc == IRQ_HANDLED) |
| 12060 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12061 | } |
| 12062 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12063 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12064 | } /* lpfc_sli4_intr_handler */ |
| 12065 | |
| 12066 | /** |
| 12067 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 12068 | * @queue: The queue structure to free. |
| 12069 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 12070 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12071 | * the host resident queue. This function must be called after destroying the |
| 12072 | * queue on the HBA. |
| 12073 | **/ |
| 12074 | void |
| 12075 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12076 | { |
| 12077 | struct lpfc_dmabuf *dmabuf; |
| 12078 | |
| 12079 | if (!queue) |
| 12080 | return; |
| 12081 | |
| 12082 | while (!list_empty(&queue->page_list)) { |
| 12083 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12084 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12085 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12086 | dmabuf->virt, dmabuf->phys); |
| 12087 | kfree(dmabuf); |
| 12088 | } |
| 12089 | kfree(queue); |
| 12090 | return; |
| 12091 | } |
| 12092 | |
| 12093 | /** |
| 12094 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12095 | * @phba: The HBA that this queue is being created on. |
| 12096 | * @entry_size: The size of each queue entry for this queue. |
| 12097 | * @entry count: The number of entries that this queue will handle. |
| 12098 | * |
| 12099 | * This function allocates a queue structure and the DMAable memory used for |
| 12100 | * the host resident queue. This function must be called before creating the |
| 12101 | * queue on the HBA. |
| 12102 | **/ |
| 12103 | struct lpfc_queue * |
| 12104 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12105 | uint32_t entry_count) |
| 12106 | { |
| 12107 | struct lpfc_queue *queue; |
| 12108 | struct lpfc_dmabuf *dmabuf; |
| 12109 | int x, total_qe_count; |
| 12110 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12111 | 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] | 12112 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12113 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12114 | hw_page_size = SLI4_PAGE_SIZE; |
| 12115 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12116 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 12117 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 12118 | if (!queue) |
| 12119 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12120 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 12121 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12122 | INIT_LIST_HEAD(&queue->list); |
| 12123 | INIT_LIST_HEAD(&queue->page_list); |
| 12124 | INIT_LIST_HEAD(&queue->child_list); |
| 12125 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 12126 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 12127 | if (!dmabuf) |
| 12128 | goto out_fail; |
| 12129 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12130 | hw_page_size, &dmabuf->phys, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12131 | GFP_KERNEL); |
| 12132 | if (!dmabuf->virt) { |
| 12133 | kfree(dmabuf); |
| 12134 | goto out_fail; |
| 12135 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12136 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12137 | dmabuf->buffer_tag = x; |
| 12138 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 12139 | /* initialize queue's entry array */ |
| 12140 | dma_pointer = dmabuf->virt; |
| 12141 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12142 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12143 | total_qe_count++, dma_pointer += entry_size) { |
| 12144 | queue->qe[total_qe_count].address = dma_pointer; |
| 12145 | } |
| 12146 | } |
| 12147 | queue->entry_size = entry_size; |
| 12148 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12149 | |
| 12150 | /* |
| 12151 | * entry_repost is calculated based on the number of entries in the |
| 12152 | * queue. This works out except for RQs. If buffers are NOT initially |
| 12153 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 12154 | */ |
| 12155 | queue->entry_repost = (entry_count >> 3); |
| 12156 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 12157 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12158 | queue->phba = phba; |
| 12159 | |
| 12160 | return queue; |
| 12161 | out_fail: |
| 12162 | lpfc_sli4_queue_free(queue); |
| 12163 | return NULL; |
| 12164 | } |
| 12165 | |
| 12166 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12167 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 12168 | * @phba: HBA structure that indicates port to create a queue on. |
| 12169 | * @pci_barset: PCI BAR set flag. |
| 12170 | * |
| 12171 | * This function shall perform iomap of the specified PCI BAR address to host |
| 12172 | * memory address if not already done so and return it. The returned host |
| 12173 | * memory address can be NULL. |
| 12174 | */ |
| 12175 | static void __iomem * |
| 12176 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 12177 | { |
| 12178 | struct pci_dev *pdev; |
| 12179 | unsigned long bar_map, bar_map_len; |
| 12180 | |
| 12181 | if (!phba->pcidev) |
| 12182 | return NULL; |
| 12183 | else |
| 12184 | pdev = phba->pcidev; |
| 12185 | |
| 12186 | switch (pci_barset) { |
| 12187 | case WQ_PCI_BAR_0_AND_1: |
| 12188 | if (!phba->pci_bar0_memmap_p) { |
| 12189 | bar_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 12190 | bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
| 12191 | phba->pci_bar0_memmap_p = ioremap(bar_map, bar_map_len); |
| 12192 | } |
| 12193 | return phba->pci_bar0_memmap_p; |
| 12194 | case WQ_PCI_BAR_2_AND_3: |
| 12195 | if (!phba->pci_bar2_memmap_p) { |
| 12196 | bar_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 12197 | bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 12198 | phba->pci_bar2_memmap_p = ioremap(bar_map, bar_map_len); |
| 12199 | } |
| 12200 | return phba->pci_bar2_memmap_p; |
| 12201 | case WQ_PCI_BAR_4_AND_5: |
| 12202 | if (!phba->pci_bar4_memmap_p) { |
| 12203 | bar_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 12204 | bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 12205 | phba->pci_bar4_memmap_p = ioremap(bar_map, bar_map_len); |
| 12206 | } |
| 12207 | return phba->pci_bar4_memmap_p; |
| 12208 | default: |
| 12209 | break; |
| 12210 | } |
| 12211 | return NULL; |
| 12212 | } |
| 12213 | |
| 12214 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12215 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 12216 | * @phba: HBA structure that indicates port to create a queue on. |
| 12217 | * @startq: The starting FCP EQ to modify |
| 12218 | * |
| 12219 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 12220 | * |
| 12221 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 12222 | * is used to get the starting FCP EQ to change. |
| 12223 | * This function is asynchronous and will wait for the mailbox |
| 12224 | * command to finish before continuing. |
| 12225 | * |
| 12226 | * On success this function will return a zero. If unable to allocate enough |
| 12227 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12228 | * fails this function will return -ENXIO. |
| 12229 | **/ |
| 12230 | uint32_t |
| 12231 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) |
| 12232 | { |
| 12233 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 12234 | LPFC_MBOXQ_t *mbox; |
| 12235 | struct lpfc_queue *eq; |
| 12236 | int cnt, rc, length, status = 0; |
| 12237 | uint32_t shdr_status, shdr_add_status; |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12238 | uint32_t result; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12239 | int fcp_eqidx; |
| 12240 | union lpfc_sli4_cfg_shdr *shdr; |
| 12241 | uint16_t dmult; |
| 12242 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12243 | if (startq >= phba->cfg_fcp_io_channel) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12244 | return 0; |
| 12245 | |
| 12246 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12247 | if (!mbox) |
| 12248 | return -ENOMEM; |
| 12249 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 12250 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12251 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12252 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 12253 | length, LPFC_SLI4_MBX_EMBED); |
| 12254 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 12255 | |
| 12256 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12257 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
| 12258 | if (result > LPFC_DMULT_CONST) |
| 12259 | dmult = 0; |
| 12260 | else |
| 12261 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12262 | |
| 12263 | cnt = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12264 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12265 | fcp_eqidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12266 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12267 | if (!eq) |
| 12268 | continue; |
| 12269 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 12270 | eq_delay->u.request.eq[cnt].phase = 0; |
| 12271 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 12272 | cnt++; |
| 12273 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 12274 | break; |
| 12275 | } |
| 12276 | eq_delay->u.request.num_eq = cnt; |
| 12277 | |
| 12278 | mbox->vport = phba->pport; |
| 12279 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12280 | mbox->context1 = NULL; |
| 12281 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12282 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 12283 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12284 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12285 | if (shdr_status || shdr_add_status || rc) { |
| 12286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12287 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 12288 | "status x%x add_status x%x, mbx status x%x\n", |
| 12289 | shdr_status, shdr_add_status, rc); |
| 12290 | status = -ENXIO; |
| 12291 | } |
| 12292 | mempool_free(mbox, phba->mbox_mem_pool); |
| 12293 | return status; |
| 12294 | } |
| 12295 | |
| 12296 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12297 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 12298 | * @phba: HBA structure that indicates port to create a queue on. |
| 12299 | * @eq: The queue structure to use to create the event queue. |
| 12300 | * @imax: The maximum interrupt per second limit. |
| 12301 | * |
| 12302 | * This function creates an event queue, as detailed in @eq, on a port, |
| 12303 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 12304 | * |
| 12305 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 12306 | * is used to get the entry count and entry size that are necessary to |
| 12307 | * determine the number of pages to allocate and use for this queue. This |
| 12308 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 12309 | * event queue. This function is asynchronous and will wait for the mailbox |
| 12310 | * command to finish before continuing. |
| 12311 | * |
| 12312 | * 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] | 12313 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12314 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12315 | **/ |
| 12316 | uint32_t |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12317 | 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] | 12318 | { |
| 12319 | struct lpfc_mbx_eq_create *eq_create; |
| 12320 | LPFC_MBOXQ_t *mbox; |
| 12321 | int rc, length, status = 0; |
| 12322 | struct lpfc_dmabuf *dmabuf; |
| 12323 | uint32_t shdr_status, shdr_add_status; |
| 12324 | union lpfc_sli4_cfg_shdr *shdr; |
| 12325 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12326 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12327 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12328 | /* sanity check on queue memory */ |
| 12329 | if (!eq) |
| 12330 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12331 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12332 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12333 | |
| 12334 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12335 | if (!mbox) |
| 12336 | return -ENOMEM; |
| 12337 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 12338 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12339 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12340 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 12341 | length, LPFC_SLI4_MBX_EMBED); |
| 12342 | eq_create = &mbox->u.mqe.un.eq_create; |
| 12343 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 12344 | eq->page_count); |
| 12345 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 12346 | LPFC_EQE_SIZE); |
| 12347 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
| 12348 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12349 | if (imax > LPFC_DMULT_CONST) |
| 12350 | dmult = 0; |
| 12351 | else |
| 12352 | dmult = LPFC_DMULT_CONST/imax - 1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12353 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 12354 | dmult); |
| 12355 | switch (eq->entry_count) { |
| 12356 | default: |
| 12357 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12358 | "0360 Unsupported EQ count. (%d)\n", |
| 12359 | eq->entry_count); |
| 12360 | if (eq->entry_count < 256) |
| 12361 | return -EINVAL; |
| 12362 | /* otherwise default to smallest count (drop through) */ |
| 12363 | case 256: |
| 12364 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12365 | LPFC_EQ_CNT_256); |
| 12366 | break; |
| 12367 | case 512: |
| 12368 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12369 | LPFC_EQ_CNT_512); |
| 12370 | break; |
| 12371 | case 1024: |
| 12372 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12373 | LPFC_EQ_CNT_1024); |
| 12374 | break; |
| 12375 | case 2048: |
| 12376 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12377 | LPFC_EQ_CNT_2048); |
| 12378 | break; |
| 12379 | case 4096: |
| 12380 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12381 | LPFC_EQ_CNT_4096); |
| 12382 | break; |
| 12383 | } |
| 12384 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12385 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12386 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12387 | putPaddrLow(dmabuf->phys); |
| 12388 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12389 | putPaddrHigh(dmabuf->phys); |
| 12390 | } |
| 12391 | mbox->vport = phba->pport; |
| 12392 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12393 | mbox->context1 = NULL; |
| 12394 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12395 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 12396 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12397 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12398 | if (shdr_status || shdr_add_status || rc) { |
| 12399 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12400 | "2500 EQ_CREATE mailbox failed with " |
| 12401 | "status x%x add_status x%x, mbx status x%x\n", |
| 12402 | shdr_status, shdr_add_status, rc); |
| 12403 | status = -ENXIO; |
| 12404 | } |
| 12405 | eq->type = LPFC_EQ; |
| 12406 | eq->subtype = LPFC_NONE; |
| 12407 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 12408 | if (eq->queue_id == 0xFFFF) |
| 12409 | status = -ENXIO; |
| 12410 | eq->host_index = 0; |
| 12411 | eq->hba_index = 0; |
| 12412 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12413 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12414 | return status; |
| 12415 | } |
| 12416 | |
| 12417 | /** |
| 12418 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 12419 | * @phba: HBA structure that indicates port to create a queue on. |
| 12420 | * @cq: The queue structure to use to create the completion queue. |
| 12421 | * @eq: The event queue to bind this completion queue to. |
| 12422 | * |
| 12423 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 12424 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 12425 | * |
| 12426 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12427 | * is used to get the entry count and entry size that are necessary to |
| 12428 | * determine the number of pages to allocate and use for this queue. The @eq |
| 12429 | * is used to indicate which event queue to bind this completion queue to. This |
| 12430 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 12431 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 12432 | * command to finish before continuing. |
| 12433 | * |
| 12434 | * 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] | 12435 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12436 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12437 | **/ |
| 12438 | uint32_t |
| 12439 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12440 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 12441 | { |
| 12442 | struct lpfc_mbx_cq_create *cq_create; |
| 12443 | struct lpfc_dmabuf *dmabuf; |
| 12444 | LPFC_MBOXQ_t *mbox; |
| 12445 | int rc, length, status = 0; |
| 12446 | uint32_t shdr_status, shdr_add_status; |
| 12447 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12448 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12449 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12450 | /* sanity check on queue memory */ |
| 12451 | if (!cq || !eq) |
| 12452 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12453 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12454 | hw_page_size = SLI4_PAGE_SIZE; |
| 12455 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12456 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12457 | if (!mbox) |
| 12458 | return -ENOMEM; |
| 12459 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 12460 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12461 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12462 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 12463 | length, LPFC_SLI4_MBX_EMBED); |
| 12464 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12465 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12466 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 12467 | cq->page_count); |
| 12468 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 12469 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12470 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12471 | phba->sli4_hba.pc_sli4_params.cqv); |
| 12472 | 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] | 12473 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 12474 | 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] | 12475 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 12476 | eq->queue_id); |
| 12477 | } else { |
| 12478 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 12479 | eq->queue_id); |
| 12480 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12481 | switch (cq->entry_count) { |
| 12482 | default: |
| 12483 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12484 | "0361 Unsupported CQ count. (%d)\n", |
| 12485 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12486 | if (cq->entry_count < 256) { |
| 12487 | status = -EINVAL; |
| 12488 | goto out; |
| 12489 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12490 | /* otherwise default to smallest count (drop through) */ |
| 12491 | case 256: |
| 12492 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12493 | LPFC_CQ_CNT_256); |
| 12494 | break; |
| 12495 | case 512: |
| 12496 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12497 | LPFC_CQ_CNT_512); |
| 12498 | break; |
| 12499 | case 1024: |
| 12500 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12501 | LPFC_CQ_CNT_1024); |
| 12502 | break; |
| 12503 | } |
| 12504 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12505 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12506 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12507 | putPaddrLow(dmabuf->phys); |
| 12508 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12509 | putPaddrHigh(dmabuf->phys); |
| 12510 | } |
| 12511 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12512 | |
| 12513 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12514 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12515 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12516 | if (shdr_status || shdr_add_status || rc) { |
| 12517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12518 | "2501 CQ_CREATE mailbox failed with " |
| 12519 | "status x%x add_status x%x, mbx status x%x\n", |
| 12520 | shdr_status, shdr_add_status, rc); |
| 12521 | status = -ENXIO; |
| 12522 | goto out; |
| 12523 | } |
| 12524 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 12525 | if (cq->queue_id == 0xFFFF) { |
| 12526 | status = -ENXIO; |
| 12527 | goto out; |
| 12528 | } |
| 12529 | /* link the cq onto the parent eq child list */ |
| 12530 | list_add_tail(&cq->list, &eq->child_list); |
| 12531 | /* Set up completion queue's type and subtype */ |
| 12532 | cq->type = type; |
| 12533 | cq->subtype = subtype; |
| 12534 | 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] | 12535 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12536 | cq->host_index = 0; |
| 12537 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12538 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12539 | out: |
| 12540 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12541 | return status; |
| 12542 | } |
| 12543 | |
| 12544 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12545 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12546 | * @phba: HBA structure that indicates port to create a queue on. |
| 12547 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12548 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 12549 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12550 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12551 | * This function provides failback (fb) functionality when the |
| 12552 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 12553 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12554 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12555 | * This routine cannot fail as all attributes were previously accessed and |
| 12556 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12557 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12558 | static void |
| 12559 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12560 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12561 | { |
| 12562 | struct lpfc_mbx_mq_create *mq_create; |
| 12563 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12564 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12565 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12566 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 12567 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12568 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12569 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 12570 | length, LPFC_SLI4_MBX_EMBED); |
| 12571 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12572 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12573 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12574 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12575 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12576 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 12577 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12578 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12579 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12580 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12581 | break; |
| 12582 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12583 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12584 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12585 | break; |
| 12586 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12587 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12588 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12589 | break; |
| 12590 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12591 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12592 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12593 | break; |
| 12594 | } |
| 12595 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 12596 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12597 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12598 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12599 | putPaddrHigh(dmabuf->phys); |
| 12600 | } |
| 12601 | } |
| 12602 | |
| 12603 | /** |
| 12604 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 12605 | * @phba: HBA structure that indicates port to create a queue on. |
| 12606 | * @mq: The queue structure to use to create the mailbox queue. |
| 12607 | * @cq: The completion queue to associate with this cq. |
| 12608 | * @subtype: The queue's subtype. |
| 12609 | * |
| 12610 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 12611 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 12612 | * |
| 12613 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12614 | * is used to get the entry count and entry size that are necessary to |
| 12615 | * determine the number of pages to allocate and use for this queue. This |
| 12616 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 12617 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 12618 | * command to finish before continuing. |
| 12619 | * |
| 12620 | * 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] | 12621 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12622 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12623 | **/ |
| 12624 | int32_t |
| 12625 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12626 | struct lpfc_queue *cq, uint32_t subtype) |
| 12627 | { |
| 12628 | struct lpfc_mbx_mq_create *mq_create; |
| 12629 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 12630 | struct lpfc_dmabuf *dmabuf; |
| 12631 | LPFC_MBOXQ_t *mbox; |
| 12632 | int rc, length, status = 0; |
| 12633 | uint32_t shdr_status, shdr_add_status; |
| 12634 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12635 | 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] | 12636 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12637 | /* sanity check on queue memory */ |
| 12638 | if (!mq || !cq) |
| 12639 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12640 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12641 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12642 | |
| 12643 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12644 | if (!mbox) |
| 12645 | return -ENOMEM; |
| 12646 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 12647 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12648 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12649 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 12650 | length, LPFC_SLI4_MBX_EMBED); |
| 12651 | |
| 12652 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12653 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12654 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 12655 | &mq_create_ext->u.request, mq->page_count); |
| 12656 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 12657 | &mq_create_ext->u.request, 1); |
| 12658 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12659 | &mq_create_ext->u.request, 1); |
| 12660 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 12661 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12662 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 12663 | &mq_create_ext->u.request, 1); |
| 12664 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 12665 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12666 | 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] | 12667 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12668 | phba->sli4_hba.pc_sli4_params.mqv); |
| 12669 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 12670 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 12671 | cq->queue_id); |
| 12672 | else |
| 12673 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 12674 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12675 | switch (mq->entry_count) { |
| 12676 | default: |
| 12677 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12678 | "0362 Unsupported MQ count. (%d)\n", |
| 12679 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12680 | if (mq->entry_count < 16) { |
| 12681 | status = -EINVAL; |
| 12682 | goto out; |
| 12683 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12684 | /* otherwise default to smallest count (drop through) */ |
| 12685 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12686 | bf_set(lpfc_mq_context_ring_size, |
| 12687 | &mq_create_ext->u.request.context, |
| 12688 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12689 | break; |
| 12690 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12691 | bf_set(lpfc_mq_context_ring_size, |
| 12692 | &mq_create_ext->u.request.context, |
| 12693 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12694 | break; |
| 12695 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12696 | bf_set(lpfc_mq_context_ring_size, |
| 12697 | &mq_create_ext->u.request.context, |
| 12698 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12699 | break; |
| 12700 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12701 | bf_set(lpfc_mq_context_ring_size, |
| 12702 | &mq_create_ext->u.request.context, |
| 12703 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12704 | break; |
| 12705 | } |
| 12706 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12707 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12708 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12709 | putPaddrLow(dmabuf->phys); |
| 12710 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12711 | putPaddrHigh(dmabuf->phys); |
| 12712 | } |
| 12713 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12714 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12715 | &mq_create_ext->u.response); |
| 12716 | if (rc != MBX_SUCCESS) { |
| 12717 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12718 | "2795 MQ_CREATE_EXT failed with " |
| 12719 | "status x%x. Failback to MQ_CREATE.\n", |
| 12720 | rc); |
| 12721 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 12722 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12723 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12724 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 12725 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12726 | &mq_create->u.response); |
| 12727 | } |
| 12728 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12729 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12730 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12731 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12732 | if (shdr_status || shdr_add_status || rc) { |
| 12733 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12734 | "2502 MQ_CREATE mailbox failed with " |
| 12735 | "status x%x add_status x%x, mbx status x%x\n", |
| 12736 | shdr_status, shdr_add_status, rc); |
| 12737 | status = -ENXIO; |
| 12738 | goto out; |
| 12739 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12740 | if (mq->queue_id == 0xFFFF) { |
| 12741 | status = -ENXIO; |
| 12742 | goto out; |
| 12743 | } |
| 12744 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12745 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12746 | mq->subtype = subtype; |
| 12747 | mq->host_index = 0; |
| 12748 | mq->hba_index = 0; |
| 12749 | |
| 12750 | /* link the mq onto the parent cq child list */ |
| 12751 | list_add_tail(&mq->list, &cq->child_list); |
| 12752 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12753 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12754 | return status; |
| 12755 | } |
| 12756 | |
| 12757 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12758 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 12759 | * @phba: HBA structure that indicates port to create a queue on. |
| 12760 | * @wq: The queue structure to use to create the work queue. |
| 12761 | * @cq: The completion queue to bind this work queue to. |
| 12762 | * @subtype: The subtype of the work queue indicating its functionality. |
| 12763 | * |
| 12764 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 12765 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 12766 | * |
| 12767 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 12768 | * is used to get the entry count and entry size that are necessary to |
| 12769 | * determine the number of pages to allocate and use for this queue. The @cq |
| 12770 | * is used to indicate which completion queue to bind this work queue to. This |
| 12771 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 12772 | * work queue. This function is asynchronous and will wait for the mailbox |
| 12773 | * command to finish before continuing. |
| 12774 | * |
| 12775 | * 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] | 12776 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12777 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12778 | **/ |
| 12779 | uint32_t |
| 12780 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 12781 | struct lpfc_queue *cq, uint32_t subtype) |
| 12782 | { |
| 12783 | struct lpfc_mbx_wq_create *wq_create; |
| 12784 | struct lpfc_dmabuf *dmabuf; |
| 12785 | LPFC_MBOXQ_t *mbox; |
| 12786 | int rc, length, status = 0; |
| 12787 | uint32_t shdr_status, shdr_add_status; |
| 12788 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12789 | 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] | 12790 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12791 | void __iomem *bar_memmap_p; |
| 12792 | uint32_t db_offset; |
| 12793 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12794 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12795 | /* sanity check on queue memory */ |
| 12796 | if (!wq || !cq) |
| 12797 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12798 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12799 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12800 | |
| 12801 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12802 | if (!mbox) |
| 12803 | return -ENOMEM; |
| 12804 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 12805 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12806 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12807 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 12808 | length, LPFC_SLI4_MBX_EMBED); |
| 12809 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12810 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12811 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 12812 | wq->page_count); |
| 12813 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 12814 | cq->queue_id); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12815 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12816 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12817 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12818 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { |
| 12819 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 12820 | wq->entry_count); |
| 12821 | switch (wq->entry_size) { |
| 12822 | default: |
| 12823 | case 64: |
| 12824 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12825 | &wq_create->u.request_1, |
| 12826 | LPFC_WQ_WQE_SIZE_64); |
| 12827 | break; |
| 12828 | case 128: |
| 12829 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12830 | &wq_create->u.request_1, |
| 12831 | LPFC_WQ_WQE_SIZE_128); |
| 12832 | break; |
| 12833 | } |
| 12834 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 12835 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 12836 | page = wq_create->u.request_1.page; |
| 12837 | } else { |
| 12838 | page = wq_create->u.request.page; |
| 12839 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12840 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12841 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12842 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 12843 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12844 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12845 | |
| 12846 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 12847 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 12848 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12849 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12850 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12851 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12852 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12853 | if (shdr_status || shdr_add_status || rc) { |
| 12854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12855 | "2503 WQ_CREATE mailbox failed with " |
| 12856 | "status x%x add_status x%x, mbx status x%x\n", |
| 12857 | shdr_status, shdr_add_status, rc); |
| 12858 | status = -ENXIO; |
| 12859 | goto out; |
| 12860 | } |
| 12861 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 12862 | if (wq->queue_id == 0xFFFF) { |
| 12863 | status = -ENXIO; |
| 12864 | goto out; |
| 12865 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12866 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 12867 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 12868 | &wq_create->u.response); |
| 12869 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 12870 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 12871 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12872 | "3265 WQ[%d] doorbell format not " |
| 12873 | "supported: x%x\n", wq->queue_id, |
| 12874 | wq->db_format); |
| 12875 | status = -EINVAL; |
| 12876 | goto out; |
| 12877 | } |
| 12878 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 12879 | &wq_create->u.response); |
| 12880 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 12881 | if (!bar_memmap_p) { |
| 12882 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12883 | "3263 WQ[%d] failed to memmap pci " |
| 12884 | "barset:x%x\n", wq->queue_id, |
| 12885 | pci_barset); |
| 12886 | status = -ENOMEM; |
| 12887 | goto out; |
| 12888 | } |
| 12889 | db_offset = wq_create->u.response.doorbell_offset; |
| 12890 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 12891 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 12892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12893 | "3252 WQ[%d] doorbell offset not " |
| 12894 | "supported: x%x\n", wq->queue_id, |
| 12895 | db_offset); |
| 12896 | status = -EINVAL; |
| 12897 | goto out; |
| 12898 | } |
| 12899 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 12900 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12901 | "3264 WQ[%d]: barset:x%x, offset:x%x\n", |
| 12902 | wq->queue_id, pci_barset, db_offset); |
| 12903 | } else { |
| 12904 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 12905 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 12906 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12907 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12908 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12909 | wq->subtype = subtype; |
| 12910 | wq->host_index = 0; |
| 12911 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12912 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12913 | |
| 12914 | /* link the wq onto the parent cq child list */ |
| 12915 | list_add_tail(&wq->list, &cq->child_list); |
| 12916 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12917 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12918 | return status; |
| 12919 | } |
| 12920 | |
| 12921 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12922 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 12923 | * @phba: HBA structure that indicates port to create a queue on. |
| 12924 | * @rq: The queue structure to use for the receive queue. |
| 12925 | * @qno: The associated HBQ number |
| 12926 | * |
| 12927 | * |
| 12928 | * For SLI4 we need to adjust the RQ repost value based on |
| 12929 | * the number of buffers that are initially posted to the RQ. |
| 12930 | */ |
| 12931 | void |
| 12932 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 12933 | { |
| 12934 | uint32_t cnt; |
| 12935 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12936 | /* sanity check on queue memory */ |
| 12937 | if (!rq) |
| 12938 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12939 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 12940 | |
| 12941 | /* Recalc repost for RQs based on buffers initially posted */ |
| 12942 | cnt = (cnt >> 3); |
| 12943 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 12944 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 12945 | |
| 12946 | rq->entry_repost = cnt; |
| 12947 | } |
| 12948 | |
| 12949 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12950 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 12951 | * @phba: HBA structure that indicates port to create a queue on. |
| 12952 | * @hrq: The queue structure to use to create the header receive queue. |
| 12953 | * @drq: The queue structure to use to create the data receive queue. |
| 12954 | * @cq: The completion queue to bind this work queue to. |
| 12955 | * |
| 12956 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 12957 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 12958 | * to the HBA. |
| 12959 | * |
| 12960 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 12961 | * struct is used to get the entry count that is necessary to determine the |
| 12962 | * number of pages to use for this queue. The @cq is used to indicate which |
| 12963 | * completion queue to bind received buffers that are posted to these queues to. |
| 12964 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 12965 | * receive queue pair. This function is asynchronous and will wait for the |
| 12966 | * mailbox command to finish before continuing. |
| 12967 | * |
| 12968 | * 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] | 12969 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12970 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12971 | **/ |
| 12972 | uint32_t |
| 12973 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 12974 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 12975 | { |
| 12976 | struct lpfc_mbx_rq_create *rq_create; |
| 12977 | struct lpfc_dmabuf *dmabuf; |
| 12978 | LPFC_MBOXQ_t *mbox; |
| 12979 | int rc, length, status = 0; |
| 12980 | uint32_t shdr_status, shdr_add_status; |
| 12981 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12982 | 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] | 12983 | void __iomem *bar_memmap_p; |
| 12984 | uint32_t db_offset; |
| 12985 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12986 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12987 | /* sanity check on queue memory */ |
| 12988 | if (!hrq || !drq || !cq) |
| 12989 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12990 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12991 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12992 | |
| 12993 | if (hrq->entry_count != drq->entry_count) |
| 12994 | return -EINVAL; |
| 12995 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12996 | if (!mbox) |
| 12997 | return -ENOMEM; |
| 12998 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 12999 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13000 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13001 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13002 | length, LPFC_SLI4_MBX_EMBED); |
| 13003 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13004 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13005 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13006 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13007 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13008 | bf_set(lpfc_rq_context_rqe_count_1, |
| 13009 | &rq_create->u.request.context, |
| 13010 | hrq->entry_count); |
| 13011 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13012 | bf_set(lpfc_rq_context_rqe_size, |
| 13013 | &rq_create->u.request.context, |
| 13014 | LPFC_RQE_SIZE_8); |
| 13015 | bf_set(lpfc_rq_context_page_size, |
| 13016 | &rq_create->u.request.context, |
| 13017 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13018 | } else { |
| 13019 | switch (hrq->entry_count) { |
| 13020 | default: |
| 13021 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13022 | "2535 Unsupported RQ count. (%d)\n", |
| 13023 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13024 | if (hrq->entry_count < 512) { |
| 13025 | status = -EINVAL; |
| 13026 | goto out; |
| 13027 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13028 | /* otherwise default to smallest count (drop through) */ |
| 13029 | case 512: |
| 13030 | bf_set(lpfc_rq_context_rqe_count, |
| 13031 | &rq_create->u.request.context, |
| 13032 | LPFC_RQ_RING_SIZE_512); |
| 13033 | break; |
| 13034 | case 1024: |
| 13035 | bf_set(lpfc_rq_context_rqe_count, |
| 13036 | &rq_create->u.request.context, |
| 13037 | LPFC_RQ_RING_SIZE_1024); |
| 13038 | break; |
| 13039 | case 2048: |
| 13040 | bf_set(lpfc_rq_context_rqe_count, |
| 13041 | &rq_create->u.request.context, |
| 13042 | LPFC_RQ_RING_SIZE_2048); |
| 13043 | break; |
| 13044 | case 4096: |
| 13045 | bf_set(lpfc_rq_context_rqe_count, |
| 13046 | &rq_create->u.request.context, |
| 13047 | LPFC_RQ_RING_SIZE_4096); |
| 13048 | break; |
| 13049 | } |
| 13050 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13051 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13052 | } |
| 13053 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13054 | cq->queue_id); |
| 13055 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13056 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13057 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13058 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13059 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13060 | putPaddrLow(dmabuf->phys); |
| 13061 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13062 | putPaddrHigh(dmabuf->phys); |
| 13063 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13064 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13065 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 13066 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13067 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13068 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13069 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13070 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13071 | if (shdr_status || shdr_add_status || rc) { |
| 13072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13073 | "2504 RQ_CREATE mailbox failed with " |
| 13074 | "status x%x add_status x%x, mbx status x%x\n", |
| 13075 | shdr_status, shdr_add_status, rc); |
| 13076 | status = -ENXIO; |
| 13077 | goto out; |
| 13078 | } |
| 13079 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13080 | if (hrq->queue_id == 0xFFFF) { |
| 13081 | status = -ENXIO; |
| 13082 | goto out; |
| 13083 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13084 | |
| 13085 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13086 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 13087 | &rq_create->u.response); |
| 13088 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13089 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13090 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13091 | "3262 RQ [%d] doorbell format not " |
| 13092 | "supported: x%x\n", hrq->queue_id, |
| 13093 | hrq->db_format); |
| 13094 | status = -EINVAL; |
| 13095 | goto out; |
| 13096 | } |
| 13097 | |
| 13098 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 13099 | &rq_create->u.response); |
| 13100 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13101 | if (!bar_memmap_p) { |
| 13102 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13103 | "3269 RQ[%d] failed to memmap pci " |
| 13104 | "barset:x%x\n", hrq->queue_id, |
| 13105 | pci_barset); |
| 13106 | status = -ENOMEM; |
| 13107 | goto out; |
| 13108 | } |
| 13109 | |
| 13110 | db_offset = rq_create->u.response.doorbell_offset; |
| 13111 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 13112 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 13113 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13114 | "3270 RQ[%d] doorbell offset not " |
| 13115 | "supported: x%x\n", hrq->queue_id, |
| 13116 | db_offset); |
| 13117 | status = -EINVAL; |
| 13118 | goto out; |
| 13119 | } |
| 13120 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 13121 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13122 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x\n", |
| 13123 | hrq->queue_id, pci_barset, db_offset); |
| 13124 | } else { |
| 13125 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 13126 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 13127 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13128 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13129 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13130 | hrq->subtype = subtype; |
| 13131 | hrq->host_index = 0; |
| 13132 | hrq->hba_index = 0; |
| 13133 | |
| 13134 | /* now create the data queue */ |
| 13135 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13136 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13137 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13138 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13139 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13140 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13141 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13142 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13143 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13144 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 13145 | LPFC_RQE_SIZE_8); |
| 13146 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 13147 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13148 | } else { |
| 13149 | switch (drq->entry_count) { |
| 13150 | default: |
| 13151 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13152 | "2536 Unsupported RQ count. (%d)\n", |
| 13153 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13154 | if (drq->entry_count < 512) { |
| 13155 | status = -EINVAL; |
| 13156 | goto out; |
| 13157 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13158 | /* otherwise default to smallest count (drop through) */ |
| 13159 | case 512: |
| 13160 | bf_set(lpfc_rq_context_rqe_count, |
| 13161 | &rq_create->u.request.context, |
| 13162 | LPFC_RQ_RING_SIZE_512); |
| 13163 | break; |
| 13164 | case 1024: |
| 13165 | bf_set(lpfc_rq_context_rqe_count, |
| 13166 | &rq_create->u.request.context, |
| 13167 | LPFC_RQ_RING_SIZE_1024); |
| 13168 | break; |
| 13169 | case 2048: |
| 13170 | bf_set(lpfc_rq_context_rqe_count, |
| 13171 | &rq_create->u.request.context, |
| 13172 | LPFC_RQ_RING_SIZE_2048); |
| 13173 | break; |
| 13174 | case 4096: |
| 13175 | bf_set(lpfc_rq_context_rqe_count, |
| 13176 | &rq_create->u.request.context, |
| 13177 | LPFC_RQ_RING_SIZE_4096); |
| 13178 | break; |
| 13179 | } |
| 13180 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13181 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13182 | } |
| 13183 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13184 | cq->queue_id); |
| 13185 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13186 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13187 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 13188 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13189 | putPaddrLow(dmabuf->phys); |
| 13190 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13191 | putPaddrHigh(dmabuf->phys); |
| 13192 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13193 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13194 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13195 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13196 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13197 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13198 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13199 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13200 | if (shdr_status || shdr_add_status || rc) { |
| 13201 | status = -ENXIO; |
| 13202 | goto out; |
| 13203 | } |
| 13204 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13205 | if (drq->queue_id == 0xFFFF) { |
| 13206 | status = -ENXIO; |
| 13207 | goto out; |
| 13208 | } |
| 13209 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13210 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13211 | drq->subtype = subtype; |
| 13212 | drq->host_index = 0; |
| 13213 | drq->hba_index = 0; |
| 13214 | |
| 13215 | /* link the header and data RQs onto the parent cq child list */ |
| 13216 | list_add_tail(&hrq->list, &cq->child_list); |
| 13217 | list_add_tail(&drq->list, &cq->child_list); |
| 13218 | |
| 13219 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13220 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13221 | return status; |
| 13222 | } |
| 13223 | |
| 13224 | /** |
| 13225 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 13226 | * @eq: The queue structure associated with the queue to destroy. |
| 13227 | * |
| 13228 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 13229 | * command, specific to the type of queue, to the HBA. |
| 13230 | * |
| 13231 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 13232 | * |
| 13233 | * 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] | 13234 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13235 | **/ |
| 13236 | uint32_t |
| 13237 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13238 | { |
| 13239 | LPFC_MBOXQ_t *mbox; |
| 13240 | int rc, length, status = 0; |
| 13241 | uint32_t shdr_status, shdr_add_status; |
| 13242 | union lpfc_sli4_cfg_shdr *shdr; |
| 13243 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13244 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13245 | if (!eq) |
| 13246 | return -ENODEV; |
| 13247 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13248 | if (!mbox) |
| 13249 | return -ENOMEM; |
| 13250 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 13251 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13252 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13253 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 13254 | length, LPFC_SLI4_MBX_EMBED); |
| 13255 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 13256 | eq->queue_id); |
| 13257 | mbox->vport = eq->phba->pport; |
| 13258 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13259 | |
| 13260 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 13261 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13262 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13263 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 13264 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13265 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13266 | if (shdr_status || shdr_add_status || rc) { |
| 13267 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13268 | "2505 EQ_DESTROY mailbox failed with " |
| 13269 | "status x%x add_status x%x, mbx status x%x\n", |
| 13270 | shdr_status, shdr_add_status, rc); |
| 13271 | status = -ENXIO; |
| 13272 | } |
| 13273 | |
| 13274 | /* Remove eq from any list */ |
| 13275 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13276 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13277 | return status; |
| 13278 | } |
| 13279 | |
| 13280 | /** |
| 13281 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 13282 | * @cq: The queue structure associated with the queue to destroy. |
| 13283 | * |
| 13284 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 13285 | * command, specific to the type of queue, to the HBA. |
| 13286 | * |
| 13287 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 13288 | * |
| 13289 | * 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] | 13290 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13291 | **/ |
| 13292 | uint32_t |
| 13293 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 13294 | { |
| 13295 | LPFC_MBOXQ_t *mbox; |
| 13296 | int rc, length, status = 0; |
| 13297 | uint32_t shdr_status, shdr_add_status; |
| 13298 | union lpfc_sli4_cfg_shdr *shdr; |
| 13299 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13300 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13301 | if (!cq) |
| 13302 | return -ENODEV; |
| 13303 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13304 | if (!mbox) |
| 13305 | return -ENOMEM; |
| 13306 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 13307 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13308 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13309 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 13310 | length, LPFC_SLI4_MBX_EMBED); |
| 13311 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 13312 | cq->queue_id); |
| 13313 | mbox->vport = cq->phba->pport; |
| 13314 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13315 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 13316 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13317 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13318 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 13319 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13320 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13321 | if (shdr_status || shdr_add_status || rc) { |
| 13322 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13323 | "2506 CQ_DESTROY mailbox failed with " |
| 13324 | "status x%x add_status x%x, mbx status x%x\n", |
| 13325 | shdr_status, shdr_add_status, rc); |
| 13326 | status = -ENXIO; |
| 13327 | } |
| 13328 | /* Remove cq from any list */ |
| 13329 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13330 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13331 | return status; |
| 13332 | } |
| 13333 | |
| 13334 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13335 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 13336 | * @qm: The queue structure associated with the queue to destroy. |
| 13337 | * |
| 13338 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 13339 | * command, specific to the type of queue, to the HBA. |
| 13340 | * |
| 13341 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 13342 | * |
| 13343 | * 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] | 13344 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13345 | **/ |
| 13346 | uint32_t |
| 13347 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 13348 | { |
| 13349 | LPFC_MBOXQ_t *mbox; |
| 13350 | int rc, length, status = 0; |
| 13351 | uint32_t shdr_status, shdr_add_status; |
| 13352 | union lpfc_sli4_cfg_shdr *shdr; |
| 13353 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13354 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13355 | if (!mq) |
| 13356 | return -ENODEV; |
| 13357 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13358 | if (!mbox) |
| 13359 | return -ENOMEM; |
| 13360 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 13361 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13362 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13363 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 13364 | length, LPFC_SLI4_MBX_EMBED); |
| 13365 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 13366 | mq->queue_id); |
| 13367 | mbox->vport = mq->phba->pport; |
| 13368 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13369 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 13370 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13371 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13372 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 13373 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13374 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13375 | if (shdr_status || shdr_add_status || rc) { |
| 13376 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13377 | "2507 MQ_DESTROY mailbox failed with " |
| 13378 | "status x%x add_status x%x, mbx status x%x\n", |
| 13379 | shdr_status, shdr_add_status, rc); |
| 13380 | status = -ENXIO; |
| 13381 | } |
| 13382 | /* Remove mq from any list */ |
| 13383 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13384 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13385 | return status; |
| 13386 | } |
| 13387 | |
| 13388 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13389 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 13390 | * @wq: The queue structure associated with the queue to destroy. |
| 13391 | * |
| 13392 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 13393 | * command, specific to the type of queue, to the HBA. |
| 13394 | * |
| 13395 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 13396 | * |
| 13397 | * 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] | 13398 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13399 | **/ |
| 13400 | uint32_t |
| 13401 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 13402 | { |
| 13403 | LPFC_MBOXQ_t *mbox; |
| 13404 | int rc, length, status = 0; |
| 13405 | uint32_t shdr_status, shdr_add_status; |
| 13406 | union lpfc_sli4_cfg_shdr *shdr; |
| 13407 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13408 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13409 | if (!wq) |
| 13410 | return -ENODEV; |
| 13411 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13412 | if (!mbox) |
| 13413 | return -ENOMEM; |
| 13414 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 13415 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13416 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13417 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 13418 | length, LPFC_SLI4_MBX_EMBED); |
| 13419 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 13420 | wq->queue_id); |
| 13421 | mbox->vport = wq->phba->pport; |
| 13422 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13423 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 13424 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13425 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 13426 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13427 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13428 | if (shdr_status || shdr_add_status || rc) { |
| 13429 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13430 | "2508 WQ_DESTROY mailbox failed with " |
| 13431 | "status x%x add_status x%x, mbx status x%x\n", |
| 13432 | shdr_status, shdr_add_status, rc); |
| 13433 | status = -ENXIO; |
| 13434 | } |
| 13435 | /* Remove wq from any list */ |
| 13436 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13437 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13438 | return status; |
| 13439 | } |
| 13440 | |
| 13441 | /** |
| 13442 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 13443 | * @rq: The queue structure associated with the queue to destroy. |
| 13444 | * |
| 13445 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 13446 | * command, specific to the type of queue, to the HBA. |
| 13447 | * |
| 13448 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 13449 | * |
| 13450 | * 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] | 13451 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13452 | **/ |
| 13453 | uint32_t |
| 13454 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13455 | struct lpfc_queue *drq) |
| 13456 | { |
| 13457 | LPFC_MBOXQ_t *mbox; |
| 13458 | int rc, length, status = 0; |
| 13459 | uint32_t shdr_status, shdr_add_status; |
| 13460 | union lpfc_sli4_cfg_shdr *shdr; |
| 13461 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13462 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13463 | if (!hrq || !drq) |
| 13464 | return -ENODEV; |
| 13465 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13466 | if (!mbox) |
| 13467 | return -ENOMEM; |
| 13468 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13469 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13470 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13471 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 13472 | length, LPFC_SLI4_MBX_EMBED); |
| 13473 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13474 | hrq->queue_id); |
| 13475 | mbox->vport = hrq->phba->pport; |
| 13476 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13477 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 13478 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13479 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13480 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13481 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13482 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13483 | if (shdr_status || shdr_add_status || rc) { |
| 13484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13485 | "2509 RQ_DESTROY mailbox failed with " |
| 13486 | "status x%x add_status x%x, mbx status x%x\n", |
| 13487 | shdr_status, shdr_add_status, rc); |
| 13488 | if (rc != MBX_TIMEOUT) |
| 13489 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 13490 | return -ENXIO; |
| 13491 | } |
| 13492 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13493 | drq->queue_id); |
| 13494 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 13495 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13496 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13497 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13498 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13499 | if (shdr_status || shdr_add_status || rc) { |
| 13500 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13501 | "2510 RQ_DESTROY mailbox failed with " |
| 13502 | "status x%x add_status x%x, mbx status x%x\n", |
| 13503 | shdr_status, shdr_add_status, rc); |
| 13504 | status = -ENXIO; |
| 13505 | } |
| 13506 | list_del_init(&hrq->list); |
| 13507 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13508 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13509 | return status; |
| 13510 | } |
| 13511 | |
| 13512 | /** |
| 13513 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 13514 | * @phba: The virtual port for which this call being executed. |
| 13515 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 13516 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 13517 | * @xritag: the xritag that ties this io to the SGL pages. |
| 13518 | * |
| 13519 | * This routine will post the sgl pages for the IO that has the xritag |
| 13520 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 13521 | * creation and persists for as long as the driver is loaded. |
| 13522 | * if the caller has fewer than 256 scatter gather segments to map then |
| 13523 | * pdma_phys_addr1 should be 0. |
| 13524 | * If the caller needs to map more than 256 scatter gather segment then |
| 13525 | * pdma_phys_addr1 should be a valid physical address. |
| 13526 | * physical address for SGLs must be 64 byte aligned. |
| 13527 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 13528 | * the second sgl can have between 1 and 256 entries. |
| 13529 | * |
| 13530 | * Return codes: |
| 13531 | * 0 - Success |
| 13532 | * -ENXIO, -ENOMEM - Failure |
| 13533 | **/ |
| 13534 | int |
| 13535 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 13536 | dma_addr_t pdma_phys_addr0, |
| 13537 | dma_addr_t pdma_phys_addr1, |
| 13538 | uint16_t xritag) |
| 13539 | { |
| 13540 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 13541 | LPFC_MBOXQ_t *mbox; |
| 13542 | int rc; |
| 13543 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13544 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13545 | union lpfc_sli4_cfg_shdr *shdr; |
| 13546 | |
| 13547 | if (xritag == NO_XRI) { |
| 13548 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13549 | "0364 Invalid param:\n"); |
| 13550 | return -EINVAL; |
| 13551 | } |
| 13552 | |
| 13553 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13554 | if (!mbox) |
| 13555 | return -ENOMEM; |
| 13556 | |
| 13557 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13558 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13559 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13560 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13561 | |
| 13562 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 13563 | &mbox->u.mqe.un.post_sgl_pages; |
| 13564 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 13565 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 13566 | |
| 13567 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 13568 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 13569 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 13570 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 13571 | |
| 13572 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 13573 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 13574 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 13575 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 13576 | if (!phba->sli4_hba.intr_enable) |
| 13577 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13578 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13579 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13580 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13581 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13582 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13583 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 13584 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13585 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13586 | if (rc != MBX_TIMEOUT) |
| 13587 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13588 | if (shdr_status || shdr_add_status || rc) { |
| 13589 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13590 | "2511 POST_SGL mailbox failed with " |
| 13591 | "status x%x add_status x%x, mbx status x%x\n", |
| 13592 | shdr_status, shdr_add_status, rc); |
| 13593 | rc = -ENXIO; |
| 13594 | } |
| 13595 | return 0; |
| 13596 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13597 | |
| 13598 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13599 | * 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] | 13600 | * @phba: pointer to lpfc hba data structure. |
| 13601 | * |
| 13602 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13603 | * HBA consistent with the SLI-4 interface spec. This routine |
| 13604 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 13605 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13606 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13607 | * Returns |
| 13608 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 13609 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 13610 | **/ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13611 | uint16_t |
| 13612 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 13613 | { |
| 13614 | unsigned long xri; |
| 13615 | |
| 13616 | /* |
| 13617 | * Fetch the next logical xri. Because this index is logical, |
| 13618 | * the driver starts at 0 each time. |
| 13619 | */ |
| 13620 | spin_lock_irq(&phba->hbalock); |
| 13621 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 13622 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 13623 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 13624 | spin_unlock_irq(&phba->hbalock); |
| 13625 | return NO_XRI; |
| 13626 | } else { |
| 13627 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 13628 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13629 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13630 | spin_unlock_irq(&phba->hbalock); |
| 13631 | return xri; |
| 13632 | } |
| 13633 | |
| 13634 | /** |
| 13635 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13636 | * @phba: pointer to lpfc hba data structure. |
| 13637 | * |
| 13638 | * This routine is invoked to release an xri to the pool of |
| 13639 | * available rpis maintained by the driver. |
| 13640 | **/ |
| 13641 | void |
| 13642 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13643 | { |
| 13644 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13645 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 13646 | } |
| 13647 | } |
| 13648 | |
| 13649 | /** |
| 13650 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13651 | * @phba: pointer to lpfc hba data structure. |
| 13652 | * |
| 13653 | * This routine is invoked to release an xri to the pool of |
| 13654 | * available rpis maintained by the driver. |
| 13655 | **/ |
| 13656 | void |
| 13657 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13658 | { |
| 13659 | spin_lock_irq(&phba->hbalock); |
| 13660 | __lpfc_sli4_free_xri(phba, xri); |
| 13661 | spin_unlock_irq(&phba->hbalock); |
| 13662 | } |
| 13663 | |
| 13664 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13665 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 13666 | * @phba: Pointer to HBA context object. |
| 13667 | * |
| 13668 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 13669 | * it will return 0xffff. |
| 13670 | * The function returns the allocated xritag if successful, else returns zero. |
| 13671 | * Zero is not a valid xritag. |
| 13672 | * The caller is not required to hold any lock. |
| 13673 | **/ |
| 13674 | uint16_t |
| 13675 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 13676 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13677 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13678 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13679 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 13680 | if (xri_index == NO_XRI) |
| 13681 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13682 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 13683 | " Max XRI is %d, Used XRI is %d\n", |
| 13684 | xri_index, |
| 13685 | phba->sli4_hba.max_cfg_param.max_xri, |
| 13686 | phba->sli4_hba.max_cfg_param.xri_used); |
| 13687 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13688 | } |
| 13689 | |
| 13690 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13691 | * 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] | 13692 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13693 | * @post_sgl_list: pointer to els sgl entry list. |
| 13694 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13695 | * |
| 13696 | * This routine is invoked to post a block of driver's sgl pages to the |
| 13697 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 13698 | * is only called when the driver is loading and after all IO has been |
| 13699 | * stopped. |
| 13700 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13701 | static int |
| 13702 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 13703 | struct list_head *post_sgl_list, |
| 13704 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13705 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13706 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13707 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13708 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13709 | void *viraddr; |
| 13710 | LPFC_MBOXQ_t *mbox; |
| 13711 | uint32_t reqlen, alloclen, pg_pairs; |
| 13712 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13713 | uint16_t xritag_start = 0; |
| 13714 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13715 | uint32_t shdr_status, shdr_add_status; |
| 13716 | union lpfc_sli4_cfg_shdr *shdr; |
| 13717 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13718 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13719 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13720 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13721 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13722 | "2559 Block sgl registration required DMA " |
| 13723 | "size (%d) great than a page\n", reqlen); |
| 13724 | return -ENOMEM; |
| 13725 | } |
| 13726 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13727 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13728 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13729 | |
| 13730 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13731 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13732 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13733 | LPFC_SLI4_MBX_NEMBED); |
| 13734 | |
| 13735 | if (alloclen < reqlen) { |
| 13736 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13737 | "0285 Allocated DMA memory size (%d) is " |
| 13738 | "less than the requested DMA memory " |
| 13739 | "size (%d)\n", alloclen, reqlen); |
| 13740 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13741 | return -ENOMEM; |
| 13742 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13743 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13744 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13745 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13746 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13747 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13748 | pg_pairs = 0; |
| 13749 | 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] | 13750 | /* Set up the sge entry */ |
| 13751 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13752 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 13753 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13754 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 13755 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13756 | cpu_to_le32(putPaddrLow(0)); |
| 13757 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13758 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13759 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13760 | /* Keep the first xritag on the list */ |
| 13761 | if (pg_pairs == 0) |
| 13762 | xritag_start = sglq_entry->sli4_xritag; |
| 13763 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13764 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13765 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13766 | |
| 13767 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13768 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13769 | 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] | 13770 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13771 | if (!phba->sli4_hba.intr_enable) |
| 13772 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13773 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13774 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13775 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13776 | } |
| 13777 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13778 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13779 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13780 | if (rc != MBX_TIMEOUT) |
| 13781 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13782 | if (shdr_status || shdr_add_status || rc) { |
| 13783 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13784 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 13785 | "status x%x add_status x%x mbx status x%x\n", |
| 13786 | shdr_status, shdr_add_status, rc); |
| 13787 | rc = -ENXIO; |
| 13788 | } |
| 13789 | return rc; |
| 13790 | } |
| 13791 | |
| 13792 | /** |
| 13793 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 13794 | * @phba: pointer to lpfc hba data structure. |
| 13795 | * @sblist: pointer to scsi buffer list. |
| 13796 | * @count: number of scsi buffers on the list. |
| 13797 | * |
| 13798 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 13799 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 13800 | * No Lock is held. |
| 13801 | * |
| 13802 | **/ |
| 13803 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13804 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 13805 | struct list_head *sblist, |
| 13806 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13807 | { |
| 13808 | struct lpfc_scsi_buf *psb; |
| 13809 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13810 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13811 | void *viraddr; |
| 13812 | LPFC_MBOXQ_t *mbox; |
| 13813 | uint32_t reqlen, alloclen, pg_pairs; |
| 13814 | uint32_t mbox_tmo; |
| 13815 | uint16_t xritag_start = 0; |
| 13816 | int rc = 0; |
| 13817 | uint32_t shdr_status, shdr_add_status; |
| 13818 | dma_addr_t pdma_phys_bpl1; |
| 13819 | union lpfc_sli4_cfg_shdr *shdr; |
| 13820 | |
| 13821 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13822 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13823 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13824 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13825 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13826 | "0217 Block sgl registration required DMA " |
| 13827 | "size (%d) great than a page\n", reqlen); |
| 13828 | return -ENOMEM; |
| 13829 | } |
| 13830 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13831 | if (!mbox) { |
| 13832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13833 | "0283 Failed to allocate mbox cmd memory\n"); |
| 13834 | return -ENOMEM; |
| 13835 | } |
| 13836 | |
| 13837 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13838 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13839 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13840 | LPFC_SLI4_MBX_NEMBED); |
| 13841 | |
| 13842 | if (alloclen < reqlen) { |
| 13843 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13844 | "2561 Allocated DMA memory size (%d) is " |
| 13845 | "less than the requested DMA memory " |
| 13846 | "size (%d)\n", alloclen, reqlen); |
| 13847 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13848 | return -ENOMEM; |
| 13849 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13850 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13851 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13852 | viraddr = mbox->sge_array->addr[0]; |
| 13853 | |
| 13854 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 13855 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13856 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13857 | |
| 13858 | pg_pairs = 0; |
| 13859 | list_for_each_entry(psb, sblist, list) { |
| 13860 | /* Set up the sge entry */ |
| 13861 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13862 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 13863 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13864 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 13865 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 13866 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 13867 | else |
| 13868 | pdma_phys_bpl1 = 0; |
| 13869 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13870 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 13871 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13872 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 13873 | /* Keep the first xritag on the list */ |
| 13874 | if (pg_pairs == 0) |
| 13875 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 13876 | sgl_pg_pairs++; |
| 13877 | pg_pairs++; |
| 13878 | } |
| 13879 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 13880 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 13881 | /* Perform endian conversion if necessary */ |
| 13882 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 13883 | |
| 13884 | if (!phba->sli4_hba.intr_enable) |
| 13885 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13886 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13887 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13888 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13889 | } |
| 13890 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13891 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13892 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13893 | if (rc != MBX_TIMEOUT) |
| 13894 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13895 | if (shdr_status || shdr_add_status || rc) { |
| 13896 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13897 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 13898 | "status x%x add_status x%x mbx status x%x\n", |
| 13899 | shdr_status, shdr_add_status, rc); |
| 13900 | rc = -ENXIO; |
| 13901 | } |
| 13902 | return rc; |
| 13903 | } |
| 13904 | |
| 13905 | /** |
| 13906 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 13907 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 13908 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13909 | * |
| 13910 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 13911 | * valid type of frame that the LPFC driver will handle. This function will |
| 13912 | * return a zero if the frame is a valid frame or a non zero value when the |
| 13913 | * frame does not pass the check. |
| 13914 | **/ |
| 13915 | static int |
| 13916 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 13917 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 13918 | /* make rctl_names static to save stack space */ |
| 13919 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13920 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 13921 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13922 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13923 | |
| 13924 | switch (fc_hdr->fh_r_ctl) { |
| 13925 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 13926 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 13927 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 13928 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 13929 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 13930 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 13931 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 13932 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 13933 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 13934 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 13935 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 13936 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 13937 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 13938 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 13939 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 13940 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 13941 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 13942 | case FC_RCTL_BA_PRMT: |
| 13943 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 13944 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 13945 | case FC_RCTL_P_RJT: /* port reject */ |
| 13946 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 13947 | case FC_RCTL_P_BSY: /* port busy */ |
| 13948 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 13949 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 13950 | case FC_RCTL_LCR: /* link credit reset */ |
| 13951 | case FC_RCTL_END: /* end */ |
| 13952 | break; |
| 13953 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 13954 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13955 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 13956 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 13957 | default: |
| 13958 | goto drop; |
| 13959 | } |
| 13960 | switch (fc_hdr->fh_type) { |
| 13961 | case FC_TYPE_BLS: |
| 13962 | case FC_TYPE_ELS: |
| 13963 | case FC_TYPE_FCP: |
| 13964 | case FC_TYPE_CT: |
| 13965 | break; |
| 13966 | case FC_TYPE_IP: |
| 13967 | case FC_TYPE_ILS: |
| 13968 | default: |
| 13969 | goto drop; |
| 13970 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13971 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13972 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13973 | "2538 Received frame rctl:%s type:%s " |
| 13974 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13975 | rctl_names[fc_hdr->fh_r_ctl], |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13976 | type_names[fc_hdr->fh_type], |
| 13977 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 13978 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 13979 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13980 | return 0; |
| 13981 | drop: |
| 13982 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 13983 | "2539 Dropped frame rctl:%s type:%s\n", |
| 13984 | rctl_names[fc_hdr->fh_r_ctl], |
| 13985 | type_names[fc_hdr->fh_type]); |
| 13986 | return 1; |
| 13987 | } |
| 13988 | |
| 13989 | /** |
| 13990 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 13991 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13992 | * |
| 13993 | * This function processes the FC header to retrieve the VFI from the VF |
| 13994 | * header, if one exists. This function will return the VFI if one exists |
| 13995 | * or 0 if no VSAN Header exists. |
| 13996 | **/ |
| 13997 | static uint32_t |
| 13998 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 13999 | { |
| 14000 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14001 | |
| 14002 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 14003 | return 0; |
| 14004 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 14005 | } |
| 14006 | |
| 14007 | /** |
| 14008 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 14009 | * @phba: Pointer to the HBA structure to search for the vport on |
| 14010 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14011 | * @fcfi: The FC Fabric ID that the frame came from |
| 14012 | * |
| 14013 | * This function searches the @phba for a vport that matches the content of the |
| 14014 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 14015 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 14016 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 14017 | * vport. |
| 14018 | **/ |
| 14019 | static struct lpfc_vport * |
| 14020 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 14021 | uint16_t fcfi) |
| 14022 | { |
| 14023 | struct lpfc_vport **vports; |
| 14024 | struct lpfc_vport *vport = NULL; |
| 14025 | int i; |
| 14026 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 14027 | fc_hdr->fh_d_id[1] << 8 | |
| 14028 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14029 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 14030 | if (did == Fabric_DID) |
| 14031 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14032 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 14033 | !(phba->link_state == LPFC_HBA_READY)) |
| 14034 | return phba->pport; |
| 14035 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14036 | vports = lpfc_create_vport_work_array(phba); |
| 14037 | if (vports != NULL) |
| 14038 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 14039 | if (phba->fcf.fcfi == fcfi && |
| 14040 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 14041 | vports[i]->fc_myDID == did) { |
| 14042 | vport = vports[i]; |
| 14043 | break; |
| 14044 | } |
| 14045 | } |
| 14046 | lpfc_destroy_vport_work_array(phba, vports); |
| 14047 | return vport; |
| 14048 | } |
| 14049 | |
| 14050 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14051 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 14052 | * @vport: The vport to work on. |
| 14053 | * |
| 14054 | * This function updates the receive sequence time stamp for this vport. The |
| 14055 | * receive sequence time stamp indicates the time that the last frame of the |
| 14056 | * the sequence that has been idle for the longest amount of time was received. |
| 14057 | * the driver uses this time stamp to indicate if any received sequences have |
| 14058 | * timed out. |
| 14059 | **/ |
| 14060 | void |
| 14061 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 14062 | { |
| 14063 | struct lpfc_dmabuf *h_buf; |
| 14064 | struct hbq_dmabuf *dmabuf = NULL; |
| 14065 | |
| 14066 | /* get the oldest sequence on the rcv list */ |
| 14067 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 14068 | struct lpfc_dmabuf, list); |
| 14069 | if (!h_buf) |
| 14070 | return; |
| 14071 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14072 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 14073 | } |
| 14074 | |
| 14075 | /** |
| 14076 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 14077 | * @vport: The vport that the received sequences were sent to. |
| 14078 | * |
| 14079 | * This function cleans up all outstanding received sequences. This is called |
| 14080 | * by the driver when a link event or user action invalidates all the received |
| 14081 | * sequences. |
| 14082 | **/ |
| 14083 | void |
| 14084 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 14085 | { |
| 14086 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14087 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14088 | struct hbq_dmabuf *dmabuf = NULL; |
| 14089 | |
| 14090 | /* start with the oldest sequence on the rcv list */ |
| 14091 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14092 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14093 | list_del_init(&dmabuf->hbuf.list); |
| 14094 | list_for_each_entry_safe(d_buf, dnext, |
| 14095 | &dmabuf->dbuf.list, list) { |
| 14096 | list_del_init(&d_buf->list); |
| 14097 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14098 | } |
| 14099 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14100 | } |
| 14101 | } |
| 14102 | |
| 14103 | /** |
| 14104 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 14105 | * @vport: The vport that the received sequences were sent to. |
| 14106 | * |
| 14107 | * This function determines whether any received sequences have timed out by |
| 14108 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 14109 | * indicates that there is at least one timed out sequence this routine will |
| 14110 | * go through the received sequences one at a time from most inactive to most |
| 14111 | * active to determine which ones need to be cleaned up. Once it has determined |
| 14112 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 14113 | * without sending an abort. |
| 14114 | **/ |
| 14115 | void |
| 14116 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 14117 | { |
| 14118 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14119 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14120 | struct hbq_dmabuf *dmabuf = NULL; |
| 14121 | unsigned long timeout; |
| 14122 | int abort_count = 0; |
| 14123 | |
| 14124 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 14125 | vport->rcv_buffer_time_stamp); |
| 14126 | if (list_empty(&vport->rcv_buffer_list) || |
| 14127 | time_before(jiffies, timeout)) |
| 14128 | return; |
| 14129 | /* start with the oldest sequence on the rcv list */ |
| 14130 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14131 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14132 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 14133 | dmabuf->time_stamp); |
| 14134 | if (time_before(jiffies, timeout)) |
| 14135 | break; |
| 14136 | abort_count++; |
| 14137 | list_del_init(&dmabuf->hbuf.list); |
| 14138 | list_for_each_entry_safe(d_buf, dnext, |
| 14139 | &dmabuf->dbuf.list, list) { |
| 14140 | list_del_init(&d_buf->list); |
| 14141 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14142 | } |
| 14143 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14144 | } |
| 14145 | if (abort_count) |
| 14146 | lpfc_update_rcv_time_stamp(vport); |
| 14147 | } |
| 14148 | |
| 14149 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14150 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 14151 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 14152 | * |
| 14153 | * This function searches through the existing incomplete sequences that have |
| 14154 | * been sent to this @vport. If the frame matches one of the incomplete |
| 14155 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 14156 | * make up that sequence. If no sequence is found that matches this frame then |
| 14157 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 14158 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 14159 | * the frame was linked to. |
| 14160 | **/ |
| 14161 | static struct hbq_dmabuf * |
| 14162 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 14163 | { |
| 14164 | struct fc_frame_header *new_hdr; |
| 14165 | struct fc_frame_header *temp_hdr; |
| 14166 | struct lpfc_dmabuf *d_buf; |
| 14167 | struct lpfc_dmabuf *h_buf; |
| 14168 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14169 | struct hbq_dmabuf *temp_dmabuf = NULL; |
| 14170 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14171 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14172 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14173 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14174 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 14175 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14176 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14177 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14178 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14179 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14180 | continue; |
| 14181 | /* found a pending sequence that matches this frame */ |
| 14182 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14183 | break; |
| 14184 | } |
| 14185 | if (!seq_dmabuf) { |
| 14186 | /* |
| 14187 | * This indicates first frame received for this sequence. |
| 14188 | * Queue the buffer on the vport's rcv_buffer_list. |
| 14189 | */ |
| 14190 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14191 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14192 | return dmabuf; |
| 14193 | } |
| 14194 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14195 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 14196 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14197 | list_del_init(&seq_dmabuf->hbuf.list); |
| 14198 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 14199 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14200 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14201 | return dmabuf; |
| 14202 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14203 | /* move this sequence to the tail to indicate a young sequence */ |
| 14204 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 14205 | seq_dmabuf->time_stamp = jiffies; |
| 14206 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14207 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 14208 | temp_hdr = dmabuf->hbuf.virt; |
| 14209 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 14210 | return seq_dmabuf; |
| 14211 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14212 | /* find the correct place in the sequence to insert this frame */ |
| 14213 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { |
| 14214 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14215 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 14216 | /* |
| 14217 | * If the frame's sequence count is greater than the frame on |
| 14218 | * the list then insert the frame right after this frame |
| 14219 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14220 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 14221 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14222 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
| 14223 | return seq_dmabuf; |
| 14224 | } |
| 14225 | } |
| 14226 | return NULL; |
| 14227 | } |
| 14228 | |
| 14229 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14230 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 14231 | * @vport: pointer to a vitural port |
| 14232 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14233 | * |
| 14234 | * This function tries to abort from the partially assembed sequence, described |
| 14235 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 14236 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 14237 | * the frames from the partially assembled sequence. |
| 14238 | * |
| 14239 | * Return |
| 14240 | * true -- if there is matching partially assembled sequence present and all |
| 14241 | * the frames freed with the sequence; |
| 14242 | * false -- if there is no matching partially assembled sequence present so |
| 14243 | * nothing got aborted in the lower layer driver |
| 14244 | **/ |
| 14245 | static bool |
| 14246 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 14247 | struct hbq_dmabuf *dmabuf) |
| 14248 | { |
| 14249 | struct fc_frame_header *new_hdr; |
| 14250 | struct fc_frame_header *temp_hdr; |
| 14251 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 14252 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14253 | |
| 14254 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 14255 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 14256 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 14257 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14258 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14259 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14260 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14261 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14262 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14263 | continue; |
| 14264 | /* found a pending sequence that matches this frame */ |
| 14265 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14266 | break; |
| 14267 | } |
| 14268 | |
| 14269 | /* Free up all the frames from the partially assembled sequence */ |
| 14270 | if (seq_dmabuf) { |
| 14271 | list_for_each_entry_safe(d_buf, n_buf, |
| 14272 | &seq_dmabuf->dbuf.list, list) { |
| 14273 | list_del_init(&d_buf->list); |
| 14274 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14275 | } |
| 14276 | return true; |
| 14277 | } |
| 14278 | return false; |
| 14279 | } |
| 14280 | |
| 14281 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14282 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 14283 | * @vport: pointer to a vitural port |
| 14284 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14285 | * |
| 14286 | * This function tries to abort from the assembed sequence from upper level |
| 14287 | * protocol, described by the information from basic abbort @dmabuf. It |
| 14288 | * checks to see whether such pending context exists at upper level protocol. |
| 14289 | * If so, it shall clean up the pending context. |
| 14290 | * |
| 14291 | * Return |
| 14292 | * true -- if there is matching pending context of the sequence cleaned |
| 14293 | * at ulp; |
| 14294 | * false -- if there is no matching pending context of the sequence present |
| 14295 | * at ulp. |
| 14296 | **/ |
| 14297 | static bool |
| 14298 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 14299 | { |
| 14300 | struct lpfc_hba *phba = vport->phba; |
| 14301 | int handled; |
| 14302 | |
| 14303 | /* Accepting abort at ulp with SLI4 only */ |
| 14304 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 14305 | return false; |
| 14306 | |
| 14307 | /* Register all caring upper level protocols to attend abort */ |
| 14308 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 14309 | if (handled) |
| 14310 | return true; |
| 14311 | |
| 14312 | return false; |
| 14313 | } |
| 14314 | |
| 14315 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14316 | * 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] | 14317 | * @phba: Pointer to HBA context object. |
| 14318 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 14319 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 14320 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14321 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14322 | * event. It properly releases the memory allocated to the sequence abort |
| 14323 | * accept iocb. |
| 14324 | **/ |
| 14325 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14326 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14327 | struct lpfc_iocbq *cmd_iocbq, |
| 14328 | struct lpfc_iocbq *rsp_iocbq) |
| 14329 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14330 | struct lpfc_nodelist *ndlp; |
| 14331 | |
| 14332 | if (cmd_iocbq) { |
| 14333 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 14334 | lpfc_nlp_put(ndlp); |
| 14335 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14336 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14337 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14338 | |
| 14339 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 14340 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 14341 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14342 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 14343 | rsp_iocbq->iocb.ulpStatus, |
| 14344 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14345 | } |
| 14346 | |
| 14347 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14348 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 14349 | * @phba: Pointer to HBA context object. |
| 14350 | * @xri: xri id in transaction. |
| 14351 | * |
| 14352 | * This function validates the xri maps to the known range of XRIs allocated an |
| 14353 | * used by the driver. |
| 14354 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14355 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14356 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 14357 | uint16_t xri) |
| 14358 | { |
| 14359 | int i; |
| 14360 | |
| 14361 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 14362 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 14363 | return i; |
| 14364 | } |
| 14365 | return NO_XRI; |
| 14366 | } |
| 14367 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14368 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14369 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14370 | * @phba: Pointer to HBA context object. |
| 14371 | * @fc_hdr: pointer to a FC frame header. |
| 14372 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14373 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14374 | * event after aborting the sequence handling. |
| 14375 | **/ |
| 14376 | static void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14377 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 14378 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14379 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14380 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14381 | struct lpfc_iocbq *ctiocb = NULL; |
| 14382 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14383 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14384 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14385 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14386 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14387 | |
| 14388 | if (!lpfc_is_link_up(phba)) |
| 14389 | return; |
| 14390 | |
| 14391 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 14392 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14393 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14394 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14395 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14396 | if (!ndlp) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14397 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 14398 | if (!ndlp) { |
| 14399 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 14400 | "1268 Failed to allocate ndlp for " |
| 14401 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 14402 | return; |
| 14403 | } |
| 14404 | lpfc_nlp_init(vport, ndlp, sid); |
| 14405 | /* Put ndlp onto pport node list */ |
| 14406 | lpfc_enqueue_node(vport, ndlp); |
| 14407 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 14408 | /* re-setup ndlp without removing from node list */ |
| 14409 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 14410 | if (!ndlp) { |
| 14411 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 14412 | "3275 Failed to active ndlp found " |
| 14413 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 14414 | return; |
| 14415 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14416 | } |
| 14417 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14418 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14419 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 14420 | if (!ctiocb) |
| 14421 | return; |
| 14422 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14423 | /* Extract the F_CTL field from FC_HDR */ |
| 14424 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 14425 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14426 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14427 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14428 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14429 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 14430 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 14431 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 14432 | |
| 14433 | /* Fill in the rest of iocb fields */ |
| 14434 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 14435 | icmd->ulpBdeCount = 0; |
| 14436 | icmd->ulpLe = 1; |
| 14437 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14438 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14439 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14440 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14441 | ctiocb->iocb_cmpl = NULL; |
| 14442 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14443 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14444 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14445 | ctiocb->sli4_xritag = NO_XRI; |
| 14446 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14447 | if (fctl & FC_FC_EX_CTX) |
| 14448 | /* Exchange responder sent the abort so we |
| 14449 | * own the oxid. |
| 14450 | */ |
| 14451 | xri = oxid; |
| 14452 | else |
| 14453 | xri = rxid; |
| 14454 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 14455 | if (lxri != NO_XRI) |
| 14456 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 14457 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14458 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 14459 | * the oxid maps to the FCP XRI range, the port no longer has |
| 14460 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 14461 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14462 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14463 | if ((fctl & FC_FC_EX_CTX) && |
| 14464 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { |
| 14465 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14466 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14467 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14468 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14469 | } |
| 14470 | |
| 14471 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 14472 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 14473 | * the IOCB for a BA_RJT. |
| 14474 | */ |
| 14475 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14476 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14477 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14478 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14479 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14480 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14481 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14482 | if (fctl & FC_FC_EX_CTX) { |
| 14483 | /* ABTS sent by responder to CT exchange, construction |
| 14484 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 14485 | * field and RX_ID from ABTS for RX_ID field. |
| 14486 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14487 | 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] | 14488 | } else { |
| 14489 | /* ABTS sent by initiator to CT exchange, construction |
| 14490 | * 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] | 14491 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14492 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14493 | 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] | 14494 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14495 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14496 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14497 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14498 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14499 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 14500 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 14501 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14502 | |
| 14503 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 14504 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14505 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 14506 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 14507 | "xri x%x, Data x%x\n", |
| 14508 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 14509 | phba->link_state); |
| 14510 | lpfc_nlp_put(ndlp); |
| 14511 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14512 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 14513 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14514 | } |
| 14515 | |
| 14516 | /** |
| 14517 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 14518 | * @vport: Pointer to the vport on which this sequence was received |
| 14519 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14520 | * |
| 14521 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 14522 | * receive sequence is only partially assembed by the driver, it shall abort |
| 14523 | * the partially assembled frames for the sequence. Otherwise, if the |
| 14524 | * unsolicited receive sequence has been completely assembled and passed to |
| 14525 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 14526 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 14527 | * accept to accept the abort. |
| 14528 | **/ |
| 14529 | void |
| 14530 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 14531 | struct hbq_dmabuf *dmabuf) |
| 14532 | { |
| 14533 | struct lpfc_hba *phba = vport->phba; |
| 14534 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14535 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14536 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14537 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14538 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 14539 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14540 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14541 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14542 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14543 | /* ABTS by responder to exchange, no cleanup needed */ |
| 14544 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14545 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14546 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 14547 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 14548 | if (aborted == false) |
| 14549 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14550 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14551 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14552 | |
| 14553 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 14554 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14555 | } |
| 14556 | |
| 14557 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14558 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 14559 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14560 | * |
| 14561 | * This function checks the sequence, starting with the frame described by |
| 14562 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 14563 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 14564 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 14565 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 14566 | * set. 3) That there are no holes in the sequence count. The function will |
| 14567 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 14568 | **/ |
| 14569 | static int |
| 14570 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 14571 | { |
| 14572 | struct fc_frame_header *hdr; |
| 14573 | struct lpfc_dmabuf *d_buf; |
| 14574 | struct hbq_dmabuf *seq_dmabuf; |
| 14575 | uint32_t fctl; |
| 14576 | int seq_count = 0; |
| 14577 | |
| 14578 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14579 | /* make sure first fame of sequence has a sequence count of zero */ |
| 14580 | if (hdr->fh_seq_cnt != seq_count) |
| 14581 | return 0; |
| 14582 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14583 | hdr->fh_f_ctl[1] << 8 | |
| 14584 | hdr->fh_f_ctl[2]); |
| 14585 | /* If last frame of sequence we can return success. */ |
| 14586 | if (fctl & FC_FC_END_SEQ) |
| 14587 | return 1; |
| 14588 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 14589 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14590 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14591 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14592 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14593 | return 0; |
| 14594 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14595 | hdr->fh_f_ctl[1] << 8 | |
| 14596 | hdr->fh_f_ctl[2]); |
| 14597 | /* If last frame of sequence we can return success. */ |
| 14598 | if (fctl & FC_FC_END_SEQ) |
| 14599 | return 1; |
| 14600 | } |
| 14601 | return 0; |
| 14602 | } |
| 14603 | |
| 14604 | /** |
| 14605 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 14606 | * @vport: Pointer to the vport on which this sequence was received |
| 14607 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14608 | * |
| 14609 | * This function takes a sequence, described by a list of frames, and creates |
| 14610 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 14611 | * used to issue to the generic unsolicited sequence handler. This routine |
| 14612 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 14613 | * to allocate an iocbq then it throw out the received frames that were not |
| 14614 | * able to be described and return a pointer to the first iocbq. If unable to |
| 14615 | * allocate any iocbqs (including the first) this function will return NULL. |
| 14616 | **/ |
| 14617 | static struct lpfc_iocbq * |
| 14618 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 14619 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14620 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14621 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 14622 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 14623 | struct fc_frame_header *fc_hdr; |
| 14624 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14625 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14626 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14627 | |
| 14628 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14629 | /* remove from receive buffer list */ |
| 14630 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14631 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14632 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14633 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14634 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14635 | /* Get an iocbq struct to fill in. */ |
| 14636 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14637 | if (first_iocbq) { |
| 14638 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14639 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14640 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14641 | |
| 14642 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 14643 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 14644 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 14645 | first_iocbq->iocb.un.rcvels.parmRo = |
| 14646 | sli4_did_from_fc_hdr(fc_hdr); |
| 14647 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 14648 | } else |
| 14649 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14650 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 14651 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 14652 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 14653 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 14654 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 14655 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14656 | /* put the first buffer into the first IOCBq */ |
| 14657 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 14658 | first_iocbq->context3 = NULL; |
| 14659 | first_iocbq->iocb.ulpBdeCount = 1; |
| 14660 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14661 | LPFC_DATA_BUF_SIZE; |
| 14662 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14663 | tot_len = bf_get(lpfc_rcqe_length, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14664 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14665 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14666 | } |
| 14667 | iocbq = first_iocbq; |
| 14668 | /* |
| 14669 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 14670 | * of buffers for this sequence and save two buffers in each IOCBq |
| 14671 | */ |
| 14672 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 14673 | if (!iocbq) { |
| 14674 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14675 | continue; |
| 14676 | } |
| 14677 | if (!iocbq->context3) { |
| 14678 | iocbq->context3 = d_buf; |
| 14679 | iocbq->iocb.ulpBdeCount++; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14680 | pbde = (struct ulp_bde64 *) |
| 14681 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 14682 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14683 | |
| 14684 | /* We need to get the size out of the right CQE */ |
| 14685 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14686 | len = bf_get(lpfc_rcqe_length, |
| 14687 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14688 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 14689 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14690 | } else { |
| 14691 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14692 | if (!iocbq) { |
| 14693 | if (first_iocbq) { |
| 14694 | first_iocbq->iocb.ulpStatus = |
| 14695 | IOSTAT_FCP_RSP_ERROR; |
| 14696 | first_iocbq->iocb.un.ulpWord[4] = |
| 14697 | IOERR_NO_RESOURCES; |
| 14698 | } |
| 14699 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14700 | continue; |
| 14701 | } |
| 14702 | iocbq->context2 = d_buf; |
| 14703 | iocbq->context3 = NULL; |
| 14704 | iocbq->iocb.ulpBdeCount = 1; |
| 14705 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14706 | LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14707 | |
| 14708 | /* We need to get the size out of the right CQE */ |
| 14709 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14710 | len = bf_get(lpfc_rcqe_length, |
| 14711 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14712 | tot_len += len; |
| 14713 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 14714 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14715 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 14716 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 14717 | } |
| 14718 | } |
| 14719 | return first_iocbq; |
| 14720 | } |
| 14721 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14722 | static void |
| 14723 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 14724 | struct hbq_dmabuf *seq_dmabuf) |
| 14725 | { |
| 14726 | struct fc_frame_header *fc_hdr; |
| 14727 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 14728 | struct lpfc_hba *phba = vport->phba; |
| 14729 | |
| 14730 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14731 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 14732 | if (!iocbq) { |
| 14733 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14734 | "2707 Ring %d handler: Failed to allocate " |
| 14735 | "iocb Rctl x%x Type x%x received\n", |
| 14736 | LPFC_ELS_RING, |
| 14737 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14738 | return; |
| 14739 | } |
| 14740 | if (!lpfc_complete_unsol_iocb(phba, |
| 14741 | &phba->sli.ring[LPFC_ELS_RING], |
| 14742 | iocbq, fc_hdr->fh_r_ctl, |
| 14743 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14744 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14745 | "2540 Ring %d handler: unexpected Rctl " |
| 14746 | "x%x Type x%x received\n", |
| 14747 | LPFC_ELS_RING, |
| 14748 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14749 | |
| 14750 | /* Free iocb created in lpfc_prep_seq */ |
| 14751 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 14752 | &iocbq->list, list) { |
| 14753 | list_del_init(&curr_iocb->list); |
| 14754 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 14755 | } |
| 14756 | lpfc_sli_release_iocbq(phba, iocbq); |
| 14757 | } |
| 14758 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14759 | /** |
| 14760 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 14761 | * @phba: Pointer to HBA context object. |
| 14762 | * |
| 14763 | * This function is called with no lock held. This function processes all |
| 14764 | * the received buffers and gives it to upper layers when a received buffer |
| 14765 | * indicates that it is the final frame in the sequence. The interrupt |
| 14766 | * service routine processes received buffers at interrupt contexts and adds |
| 14767 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 14768 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 14769 | * appropriate receive function when the final frame in a sequence is received. |
| 14770 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14771 | void |
| 14772 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 14773 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14774 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14775 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14776 | struct fc_frame_header *fc_hdr; |
| 14777 | struct lpfc_vport *vport; |
| 14778 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14779 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14780 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14781 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14782 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14783 | /* check to see if this a valid type of frame */ |
| 14784 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 14785 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14786 | return; |
| 14787 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14788 | if ((bf_get(lpfc_cqe_code, |
| 14789 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 14790 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 14791 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 14792 | else |
| 14793 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 14794 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14795 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14796 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14797 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14798 | /* throw out the frame */ |
| 14799 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14800 | return; |
| 14801 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14802 | |
| 14803 | /* d_id this frame is directed to */ |
| 14804 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 14805 | |
| 14806 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 14807 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 14808 | (did != Fabric_DID)) { |
| 14809 | /* |
| 14810 | * Throw out the frame if we are not pt2pt. |
| 14811 | * The pt2pt protocol allows for discovery frames |
| 14812 | * to be received without a registered VPI. |
| 14813 | */ |
| 14814 | if (!(vport->fc_flag & FC_PT2PT) || |
| 14815 | (phba->link_state == LPFC_HBA_READY)) { |
| 14816 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14817 | return; |
| 14818 | } |
| 14819 | } |
| 14820 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14821 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 14822 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 14823 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 14824 | return; |
| 14825 | } |
| 14826 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14827 | /* Link this frame */ |
| 14828 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 14829 | if (!seq_dmabuf) { |
| 14830 | /* unable to add frame to vport - throw it out */ |
| 14831 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14832 | return; |
| 14833 | } |
| 14834 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14835 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14836 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14837 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14838 | /* Send the complete sequence to the upper layer protocol */ |
| 14839 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14840 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14841 | |
| 14842 | /** |
| 14843 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 14844 | * @phba: pointer to lpfc hba data structure. |
| 14845 | * |
| 14846 | * This routine is invoked to post rpi header templates to the |
| 14847 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14848 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14849 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14850 | * |
| 14851 | * This routine does not require any locks. It's usage is expected |
| 14852 | * to be driver load or reset recovery when the driver is |
| 14853 | * sequential. |
| 14854 | * |
| 14855 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14856 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14857 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14858 | * When this error occurs, the driver is not guaranteed |
| 14859 | * to have any rpi regions posted to the device and |
| 14860 | * must either attempt to repost the regions or take a |
| 14861 | * fatal error. |
| 14862 | **/ |
| 14863 | int |
| 14864 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 14865 | { |
| 14866 | struct lpfc_rpi_hdr *rpi_page; |
| 14867 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14868 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14869 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14870 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14871 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14872 | goto exit; |
| 14873 | if (phba->sli4_hba.extents_in_use) |
| 14874 | return -EIO; |
| 14875 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14876 | 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] | 14877 | /* |
| 14878 | * Assign the rpi headers a physical rpi only if the driver |
| 14879 | * has not initialized those resources. A port reset only |
| 14880 | * needs the headers posted. |
| 14881 | */ |
| 14882 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 14883 | LPFC_RPI_RSRC_RDY) |
| 14884 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 14885 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14886 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 14887 | if (rc != MBX_SUCCESS) { |
| 14888 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14889 | "2008 Error %d posting all rpi " |
| 14890 | "headers\n", rc); |
| 14891 | rc = -EIO; |
| 14892 | break; |
| 14893 | } |
| 14894 | } |
| 14895 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14896 | exit: |
| 14897 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 14898 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14899 | return rc; |
| 14900 | } |
| 14901 | |
| 14902 | /** |
| 14903 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 14904 | * @phba: pointer to lpfc hba data structure. |
| 14905 | * @rpi_page: pointer to the rpi memory region. |
| 14906 | * |
| 14907 | * This routine is invoked to post a single rpi header to the |
| 14908 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 14909 | * maps up to 64 rpi context regions. |
| 14910 | * |
| 14911 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14912 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14913 | * -ENOMEM - No available memory |
| 14914 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14915 | **/ |
| 14916 | int |
| 14917 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 14918 | { |
| 14919 | LPFC_MBOXQ_t *mboxq; |
| 14920 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 14921 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14922 | uint32_t shdr_status, shdr_add_status; |
| 14923 | union lpfc_sli4_cfg_shdr *shdr; |
| 14924 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14925 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14926 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14927 | return rc; |
| 14928 | if (phba->sli4_hba.extents_in_use) |
| 14929 | return -EIO; |
| 14930 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14931 | /* The port is notified of the header region via a mailbox command. */ |
| 14932 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14933 | if (!mboxq) { |
| 14934 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14935 | "2001 Unable to allocate memory for issuing " |
| 14936 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 14937 | return -ENOMEM; |
| 14938 | } |
| 14939 | |
| 14940 | /* Post all rpi memory regions to the port. */ |
| 14941 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14942 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14943 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 14944 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14945 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 14946 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14947 | |
| 14948 | |
| 14949 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14950 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 14951 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14952 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 14953 | hdr_tmpl, rpi_page->page_count); |
| 14954 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14955 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 14956 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14957 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14958 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 14959 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14960 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14961 | if (rc != MBX_TIMEOUT) |
| 14962 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14963 | if (shdr_status || shdr_add_status || rc) { |
| 14964 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14965 | "2514 POST_RPI_HDR mailbox failed with " |
| 14966 | "status x%x add_status x%x, mbx status x%x\n", |
| 14967 | shdr_status, shdr_add_status, rc); |
| 14968 | rc = -ENXIO; |
| 14969 | } |
| 14970 | return rc; |
| 14971 | } |
| 14972 | |
| 14973 | /** |
| 14974 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 14975 | * @phba: pointer to lpfc hba data structure. |
| 14976 | * |
| 14977 | * This routine is invoked to post rpi header templates to the |
| 14978 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14979 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14980 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14981 | * |
| 14982 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14983 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14984 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14985 | **/ |
| 14986 | int |
| 14987 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 14988 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14989 | unsigned long rpi; |
| 14990 | uint16_t max_rpi, rpi_limit; |
| 14991 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14992 | struct lpfc_rpi_hdr *rpi_hdr; |
| 14993 | |
| 14994 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14995 | rpi_limit = phba->sli4_hba.next_rpi; |
| 14996 | |
| 14997 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14998 | * Fetch the next logical rpi. Because this index is logical, |
| 14999 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15000 | */ |
| 15001 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15002 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 15003 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15004 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 15005 | else { |
| 15006 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 15007 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 15008 | phba->sli4_hba.rpi_count++; |
| 15009 | } |
| 15010 | |
| 15011 | /* |
| 15012 | * 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] | 15013 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15014 | */ |
| 15015 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 15016 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
| 15017 | spin_unlock_irq(&phba->hbalock); |
| 15018 | return rpi; |
| 15019 | } |
| 15020 | |
| 15021 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15022 | * RPI header postings are not required for SLI4 ports capable of |
| 15023 | * extents. |
| 15024 | */ |
| 15025 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
| 15026 | spin_unlock_irq(&phba->hbalock); |
| 15027 | return rpi; |
| 15028 | } |
| 15029 | |
| 15030 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15031 | * If the driver is running low on rpi resources, allocate another |
| 15032 | * page now. Note that the next_rpi value is used because |
| 15033 | * it represents how many are actually in use whereas max_rpi notes |
| 15034 | * how many are supported max by the device. |
| 15035 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15036 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15037 | spin_unlock_irq(&phba->hbalock); |
| 15038 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 15039 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 15040 | if (!rpi_hdr) { |
| 15041 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15042 | "2002 Error Could not grow rpi " |
| 15043 | "count\n"); |
| 15044 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15045 | lrpi = rpi_hdr->start_rpi; |
| 15046 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15047 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 15048 | } |
| 15049 | } |
| 15050 | |
| 15051 | return rpi; |
| 15052 | } |
| 15053 | |
| 15054 | /** |
| 15055 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15056 | * @phba: pointer to lpfc hba data structure. |
| 15057 | * |
| 15058 | * This routine is invoked to release an rpi to the pool of |
| 15059 | * available rpis maintained by the driver. |
| 15060 | **/ |
| 15061 | void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15062 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15063 | { |
| 15064 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 15065 | phba->sli4_hba.rpi_count--; |
| 15066 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 15067 | } |
| 15068 | } |
| 15069 | |
| 15070 | /** |
| 15071 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15072 | * @phba: pointer to lpfc hba data structure. |
| 15073 | * |
| 15074 | * This routine is invoked to release an rpi to the pool of |
| 15075 | * available rpis maintained by the driver. |
| 15076 | **/ |
| 15077 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15078 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15079 | { |
| 15080 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15081 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15082 | spin_unlock_irq(&phba->hbalock); |
| 15083 | } |
| 15084 | |
| 15085 | /** |
| 15086 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 15087 | * @phba: pointer to lpfc hba data structure. |
| 15088 | * |
| 15089 | * This routine is invoked to remove the memory region that |
| 15090 | * provided rpi via a bitmask. |
| 15091 | **/ |
| 15092 | void |
| 15093 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 15094 | { |
| 15095 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15096 | kfree(phba->sli4_hba.rpi_ids); |
| 15097 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15098 | } |
| 15099 | |
| 15100 | /** |
| 15101 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 15102 | * @phba: pointer to lpfc hba data structure. |
| 15103 | * |
| 15104 | * This routine is invoked to remove the memory region that |
| 15105 | * provided rpi via a bitmask. |
| 15106 | **/ |
| 15107 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15108 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 15109 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15110 | { |
| 15111 | LPFC_MBOXQ_t *mboxq; |
| 15112 | struct lpfc_hba *phba = ndlp->phba; |
| 15113 | int rc; |
| 15114 | |
| 15115 | /* The port is notified of the header region via a mailbox command. */ |
| 15116 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15117 | if (!mboxq) |
| 15118 | return -ENOMEM; |
| 15119 | |
| 15120 | /* Post all rpi memory regions to the port. */ |
| 15121 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15122 | if (cmpl) { |
| 15123 | mboxq->mbox_cmpl = cmpl; |
| 15124 | mboxq->context1 = arg; |
| 15125 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 15126 | } else |
| 15127 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15128 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15129 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15130 | if (rc == MBX_NOT_FINISHED) { |
| 15131 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15132 | "2010 Resume RPI Mailbox failed " |
| 15133 | "status %d, mbxStatus x%x\n", rc, |
| 15134 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 15135 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15136 | return -EIO; |
| 15137 | } |
| 15138 | return 0; |
| 15139 | } |
| 15140 | |
| 15141 | /** |
| 15142 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15143 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15144 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15145 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15146 | * |
| 15147 | * Returns: |
| 15148 | * 0 success |
| 15149 | * -Evalue otherwise |
| 15150 | **/ |
| 15151 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15152 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15153 | { |
| 15154 | LPFC_MBOXQ_t *mboxq; |
| 15155 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15156 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15157 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15158 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15159 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15160 | if (!mboxq) |
| 15161 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15162 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15163 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15164 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15165 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15166 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15167 | "2022 INIT VPI Mailbox failed " |
| 15168 | "status %d, mbxStatus x%x\n", rc, |
| 15169 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15170 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15171 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15172 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15173 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15174 | |
| 15175 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15176 | } |
| 15177 | |
| 15178 | /** |
| 15179 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 15180 | * @phba: pointer to lpfc hba data structure. |
| 15181 | * @mboxq: Pointer to mailbox object. |
| 15182 | * |
| 15183 | * This routine is invoked to manually add a single FCF record. The caller |
| 15184 | * must pass a completely initialized FCF_Record. This routine takes |
| 15185 | * care of the nonembedded mailbox operations. |
| 15186 | **/ |
| 15187 | static void |
| 15188 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 15189 | { |
| 15190 | void *virt_addr; |
| 15191 | union lpfc_sli4_cfg_shdr *shdr; |
| 15192 | uint32_t shdr_status, shdr_add_status; |
| 15193 | |
| 15194 | virt_addr = mboxq->sge_array->addr[0]; |
| 15195 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15196 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 15197 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15198 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15199 | |
| 15200 | if ((shdr_status || shdr_add_status) && |
| 15201 | (shdr_status != STATUS_FCF_IN_USE)) |
| 15202 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15203 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 15204 | "status x%x add_status x%x\n", |
| 15205 | shdr_status, shdr_add_status); |
| 15206 | |
| 15207 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15208 | } |
| 15209 | |
| 15210 | /** |
| 15211 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 15212 | * @phba: pointer to lpfc hba data structure. |
| 15213 | * @fcf_record: pointer to the initialized fcf record to add. |
| 15214 | * |
| 15215 | * This routine is invoked to manually add a single FCF record. The caller |
| 15216 | * must pass a completely initialized FCF_Record. This routine takes |
| 15217 | * care of the nonembedded mailbox operations. |
| 15218 | **/ |
| 15219 | int |
| 15220 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 15221 | { |
| 15222 | int rc = 0; |
| 15223 | LPFC_MBOXQ_t *mboxq; |
| 15224 | uint8_t *bytep; |
| 15225 | void *virt_addr; |
| 15226 | dma_addr_t phys_addr; |
| 15227 | struct lpfc_mbx_sge sge; |
| 15228 | uint32_t alloc_len, req_len; |
| 15229 | uint32_t fcfindex; |
| 15230 | |
| 15231 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15232 | if (!mboxq) { |
| 15233 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15234 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 15235 | return -ENOMEM; |
| 15236 | } |
| 15237 | |
| 15238 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 15239 | sizeof(uint32_t); |
| 15240 | |
| 15241 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 15242 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15243 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 15244 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 15245 | if (alloc_len < req_len) { |
| 15246 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15247 | "2523 Allocated DMA memory size (x%x) is " |
| 15248 | "less than the requested DMA memory " |
| 15249 | "size (x%x)\n", alloc_len, req_len); |
| 15250 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15251 | return -ENOMEM; |
| 15252 | } |
| 15253 | |
| 15254 | /* |
| 15255 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 15256 | * routine only uses a single SGE. |
| 15257 | */ |
| 15258 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 15259 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15260 | virt_addr = mboxq->sge_array->addr[0]; |
| 15261 | /* |
| 15262 | * Configure the FCF record for FCFI 0. This is the driver's |
| 15263 | * hardcoded default and gets used in nonFIP mode. |
| 15264 | */ |
| 15265 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 15266 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 15267 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 15268 | |
| 15269 | /* |
| 15270 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 15271 | * the FCoE header plus word10. The data copy needs to be endian |
| 15272 | * correct. |
| 15273 | */ |
| 15274 | bytep += sizeof(uint32_t); |
| 15275 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 15276 | mboxq->vport = phba->pport; |
| 15277 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 15278 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15279 | if (rc == MBX_NOT_FINISHED) { |
| 15280 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15281 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 15282 | "status 0x%x\n", rc); |
| 15283 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15284 | rc = -EIO; |
| 15285 | } else |
| 15286 | rc = 0; |
| 15287 | |
| 15288 | return rc; |
| 15289 | } |
| 15290 | |
| 15291 | /** |
| 15292 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 15293 | * @phba: pointer to lpfc hba data structure. |
| 15294 | * @fcf_record: pointer to the fcf record to write the default data. |
| 15295 | * @fcf_index: FCF table entry index. |
| 15296 | * |
| 15297 | * This routine is invoked to build the driver's default FCF record. The |
| 15298 | * values used are hardcoded. This routine handles memory initialization. |
| 15299 | * |
| 15300 | **/ |
| 15301 | void |
| 15302 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 15303 | struct fcf_record *fcf_record, |
| 15304 | uint16_t fcf_index) |
| 15305 | { |
| 15306 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 15307 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 15308 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 15309 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 15310 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 15311 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 15312 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 15313 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 15314 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 15315 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 15316 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 15317 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 15318 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 15319 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 15320 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15321 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 15322 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 15323 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 15324 | /* Set the VLAN bit map */ |
| 15325 | if (phba->valid_vlan) { |
| 15326 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 15327 | = 1 << (phba->vlan_id % 8); |
| 15328 | } |
| 15329 | } |
| 15330 | |
| 15331 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15332 | * 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] | 15333 | * @phba: pointer to lpfc hba data structure. |
| 15334 | * @fcf_index: FCF table entry offset. |
| 15335 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15336 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 15337 | * record and processing it one at a time starting from the @fcf_index |
| 15338 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 15339 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15340 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15341 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15342 | **/ |
| 15343 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15344 | 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] | 15345 | { |
| 15346 | int rc = 0, error; |
| 15347 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15348 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15349 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 15350 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15351 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15352 | if (!mboxq) { |
| 15353 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15354 | "2000 Failed to allocate mbox for " |
| 15355 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15356 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15357 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15358 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15359 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15360 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15361 | if (rc) { |
| 15362 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15363 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15364 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15365 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15366 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15367 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15368 | |
| 15369 | spin_lock_irq(&phba->hbalock); |
| 15370 | phba->hba_flag |= FCF_TS_INPROG; |
| 15371 | spin_unlock_irq(&phba->hbalock); |
| 15372 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15373 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15374 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15375 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15376 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 15377 | /* Reset eligible FCF count for new scan */ |
| 15378 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 15379 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15380 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15381 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15382 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15383 | if (error) { |
| 15384 | if (mboxq) |
| 15385 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15386 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15387 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15388 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15389 | spin_unlock_irq(&phba->hbalock); |
| 15390 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15391 | return error; |
| 15392 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15393 | |
| 15394 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15395 | * 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] | 15396 | * @phba: pointer to lpfc hba data structure. |
| 15397 | * @fcf_index: FCF table entry offset. |
| 15398 | * |
| 15399 | * 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] | 15400 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15401 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15402 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15403 | * otherwise. |
| 15404 | **/ |
| 15405 | int |
| 15406 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15407 | { |
| 15408 | int rc = 0, error; |
| 15409 | LPFC_MBOXQ_t *mboxq; |
| 15410 | |
| 15411 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15412 | if (!mboxq) { |
| 15413 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15414 | "2763 Failed to allocate mbox for " |
| 15415 | "READ_FCF cmd\n"); |
| 15416 | error = -ENOMEM; |
| 15417 | goto fail_fcf_read; |
| 15418 | } |
| 15419 | /* Construct the read FCF record mailbox command */ |
| 15420 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15421 | if (rc) { |
| 15422 | error = -EINVAL; |
| 15423 | goto fail_fcf_read; |
| 15424 | } |
| 15425 | /* Issue the mailbox command asynchronously */ |
| 15426 | mboxq->vport = phba->pport; |
| 15427 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 15428 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15429 | if (rc == MBX_NOT_FINISHED) |
| 15430 | error = -EIO; |
| 15431 | else |
| 15432 | error = 0; |
| 15433 | |
| 15434 | fail_fcf_read: |
| 15435 | if (error && mboxq) |
| 15436 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15437 | return error; |
| 15438 | } |
| 15439 | |
| 15440 | /** |
| 15441 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 15442 | * @phba: pointer to lpfc hba data structure. |
| 15443 | * @fcf_index: FCF table entry offset. |
| 15444 | * |
| 15445 | * 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] | 15446 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15447 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15448 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15449 | * otherwise. |
| 15450 | **/ |
| 15451 | int |
| 15452 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15453 | { |
| 15454 | int rc = 0, error; |
| 15455 | LPFC_MBOXQ_t *mboxq; |
| 15456 | |
| 15457 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15458 | if (!mboxq) { |
| 15459 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15460 | "2758 Failed to allocate mbox for " |
| 15461 | "READ_FCF cmd\n"); |
| 15462 | error = -ENOMEM; |
| 15463 | goto fail_fcf_read; |
| 15464 | } |
| 15465 | /* Construct the read FCF record mailbox command */ |
| 15466 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15467 | if (rc) { |
| 15468 | error = -EINVAL; |
| 15469 | goto fail_fcf_read; |
| 15470 | } |
| 15471 | /* Issue the mailbox command asynchronously */ |
| 15472 | mboxq->vport = phba->pport; |
| 15473 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 15474 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15475 | if (rc == MBX_NOT_FINISHED) |
| 15476 | error = -EIO; |
| 15477 | else |
| 15478 | error = 0; |
| 15479 | |
| 15480 | fail_fcf_read: |
| 15481 | if (error && mboxq) |
| 15482 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15483 | return error; |
| 15484 | } |
| 15485 | |
| 15486 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15487 | * lpfc_check_next_fcf_pri |
| 15488 | * phba pointer to the lpfc_hba struct for this port. |
| 15489 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 15490 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 15491 | * rr_bmask based on their priority level. Starting from the highest priority |
| 15492 | * to the lowest. The most likely FCF candidate will be in the highest |
| 15493 | * priority group. When this routine is called it searches the fcf_pri list for |
| 15494 | * next lowest priority group and repopulates the rr_bmask with only those |
| 15495 | * fcf_indexes. |
| 15496 | * returns: |
| 15497 | * 1=success 0=failure |
| 15498 | **/ |
| 15499 | int |
| 15500 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 15501 | { |
| 15502 | uint16_t next_fcf_pri; |
| 15503 | uint16_t last_index; |
| 15504 | struct lpfc_fcf_pri *fcf_pri; |
| 15505 | int rc; |
| 15506 | int ret = 0; |
| 15507 | |
| 15508 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 15509 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15510 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 15511 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 15512 | |
| 15513 | /* Verify the priority list has 2 or more entries */ |
| 15514 | spin_lock_irq(&phba->hbalock); |
| 15515 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 15516 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 15517 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15518 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 15519 | "3061 Last IDX %d\n", last_index); |
| 15520 | return 0; /* Empty rr list */ |
| 15521 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 15522 | spin_unlock_irq(&phba->hbalock); |
| 15523 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15524 | next_fcf_pri = 0; |
| 15525 | /* |
| 15526 | * Clear the rr_bmask and set all of the bits that are at this |
| 15527 | * priority. |
| 15528 | */ |
| 15529 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 15530 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 15531 | spin_lock_irq(&phba->hbalock); |
| 15532 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15533 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 15534 | continue; |
| 15535 | /* |
| 15536 | * the 1st priority that has not FLOGI failed |
| 15537 | * will be the highest. |
| 15538 | */ |
| 15539 | if (!next_fcf_pri) |
| 15540 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15541 | spin_unlock_irq(&phba->hbalock); |
| 15542 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15543 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15544 | fcf_pri->fcf_rec.fcf_index); |
| 15545 | if (rc) |
| 15546 | return 0; |
| 15547 | } |
| 15548 | spin_lock_irq(&phba->hbalock); |
| 15549 | } |
| 15550 | /* |
| 15551 | * if next_fcf_pri was not set above and the list is not empty then |
| 15552 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 15553 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15554 | */ |
| 15555 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 15556 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15557 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 15558 | /* |
| 15559 | * the 1st priority that has not FLOGI failed |
| 15560 | * will be the highest. |
| 15561 | */ |
| 15562 | if (!next_fcf_pri) |
| 15563 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15564 | spin_unlock_irq(&phba->hbalock); |
| 15565 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15566 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15567 | fcf_pri->fcf_rec.fcf_index); |
| 15568 | if (rc) |
| 15569 | return 0; |
| 15570 | } |
| 15571 | spin_lock_irq(&phba->hbalock); |
| 15572 | } |
| 15573 | } else |
| 15574 | ret = 1; |
| 15575 | spin_unlock_irq(&phba->hbalock); |
| 15576 | |
| 15577 | return ret; |
| 15578 | } |
| 15579 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15580 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 15581 | * @phba: pointer to lpfc hba data structure. |
| 15582 | * |
| 15583 | * This routine is to get the next eligible FCF record index in a round |
| 15584 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15585 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15586 | * shall be returned, otherwise, the next eligible FCF record's index |
| 15587 | * shall be returned. |
| 15588 | **/ |
| 15589 | uint16_t |
| 15590 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 15591 | { |
| 15592 | uint16_t next_fcf_index; |
| 15593 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 15594 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15595 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 15596 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 15597 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15598 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 15599 | /* Determine the next fcf index to check */ |
| 15600 | 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] | 15601 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15602 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15603 | next_fcf_index); |
| 15604 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15605 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15606 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15607 | /* |
| 15608 | * If we have wrapped then we need to clear the bits that |
| 15609 | * have been tested so that we can detect when we should |
| 15610 | * change the priority level. |
| 15611 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15612 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15613 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15614 | } |
| 15615 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15616 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15617 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15618 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 15619 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 15620 | /* |
| 15621 | * If next fcf index is not found check if there are lower |
| 15622 | * Priority level fcf's in the fcf_priority list. |
| 15623 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 15624 | * at that level and continue the selection process. |
| 15625 | */ |
| 15626 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 15627 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15628 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15629 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15630 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 15631 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 15632 | else { |
| 15633 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15634 | "3063 Only FCF available idx %d, flag %x\n", |
| 15635 | next_fcf_index, |
| 15636 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 15637 | return next_fcf_index; |
| 15638 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15639 | } |
| 15640 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15641 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 15642 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
| 15643 | LPFC_FCF_FLOGI_FAILED) |
| 15644 | goto next_priority; |
| 15645 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15646 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15647 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 15648 | next_fcf_index); |
| 15649 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15650 | return next_fcf_index; |
| 15651 | } |
| 15652 | |
| 15653 | /** |
| 15654 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 15655 | * @phba: pointer to lpfc hba data structure. |
| 15656 | * |
| 15657 | * 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] | 15658 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15659 | * does not go beyond the range of the driver allocated bmask dimension |
| 15660 | * before setting the bit. |
| 15661 | * |
| 15662 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 15663 | * -EINVAL. |
| 15664 | **/ |
| 15665 | int |
| 15666 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15667 | { |
| 15668 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15669 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15670 | "2610 FCF (x%x) reached driver's book " |
| 15671 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15672 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15673 | return -EINVAL; |
| 15674 | } |
| 15675 | /* Set the eligible FCF record index bmask */ |
| 15676 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 15677 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15678 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15679 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15680 | "bmask\n", fcf_index); |
| 15681 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15682 | return 0; |
| 15683 | } |
| 15684 | |
| 15685 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15686 | * 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] | 15687 | * @phba: pointer to lpfc hba data structure. |
| 15688 | * |
| 15689 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15690 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15691 | * does not go beyond the range of the driver allocated bmask dimension |
| 15692 | * before clearing the bit. |
| 15693 | **/ |
| 15694 | void |
| 15695 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15696 | { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15697 | struct lpfc_fcf_pri *fcf_pri; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15698 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15699 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15700 | "2762 FCF (x%x) reached driver's book " |
| 15701 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15702 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15703 | return; |
| 15704 | } |
| 15705 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15706 | spin_lock_irq(&phba->hbalock); |
| 15707 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15708 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 15709 | list_del_init(&fcf_pri->list); |
| 15710 | break; |
| 15711 | } |
| 15712 | } |
| 15713 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15714 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15715 | |
| 15716 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15717 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15718 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15719 | } |
| 15720 | |
| 15721 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15722 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 15723 | * @phba: pointer to lpfc hba data structure. |
| 15724 | * |
| 15725 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 15726 | * command. If the mailbox command returned failure, it will try to stop the |
| 15727 | * FCF rediscover wait timer. |
| 15728 | **/ |
| 15729 | void |
| 15730 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 15731 | { |
| 15732 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15733 | uint32_t shdr_status, shdr_add_status; |
| 15734 | |
| 15735 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15736 | |
| 15737 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 15738 | &redisc_fcf->header.cfg_shdr.response); |
| 15739 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 15740 | &redisc_fcf->header.cfg_shdr.response); |
| 15741 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15742 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15743 | "2746 Requesting for FCF rediscovery failed " |
| 15744 | "status x%x add_status x%x\n", |
| 15745 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15746 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15747 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15748 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15749 | spin_unlock_irq(&phba->hbalock); |
| 15750 | /* |
| 15751 | * CVL event triggered FCF rediscover request failed, |
| 15752 | * last resort to re-try current registered FCF entry. |
| 15753 | */ |
| 15754 | lpfc_retry_pport_discovery(phba); |
| 15755 | } else { |
| 15756 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15757 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15758 | spin_unlock_irq(&phba->hbalock); |
| 15759 | /* |
| 15760 | * DEAD FCF event triggered FCF rediscover request |
| 15761 | * failed, last resort to fail over as a link down |
| 15762 | * to FCF registration. |
| 15763 | */ |
| 15764 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 15765 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15766 | } else { |
| 15767 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15768 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15769 | /* |
| 15770 | * Start FCF rediscovery wait timer for pending FCF |
| 15771 | * before rescan FCF record table. |
| 15772 | */ |
| 15773 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15774 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15775 | |
| 15776 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15777 | } |
| 15778 | |
| 15779 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15780 | * 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] | 15781 | * @phba: pointer to lpfc hba data structure. |
| 15782 | * |
| 15783 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 15784 | * by the port. |
| 15785 | **/ |
| 15786 | int |
| 15787 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 15788 | { |
| 15789 | LPFC_MBOXQ_t *mbox; |
| 15790 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15791 | int rc, length; |
| 15792 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15793 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 15794 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 15795 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15796 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15797 | if (!mbox) { |
| 15798 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15799 | "2745 Failed to allocate mbox for " |
| 15800 | "requesting FCF rediscover.\n"); |
| 15801 | return -ENOMEM; |
| 15802 | } |
| 15803 | |
| 15804 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 15805 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15806 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15807 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 15808 | length, LPFC_SLI4_MBX_EMBED); |
| 15809 | |
| 15810 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15811 | /* Set count to 0 for invalidating the entire FCF database */ |
| 15812 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 15813 | |
| 15814 | /* Issue the mailbox command asynchronously */ |
| 15815 | mbox->vport = phba->pport; |
| 15816 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 15817 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 15818 | |
| 15819 | if (rc == MBX_NOT_FINISHED) { |
| 15820 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15821 | return -EIO; |
| 15822 | } |
| 15823 | return 0; |
| 15824 | } |
| 15825 | |
| 15826 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15827 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 15828 | * @phba: pointer to lpfc hba data structure. |
| 15829 | * |
| 15830 | * This function is the failover routine as a last resort to the FCF DEAD |
| 15831 | * event when driver failed to perform fast FCF failover. |
| 15832 | **/ |
| 15833 | void |
| 15834 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 15835 | { |
| 15836 | uint32_t link_state; |
| 15837 | |
| 15838 | /* |
| 15839 | * Last resort as FCF DEAD event failover will treat this as |
| 15840 | * a link down, but save the link state because we don't want |
| 15841 | * it to be changed to Link Down unless it is already down. |
| 15842 | */ |
| 15843 | link_state = phba->link_state; |
| 15844 | lpfc_linkdown(phba); |
| 15845 | phba->link_state = link_state; |
| 15846 | |
| 15847 | /* Unregister FCF if no devices connected to it */ |
| 15848 | lpfc_unregister_unused_fcf(phba); |
| 15849 | } |
| 15850 | |
| 15851 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15852 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15853 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15854 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15855 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15856 | * This function gets SLI3 port configure region 23 data through memory dump |
| 15857 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15858 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15859 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15860 | static uint32_t |
| 15861 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15862 | { |
| 15863 | LPFC_MBOXQ_t *pmb = NULL; |
| 15864 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15865 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15866 | int rc; |
| 15867 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15868 | if (!rgn23_data) |
| 15869 | return 0; |
| 15870 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15871 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15872 | if (!pmb) { |
| 15873 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15874 | "2600 failed to allocate mailbox memory\n"); |
| 15875 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15876 | } |
| 15877 | mb = &pmb->u.mb; |
| 15878 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15879 | do { |
| 15880 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 15881 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 15882 | |
| 15883 | if (rc != MBX_SUCCESS) { |
| 15884 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15885 | "2601 failed to read config " |
| 15886 | "region 23, rc 0x%x Status 0x%x\n", |
| 15887 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15888 | mb->un.varDmp.word_cnt = 0; |
| 15889 | } |
| 15890 | /* |
| 15891 | * dump mem may return a zero when finished or we got a |
| 15892 | * mailbox error, either way we are done. |
| 15893 | */ |
| 15894 | if (mb->un.varDmp.word_cnt == 0) |
| 15895 | break; |
| 15896 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 15897 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 15898 | |
| 15899 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15900 | rgn23_data + offset, |
| 15901 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15902 | offset += mb->un.varDmp.word_cnt; |
| 15903 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 15904 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15905 | mempool_free(pmb, phba->mbox_mem_pool); |
| 15906 | return offset; |
| 15907 | } |
| 15908 | |
| 15909 | /** |
| 15910 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 15911 | * @phba: pointer to lpfc hba data structure. |
| 15912 | * @rgn23_data: pointer to configure region 23 data. |
| 15913 | * |
| 15914 | * This function gets SLI4 port configure region 23 data through memory dump |
| 15915 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15916 | * will be returned, otherwise, 0 will be returned. |
| 15917 | **/ |
| 15918 | static uint32_t |
| 15919 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 15920 | { |
| 15921 | LPFC_MBOXQ_t *mboxq = NULL; |
| 15922 | struct lpfc_dmabuf *mp = NULL; |
| 15923 | struct lpfc_mqe *mqe; |
| 15924 | uint32_t data_length = 0; |
| 15925 | int rc; |
| 15926 | |
| 15927 | if (!rgn23_data) |
| 15928 | return 0; |
| 15929 | |
| 15930 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15931 | if (!mboxq) { |
| 15932 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15933 | "3105 failed to allocate mailbox memory\n"); |
| 15934 | return 0; |
| 15935 | } |
| 15936 | |
| 15937 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 15938 | goto out; |
| 15939 | mqe = &mboxq->u.mqe; |
| 15940 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 15941 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 15942 | if (rc) |
| 15943 | goto out; |
| 15944 | data_length = mqe->un.mb_words[5]; |
| 15945 | if (data_length == 0) |
| 15946 | goto out; |
| 15947 | if (data_length > DMP_RGN23_SIZE) { |
| 15948 | data_length = 0; |
| 15949 | goto out; |
| 15950 | } |
| 15951 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 15952 | out: |
| 15953 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15954 | if (mp) { |
| 15955 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15956 | kfree(mp); |
| 15957 | } |
| 15958 | return data_length; |
| 15959 | } |
| 15960 | |
| 15961 | /** |
| 15962 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 15963 | * @phba: pointer to lpfc hba data structure. |
| 15964 | * |
| 15965 | * This function read region 23 and parse TLV for port status to |
| 15966 | * decide if the user disaled the port. If the TLV indicates the |
| 15967 | * port is disabled, the hba_flag is set accordingly. |
| 15968 | **/ |
| 15969 | void |
| 15970 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 15971 | { |
| 15972 | uint8_t *rgn23_data = NULL; |
| 15973 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 15974 | uint32_t offset = 0; |
| 15975 | |
| 15976 | /* Get adapter Region 23 data */ |
| 15977 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 15978 | if (!rgn23_data) |
| 15979 | goto out; |
| 15980 | |
| 15981 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15982 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 15983 | else { |
| 15984 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 15985 | &phba->sli4_hba.sli_intf); |
| 15986 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 15987 | goto out; |
| 15988 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 15989 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15990 | |
| 15991 | if (!data_size) |
| 15992 | goto out; |
| 15993 | |
| 15994 | /* Check the region signature first */ |
| 15995 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 15996 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15997 | "2619 Config region 23 has bad signature\n"); |
| 15998 | goto out; |
| 15999 | } |
| 16000 | offset += 4; |
| 16001 | |
| 16002 | /* Check the data structure version */ |
| 16003 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 16004 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16005 | "2620 Config region 23 has bad version\n"); |
| 16006 | goto out; |
| 16007 | } |
| 16008 | offset += 4; |
| 16009 | |
| 16010 | /* Parse TLV entries in the region */ |
| 16011 | while (offset < data_size) { |
| 16012 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 16013 | break; |
| 16014 | /* |
| 16015 | * If the TLV is not driver specific TLV or driver id is |
| 16016 | * not linux driver id, skip the record. |
| 16017 | */ |
| 16018 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 16019 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 16020 | (rgn23_data[offset + 3] != 0)) { |
| 16021 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16022 | continue; |
| 16023 | } |
| 16024 | |
| 16025 | /* Driver found a driver specific TLV in the config region */ |
| 16026 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 16027 | offset += 4; |
| 16028 | tlv_offset = 0; |
| 16029 | |
| 16030 | /* |
| 16031 | * Search for configured port state sub-TLV. |
| 16032 | */ |
| 16033 | while ((offset < data_size) && |
| 16034 | (tlv_offset < sub_tlv_len)) { |
| 16035 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 16036 | offset += 4; |
| 16037 | tlv_offset += 4; |
| 16038 | break; |
| 16039 | } |
| 16040 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 16041 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16042 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 16043 | continue; |
| 16044 | } |
| 16045 | |
| 16046 | /* This HBA contains PORT_STE configured */ |
| 16047 | if (!rgn23_data[offset + 2]) |
| 16048 | phba->hba_flag |= LINK_DISABLED; |
| 16049 | |
| 16050 | goto out; |
| 16051 | } |
| 16052 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16053 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16054 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16055 | kfree(rgn23_data); |
| 16056 | return; |
| 16057 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16058 | |
| 16059 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16060 | * lpfc_wr_object - write an object to the firmware |
| 16061 | * @phba: HBA structure that indicates port to create a queue on. |
| 16062 | * @dmabuf_list: list of dmabufs to write to the port. |
| 16063 | * @size: the total byte value of the objects to write to the port. |
| 16064 | * @offset: the current offset to be used to start the transfer. |
| 16065 | * |
| 16066 | * This routine will create a wr_object mailbox command to send to the port. |
| 16067 | * the mailbox command will be constructed using the dma buffers described in |
| 16068 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 16069 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 16070 | * used to indicate the starting offset of the transfer and will also return |
| 16071 | * the offset after the write object mailbox has completed. @size is used to |
| 16072 | * determine the end of the object and whether the eof bit should be set. |
| 16073 | * |
| 16074 | * Return 0 is successful and offset will contain the the new offset to use |
| 16075 | * for the next write. |
| 16076 | * Return negative value for error cases. |
| 16077 | **/ |
| 16078 | int |
| 16079 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 16080 | uint32_t size, uint32_t *offset) |
| 16081 | { |
| 16082 | struct lpfc_mbx_wr_object *wr_object; |
| 16083 | LPFC_MBOXQ_t *mbox; |
| 16084 | int rc = 0, i = 0; |
| 16085 | uint32_t shdr_status, shdr_add_status; |
| 16086 | uint32_t mbox_tmo; |
| 16087 | union lpfc_sli4_cfg_shdr *shdr; |
| 16088 | struct lpfc_dmabuf *dmabuf; |
| 16089 | uint32_t written = 0; |
| 16090 | |
| 16091 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16092 | if (!mbox) |
| 16093 | return -ENOMEM; |
| 16094 | |
| 16095 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16096 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 16097 | sizeof(struct lpfc_mbx_wr_object) - |
| 16098 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 16099 | |
| 16100 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 16101 | wr_object->u.request.write_offset = *offset; |
| 16102 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 16103 | wr_object->u.request.object_name[0] = |
| 16104 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 16105 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 16106 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 16107 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 16108 | break; |
| 16109 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 16110 | wr_object->u.request.bde[i].addrHigh = |
| 16111 | putPaddrHigh(dmabuf->phys); |
| 16112 | if (written + SLI4_PAGE_SIZE >= size) { |
| 16113 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 16114 | (size - written); |
| 16115 | written += (size - written); |
| 16116 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 16117 | } else { |
| 16118 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 16119 | SLI4_PAGE_SIZE; |
| 16120 | written += SLI4_PAGE_SIZE; |
| 16121 | } |
| 16122 | i++; |
| 16123 | } |
| 16124 | wr_object->u.request.bde_count = i; |
| 16125 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 16126 | if (!phba->sli4_hba.intr_enable) |
| 16127 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16128 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16129 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16130 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16131 | } |
| 16132 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16133 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 16134 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16135 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16136 | if (rc != MBX_TIMEOUT) |
| 16137 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16138 | if (shdr_status || shdr_add_status || rc) { |
| 16139 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16140 | "3025 Write Object mailbox failed with " |
| 16141 | "status x%x add_status x%x, mbx status x%x\n", |
| 16142 | shdr_status, shdr_add_status, rc); |
| 16143 | rc = -ENXIO; |
| 16144 | } else |
| 16145 | *offset += wr_object->u.response.actual_write_length; |
| 16146 | return rc; |
| 16147 | } |
| 16148 | |
| 16149 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16150 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 16151 | * @vport: pointer to vport data structure. |
| 16152 | * |
| 16153 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 16154 | * and REG_VPI mailbox commands associated with the vport. This function |
| 16155 | * is called when driver want to restart discovery of the vport due to |
| 16156 | * a Clear Virtual Link event. |
| 16157 | **/ |
| 16158 | void |
| 16159 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 16160 | { |
| 16161 | struct lpfc_hba *phba = vport->phba; |
| 16162 | LPFC_MBOXQ_t *mb, *nextmb; |
| 16163 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16164 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16165 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 16166 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16167 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 16168 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16169 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16170 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16171 | spin_lock_irq(&phba->hbalock); |
| 16172 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 16173 | if (mb->vport != vport) |
| 16174 | continue; |
| 16175 | |
| 16176 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 16177 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 16178 | continue; |
| 16179 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16180 | list_del(&mb->list); |
| 16181 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 16182 | } |
| 16183 | /* Clean up active mailbox command with the vport */ |
| 16184 | mb = phba->sli.mbox_active; |
| 16185 | if (mb && (mb->vport == vport)) { |
| 16186 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 16187 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 16188 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16189 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16190 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 16191 | /* Put reference count for delayed processing */ |
| 16192 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 16193 | /* Unregister the RPI when mailbox complete */ |
| 16194 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 16195 | } |
| 16196 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 16197 | /* Cleanup any mailbox completions which are not yet processed */ |
| 16198 | do { |
| 16199 | restart_loop = 0; |
| 16200 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 16201 | /* |
| 16202 | * If this mailox is already processed or it is |
| 16203 | * for another vport ignore it. |
| 16204 | */ |
| 16205 | if ((mb->vport != vport) || |
| 16206 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 16207 | continue; |
| 16208 | |
| 16209 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 16210 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 16211 | continue; |
| 16212 | |
| 16213 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16214 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16215 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 16216 | /* Unregister the RPI when mailbox complete */ |
| 16217 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 16218 | restart_loop = 1; |
| 16219 | spin_unlock_irq(&phba->hbalock); |
| 16220 | spin_lock(shost->host_lock); |
| 16221 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 16222 | spin_unlock(shost->host_lock); |
| 16223 | spin_lock_irq(&phba->hbalock); |
| 16224 | break; |
| 16225 | } |
| 16226 | } |
| 16227 | } while (restart_loop); |
| 16228 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16229 | spin_unlock_irq(&phba->hbalock); |
| 16230 | |
| 16231 | /* Release the cleaned-up mailbox commands */ |
| 16232 | while (!list_empty(&mbox_cmd_list)) { |
| 16233 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16234 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16235 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 16236 | if (mp) { |
| 16237 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16238 | kfree(mp); |
| 16239 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16240 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16241 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16242 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 16243 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 16244 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 16245 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16246 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16247 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16248 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16249 | mempool_free(mb, phba->mbox_mem_pool); |
| 16250 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16251 | |
| 16252 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 16253 | if (act_mbx_ndlp) { |
| 16254 | spin_lock(shost->host_lock); |
| 16255 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 16256 | spin_unlock(shost->host_lock); |
| 16257 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16258 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16259 | } |
| 16260 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16261 | /** |
| 16262 | * lpfc_drain_txq - Drain the txq |
| 16263 | * @phba: Pointer to HBA context object. |
| 16264 | * |
| 16265 | * This function attempt to submit IOCBs on the txq |
| 16266 | * to the adapter. For SLI4 adapters, the txq contains |
| 16267 | * ELS IOCBs that have been deferred because the there |
| 16268 | * are no SGLs. This congestion can occur with large |
| 16269 | * vport counts during node discovery. |
| 16270 | **/ |
| 16271 | |
| 16272 | uint32_t |
| 16273 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 16274 | { |
| 16275 | LIST_HEAD(completions); |
| 16276 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 16277 | struct lpfc_iocbq *piocbq = 0; |
| 16278 | unsigned long iflags = 0; |
| 16279 | char *fail_msg = NULL; |
| 16280 | struct lpfc_sglq *sglq; |
| 16281 | union lpfc_wqe wqe; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16282 | int txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16283 | |
| 16284 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16285 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 16286 | txq_cnt++; |
| 16287 | } |
| 16288 | |
| 16289 | if (txq_cnt > pring->txq_max) |
| 16290 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16291 | |
| 16292 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16293 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16294 | while (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16295 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 16296 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16297 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16298 | if (!piocbq) { |
| 16299 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16300 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16301 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16302 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16303 | break; |
| 16304 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16305 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16306 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16307 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16308 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16309 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16310 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16311 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16312 | |
| 16313 | /* The xri and iocb resources secured, |
| 16314 | * attempt to issue request |
| 16315 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16316 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16317 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 16318 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 16319 | fail_msg = "to convert bpl to sgl"; |
| 16320 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 16321 | fail_msg = "to convert iocb to wqe"; |
| 16322 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 16323 | fail_msg = " - Wq is full"; |
| 16324 | else |
| 16325 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 16326 | |
| 16327 | if (fail_msg) { |
| 16328 | /* Failed means we can't issue and need to cancel */ |
| 16329 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16330 | "2822 IOCB failed %s iotag 0x%x " |
| 16331 | "xri 0x%x\n", |
| 16332 | fail_msg, |
| 16333 | piocbq->iotag, piocbq->sli4_xritag); |
| 16334 | list_add_tail(&piocbq->list, &completions); |
| 16335 | } |
| 16336 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16337 | } |
| 16338 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16339 | /* Cancel all the IOCBs that cannot be issued */ |
| 16340 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 16341 | IOERR_SLI_ABORTED); |
| 16342 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16343 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16344 | } |