| 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; |
| 127 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); |
| 128 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); |
| 129 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); |
| 130 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 137 | * @q: The Work Queue to operate on. |
| 138 | * @index: The index to advance the hba index to. |
| 139 | * |
| 140 | * This routine will update the HBA index of a queue to reflect consumption of |
| 141 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 142 | * an entry the host calls this function to update the queue's internal |
| 143 | * pointers. This routine returns the number of entries that were consumed by |
| 144 | * the HBA. |
| 145 | **/ |
| 146 | static uint32_t |
| 147 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 148 | { |
| 149 | uint32_t released = 0; |
| 150 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 151 | /* sanity check on queue memory */ |
| 152 | if (unlikely(!q)) |
| 153 | return 0; |
| 154 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 155 | if (q->hba_index == index) |
| 156 | return 0; |
| 157 | do { |
| 158 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 159 | released++; |
| 160 | } while (q->hba_index != index); |
| 161 | return released; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 166 | * @q: The Mailbox Queue to operate on. |
| 167 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 168 | * |
| 169 | * This routine will copy the contents of @mqe to the next available entry on |
| 170 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 171 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 172 | * successful. If no entries are available on @q then this function will return |
| 173 | * -ENOMEM. |
| 174 | * The caller is expected to hold the hbalock when calling this routine. |
| 175 | **/ |
| 176 | static uint32_t |
| 177 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 178 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 179 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 180 | struct lpfc_register doorbell; |
| 181 | uint32_t host_index; |
| 182 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 183 | /* sanity check on queue memory */ |
| 184 | if (unlikely(!q)) |
| 185 | return -ENOMEM; |
| 186 | temp_mqe = q->qe[q->host_index].mqe; |
| 187 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 188 | /* If the host has not yet processed the next entry then we are done */ |
| 189 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 190 | return -ENOMEM; |
| 191 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 192 | /* Save off the mailbox pointer for completion */ |
| 193 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 194 | |
| 195 | /* Update the host index before invoking device */ |
| 196 | host_index = q->host_index; |
| 197 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 198 | |
| 199 | /* Ring Doorbell */ |
| 200 | doorbell.word0 = 0; |
| 201 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 202 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 203 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 209 | * @q: The Mailbox Queue to operate on. |
| 210 | * |
| 211 | * This routine will update the HBA index of a queue to reflect consumption of |
| 212 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 213 | * an entry the host calls this function to update the queue's internal |
| 214 | * pointers. This routine returns the number of entries that were consumed by |
| 215 | * the HBA. |
| 216 | **/ |
| 217 | static uint32_t |
| 218 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 219 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 220 | /* sanity check on queue memory */ |
| 221 | if (unlikely(!q)) |
| 222 | return 0; |
| 223 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 224 | /* Clear the mailbox pointer for completion */ |
| 225 | q->phba->mbox = NULL; |
| 226 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 227 | return 1; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 232 | * @q: The Event Queue to get the first valid EQE from |
| 233 | * |
| 234 | * This routine will get the first valid Event Queue Entry from @q, update |
| 235 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 236 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 237 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 238 | **/ |
| 239 | static struct lpfc_eqe * |
| 240 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 241 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 242 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 243 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 244 | |
| 245 | /* sanity check on queue memory */ |
| 246 | if (unlikely(!q)) |
| 247 | return NULL; |
| 248 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 249 | |
| 250 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 251 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 252 | return NULL; |
| 253 | /* 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] | 254 | idx = ((q->hba_index + 1) % q->entry_count); |
| 255 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 256 | return NULL; |
| 257 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 258 | q->hba_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 259 | return eqe; |
| 260 | } |
| 261 | |
| 262 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 263 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 264 | * @q: The Event Queue to disable interrupts |
| 265 | * |
| 266 | **/ |
| 267 | static inline void |
| 268 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 269 | { |
| 270 | struct lpfc_register doorbell; |
| 271 | |
| 272 | doorbell.word0 = 0; |
| 273 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 274 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 275 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 276 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 277 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 278 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 279 | } |
| 280 | |
| 281 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 282 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 283 | * @q: The Event Queue that the host has completed processing for. |
| 284 | * @arm: Indicates whether the host wants to arms this CQ. |
| 285 | * |
| 286 | * This routine will mark all Event Queue Entries on @q, from the last |
| 287 | * known completed entry to the last entry that was processed, as completed |
| 288 | * by clearing the valid bit for each completion queue entry. Then it will |
| 289 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 290 | * The internal host index in the @q will be updated by this routine to indicate |
| 291 | * that the host has finished processing the entries. The @arm parameter |
| 292 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 293 | * |
| 294 | * This function will return the number of EQEs that were popped. |
| 295 | **/ |
| 296 | uint32_t |
| 297 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 298 | { |
| 299 | uint32_t released = 0; |
| 300 | struct lpfc_eqe *temp_eqe; |
| 301 | struct lpfc_register doorbell; |
| 302 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 303 | /* sanity check on queue memory */ |
| 304 | if (unlikely(!q)) |
| 305 | return 0; |
| 306 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 307 | /* while there are valid entries */ |
| 308 | while (q->hba_index != q->host_index) { |
| 309 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 310 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 311 | released++; |
| 312 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 313 | } |
| 314 | if (unlikely(released == 0 && !arm)) |
| 315 | return 0; |
| 316 | |
| 317 | /* ring doorbell for number popped */ |
| 318 | doorbell.word0 = 0; |
| 319 | if (arm) { |
| 320 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 321 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 322 | } |
| 323 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 324 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 325 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 326 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 327 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 328 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 329 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 330 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 331 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 332 | return released; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 337 | * @q: The Completion Queue to get the first valid CQE from |
| 338 | * |
| 339 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 340 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 341 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 342 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 343 | **/ |
| 344 | static struct lpfc_cqe * |
| 345 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 346 | { |
| 347 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 348 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 349 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 350 | /* sanity check on queue memory */ |
| 351 | if (unlikely(!q)) |
| 352 | return NULL; |
| 353 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 354 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 355 | 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] | 356 | return NULL; |
| 357 | /* 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] | 358 | idx = ((q->hba_index + 1) % q->entry_count); |
| 359 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 360 | return NULL; |
| 361 | |
| 362 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 363 | q->hba_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 364 | return cqe; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 369 | * @q: The Completion Queue that the host has completed processing for. |
| 370 | * @arm: Indicates whether the host wants to arms this CQ. |
| 371 | * |
| 372 | * This routine will mark all Completion queue entries on @q, from the last |
| 373 | * known completed entry to the last entry that was processed, as completed |
| 374 | * by clearing the valid bit for each completion queue entry. Then it will |
| 375 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 376 | * The internal host index in the @q will be updated by this routine to indicate |
| 377 | * that the host has finished processing the entries. The @arm parameter |
| 378 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 379 | * |
| 380 | * This function will return the number of CQEs that were released. |
| 381 | **/ |
| 382 | uint32_t |
| 383 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 384 | { |
| 385 | uint32_t released = 0; |
| 386 | struct lpfc_cqe *temp_qe; |
| 387 | struct lpfc_register doorbell; |
| 388 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 389 | /* sanity check on queue memory */ |
| 390 | if (unlikely(!q)) |
| 391 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 392 | /* while there are valid entries */ |
| 393 | while (q->hba_index != q->host_index) { |
| 394 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 395 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 396 | released++; |
| 397 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 398 | } |
| 399 | if (unlikely(released == 0 && !arm)) |
| 400 | return 0; |
| 401 | |
| 402 | /* ring doorbell for number popped */ |
| 403 | doorbell.word0 = 0; |
| 404 | if (arm) |
| 405 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 406 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 407 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 408 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 409 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 410 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 411 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 412 | return released; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 417 | * @q: The Header Receive Queue to operate on. |
| 418 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 419 | * |
| 420 | * This routine will copy the contents of @wqe to the next available entry on |
| 421 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 422 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 423 | * index that the rqe was copied to if successful. If no entries are available |
| 424 | * on @q then this function will return -ENOMEM. |
| 425 | * The caller is expected to hold the hbalock when calling this routine. |
| 426 | **/ |
| 427 | static int |
| 428 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 429 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 430 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 431 | struct lpfc_rqe *temp_hrqe; |
| 432 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 433 | struct lpfc_register doorbell; |
| 434 | int put_index = hq->host_index; |
| 435 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 436 | /* sanity check on queue memory */ |
| 437 | if (unlikely(!hq) || unlikely(!dq)) |
| 438 | return -ENOMEM; |
| 439 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 440 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 441 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 442 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 443 | return -EINVAL; |
| 444 | if (hq->host_index != dq->host_index) |
| 445 | return -EINVAL; |
| 446 | /* If the host has not yet processed the next entry then we are done */ |
| 447 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 448 | return -EBUSY; |
| 449 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 450 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 451 | |
| 452 | /* Update the host index to point to the next slot */ |
| 453 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 454 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 455 | |
| 456 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 457 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 458 | doorbell.word0 = 0; |
| 459 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 460 | hq->entry_repost); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 461 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); |
| 462 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); |
| 463 | } |
| 464 | return put_index; |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 469 | * @q: The Header Receive Queue to operate on. |
| 470 | * |
| 471 | * This routine will update the HBA index of a queue to reflect consumption of |
| 472 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 473 | * consumed an entry the host calls this function to update the queue's |
| 474 | * internal pointers. This routine returns the number of entries that were |
| 475 | * consumed by the HBA. |
| 476 | **/ |
| 477 | static uint32_t |
| 478 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 479 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 480 | /* sanity check on queue memory */ |
| 481 | if (unlikely(!hq) || unlikely(!dq)) |
| 482 | return 0; |
| 483 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 484 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 485 | return 0; |
| 486 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 487 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 488 | return 1; |
| 489 | } |
| 490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 492 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 493 | * @phba: Pointer to HBA context object. |
| 494 | * @pring: Pointer to driver SLI ring object. |
| 495 | * |
| 496 | * This function returns pointer to next command iocb entry |
| 497 | * in the command ring. The caller must hold hbalock to prevent |
| 498 | * other threads consume the next command iocb. |
| 499 | * SLI-2/SLI-3 provide different sized iocbs. |
| 500 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 501 | static inline IOCB_t * |
| 502 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 503 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 504 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 505 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 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_resp_iocb - Get next response 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 response iocb entry |
| 514 | * in the response ring. The caller must hold hbalock to make sure |
| 515 | * that no other thread consume the next response 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_resp_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.rspringaddr) + |
| 522 | pring->sli.sli3.rspidx * phba->iocb_rsp_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_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 527 | * @phba: Pointer to HBA context object. |
| 528 | * |
| 529 | * This function is called with hbalock held. This function |
| 530 | * allocates a new driver iocb object from the iocb pool. If the |
| 531 | * allocation is successful, it returns pointer to the newly |
| 532 | * allocated iocb object else it returns NULL. |
| 533 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 534 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 535 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 536 | { |
| 537 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 538 | struct lpfc_iocbq * iocbq = NULL; |
| 539 | |
| 540 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 541 | if (iocbq) |
| 542 | phba->iocb_cnt++; |
| 543 | if (phba->iocb_cnt > phba->iocb_max) |
| 544 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 545 | return iocbq; |
| 546 | } |
| 547 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 548 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 549 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 550 | * @phba: Pointer to HBA context object. |
| 551 | * @xritag: XRI value. |
| 552 | * |
| 553 | * This function clears the sglq pointer from the array of acive |
| 554 | * sglq's. The xritag that is passed in is used to index into the |
| 555 | * array. Before the xritag can be used it needs to be adjusted |
| 556 | * by subtracting the xribase. |
| 557 | * |
| 558 | * Returns sglq ponter = success, NULL = Failure. |
| 559 | **/ |
| 560 | static struct lpfc_sglq * |
| 561 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 562 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 563 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 564 | |
| 565 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 566 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 567 | return sglq; |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 572 | * @phba: Pointer to HBA context object. |
| 573 | * @xritag: XRI value. |
| 574 | * |
| 575 | * This function returns the sglq pointer from the array of acive |
| 576 | * sglq's. The xritag that is passed in is used to index into the |
| 577 | * array. Before the xritag can be used it needs to be adjusted |
| 578 | * by subtracting the xribase. |
| 579 | * |
| 580 | * Returns sglq ponter = success, NULL = Failure. |
| 581 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 582 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 583 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 584 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 585 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 586 | |
| 587 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 588 | return sglq; |
| 589 | } |
| 590 | |
| 591 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 592 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 593 | * @phba: Pointer to HBA context object. |
| 594 | * @xritag: xri used in this exchange. |
| 595 | * @rrq: The RRQ to be cleared. |
| 596 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 597 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 598 | void |
| 599 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 600 | uint16_t xritag, |
| 601 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 602 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 603 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 604 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 605 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 606 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 607 | |
| 608 | /* The target DID could have been swapped (cable swap) |
| 609 | * we should use the ndlp from the findnode if it is |
| 610 | * available. |
| 611 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 612 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 613 | ndlp = rrq->ndlp; |
| 614 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 615 | if (!ndlp) |
| 616 | goto out; |
| 617 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 618 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 619 | rrq->send_rrq = 0; |
| 620 | rrq->xritag = 0; |
| 621 | rrq->rrq_stop_time = 0; |
| 622 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 623 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 624 | mempool_free(rrq, phba->rrq_pool); |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 629 | * @phba: Pointer to HBA context object. |
| 630 | * |
| 631 | * This function is called with hbalock held. This function |
| 632 | * Checks if stop_time (ratov from setting rrq active) has |
| 633 | * been reached, if it has and the send_rrq flag is set then |
| 634 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 635 | * then it will just call the routine to clear the rrq and |
| 636 | * free the rrq resource. |
| 637 | * The timer is set to the next rrq that is going to expire before |
| 638 | * leaving the routine. |
| 639 | * |
| 640 | **/ |
| 641 | void |
| 642 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 643 | { |
| 644 | struct lpfc_node_rrq *rrq; |
| 645 | struct lpfc_node_rrq *nextrrq; |
| 646 | unsigned long next_time; |
| 647 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 648 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 649 | |
| 650 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 651 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 652 | next_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 653 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 654 | &phba->active_rrq_list, list) { |
| 655 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 656 | list_move(&rrq->list, &send_rrq); |
| 657 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 658 | next_time = rrq->rrq_stop_time; |
| 659 | } |
| 660 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 661 | if (!list_empty(&phba->active_rrq_list)) |
| 662 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 663 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 664 | list_del(&rrq->list); |
| 665 | if (!rrq->send_rrq) |
| 666 | /* this call will free the rrq */ |
| 667 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 668 | else if (lpfc_send_rrq(phba, rrq)) { |
| 669 | /* if we send the rrq then the completion handler |
| 670 | * will clear the bit in the xribitmap. |
| 671 | */ |
| 672 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 673 | rrq); |
| 674 | } |
| 675 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /** |
| 679 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 680 | * @vport: Pointer to vport context object. |
| 681 | * @xri: The xri used in the exchange. |
| 682 | * @did: The targets DID for this exchange. |
| 683 | * |
| 684 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 685 | * rrq = rrq for this xri and target. |
| 686 | **/ |
| 687 | struct lpfc_node_rrq * |
| 688 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 689 | { |
| 690 | struct lpfc_hba *phba = vport->phba; |
| 691 | struct lpfc_node_rrq *rrq; |
| 692 | struct lpfc_node_rrq *nextrrq; |
| 693 | unsigned long iflags; |
| 694 | |
| 695 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 696 | return NULL; |
| 697 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 698 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 699 | if (rrq->vport == vport && rrq->xritag == xri && |
| 700 | rrq->nlp_DID == did){ |
| 701 | list_del(&rrq->list); |
| 702 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 703 | return rrq; |
| 704 | } |
| 705 | } |
| 706 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 707 | return NULL; |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 712 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 713 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 714 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 715 | * phba->active_rrq_list and clear the rrq. |
| 716 | * 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] | 717 | **/ |
| 718 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 719 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 720 | |
| 721 | { |
| 722 | struct lpfc_hba *phba = vport->phba; |
| 723 | struct lpfc_node_rrq *rrq; |
| 724 | struct lpfc_node_rrq *nextrrq; |
| 725 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 726 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 727 | |
| 728 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 729 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 730 | if (!ndlp) { |
| 731 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 732 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 733 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 734 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 735 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 736 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 737 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 738 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 739 | |
| 740 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 741 | list_del(&rrq->list); |
| 742 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 743 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /** |
| 747 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. |
| 748 | * @phba: Pointer to HBA context object. |
| 749 | * |
| 750 | * Remove all rrqs from the phba->active_rrq_list and free them by |
| 751 | * calling __lpfc_clr_active_rrq |
| 752 | * |
| 753 | **/ |
| 754 | void |
| 755 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) |
| 756 | { |
| 757 | struct lpfc_node_rrq *rrq; |
| 758 | struct lpfc_node_rrq *nextrrq; |
| 759 | unsigned long next_time; |
| 760 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 761 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 762 | |
| 763 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 764 | return; |
| 765 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 766 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 767 | next_time = jiffies + HZ * (phba->fc_ratov * 2); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 768 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 769 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 770 | |
| 771 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 772 | list_del(&rrq->list); |
| 773 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 774 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 775 | if (!list_empty(&phba->active_rrq_list)) |
| 776 | mod_timer(&phba->rrq_tmr, next_time); |
| 777 | } |
| 778 | |
| 779 | |
| 780 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 781 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 782 | * @phba: Pointer to HBA context object. |
| 783 | * @ndlp: Targets nodelist pointer for this exchange. |
| 784 | * @xritag the xri in the bitmap to test. |
| 785 | * |
| 786 | * This function is called with hbalock held. This function |
| 787 | * returns 0 = rrq not active for this xri |
| 788 | * 1 = rrq is valid for this xri. |
| 789 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 790 | int |
| 791 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 792 | uint16_t xritag) |
| 793 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 794 | if (!ndlp) |
| 795 | return 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 796 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 797 | return 1; |
| 798 | else |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 804 | * @phba: Pointer to HBA context object. |
| 805 | * @ndlp: nodelist pointer for this target. |
| 806 | * @xritag: xri used in this exchange. |
| 807 | * @rxid: Remote Exchange ID. |
| 808 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 809 | * |
| 810 | * This function takes the hbalock. |
| 811 | * The active bit is always set in the active rrq xri_bitmap even |
| 812 | * if there is no slot avaiable for the other rrq information. |
| 813 | * |
| 814 | * returns 0 rrq actived for this xri |
| 815 | * < 0 No memory or invalid ndlp. |
| 816 | **/ |
| 817 | int |
| 818 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 819 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 820 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 821 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 822 | struct lpfc_node_rrq *rrq; |
| 823 | int empty; |
| 824 | |
| 825 | if (!ndlp) |
| 826 | return -EINVAL; |
| 827 | |
| 828 | if (!phba->cfg_enable_rrq) |
| 829 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 830 | |
| 831 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 832 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 833 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 834 | goto out; |
| 835 | } |
| 836 | |
| 837 | /* |
| 838 | * set the active bit even if there is no mem available. |
| 839 | */ |
| 840 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 841 | goto out; |
| 842 | |
| 843 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 844 | goto out; |
| 845 | |
| 846 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
| 847 | goto out; |
| 848 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 849 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 850 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 851 | if (!rrq) { |
| 852 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 853 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 854 | " DID:0x%x Send:%d\n", |
| 855 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 856 | return -EINVAL; |
| 857 | } |
| 858 | rrq->send_rrq = send_rrq; |
| 859 | rrq->xritag = xritag; |
| 860 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 861 | rrq->ndlp = ndlp; |
| 862 | rrq->nlp_DID = ndlp->nlp_DID; |
| 863 | rrq->vport = ndlp->vport; |
| 864 | rrq->rxid = rxid; |
| 865 | rrq->send_rrq = send_rrq; |
| 866 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 867 | empty = list_empty(&phba->active_rrq_list); |
| 868 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 869 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 870 | if (empty) |
| 871 | lpfc_worker_wake_up(phba); |
| 872 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 873 | return 0; |
| 874 | out: |
| 875 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 876 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 877 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 878 | " DID:0x%x Send:%d\n", |
| 879 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 880 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 884 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 885 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 886 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 887 | * |
| 888 | * This function is called with hbalock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 889 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 890 | * list is not empty then it is successful, it returns pointer to the newly |
| 891 | * allocated sglq object else it returns NULL. |
| 892 | **/ |
| 893 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 894 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 895 | { |
| 896 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 897 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 898 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 899 | struct lpfc_scsi_buf *lpfc_cmd; |
| 900 | struct lpfc_nodelist *ndlp; |
| 901 | int found = 0; |
| 902 | |
| 903 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 904 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 905 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 906 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
| 907 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 908 | ndlp = piocbq->context_un.ndlp; |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 909 | else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) && |
| 910 | (piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 911 | ndlp = piocbq->context_un.ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 912 | else |
| 913 | ndlp = piocbq->context1; |
| 914 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 915 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 916 | start_sglq = sglq; |
| 917 | while (!found) { |
| 918 | if (!sglq) |
| 919 | return NULL; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 920 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 921 | /* This xri has an rrq outstanding for this DID. |
| 922 | * put it back in the list and get another xri. |
| 923 | */ |
| 924 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 925 | sglq = NULL; |
| 926 | list_remove_head(lpfc_sgl_list, sglq, |
| 927 | struct lpfc_sglq, list); |
| 928 | if (sglq == start_sglq) { |
| 929 | sglq = NULL; |
| 930 | break; |
| 931 | } else |
| 932 | continue; |
| 933 | } |
| 934 | sglq->ndlp = ndlp; |
| 935 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 936 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 937 | sglq->state = SGL_ALLOCATED; |
| 938 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 939 | return sglq; |
| 940 | } |
| 941 | |
| 942 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 943 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 944 | * @phba: Pointer to HBA context object. |
| 945 | * |
| 946 | * This function is called with no lock held. This function |
| 947 | * allocates a new driver iocb object from the iocb pool. If the |
| 948 | * allocation is successful, it returns pointer to the newly |
| 949 | * allocated iocb object else it returns NULL. |
| 950 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 951 | struct lpfc_iocbq * |
| 952 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 953 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 954 | struct lpfc_iocbq * iocbq = NULL; |
| 955 | unsigned long iflags; |
| 956 | |
| 957 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 958 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 959 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 960 | return iocbq; |
| 961 | } |
| 962 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 963 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 964 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 965 | * @phba: Pointer to HBA context object. |
| 966 | * @iocbq: Pointer to driver iocb object. |
| 967 | * |
| 968 | * This function is called with hbalock held to release driver |
| 969 | * iocb object to the iocb pool. The iotag in the iocb object |
| 970 | * does not change for each use of the iocb object. This function |
| 971 | * clears all other fields of the iocb object when it is freed. |
| 972 | * The sqlq structure that holds the xritag and phys and virtual |
| 973 | * mappings for the scatter gather list is retrieved from the |
| 974 | * active array of sglq. The get of the sglq pointer also clears |
| 975 | * the entry in the array. If the status of the IO indiactes that |
| 976 | * this IO was aborted then the sglq entry it put on the |
| 977 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 978 | * IO has good status or fails for any other reason then the sglq |
| 979 | * entry is added to the free list (lpfc_sgl_list). |
| 980 | **/ |
| 981 | static void |
| 982 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 983 | { |
| 984 | struct lpfc_sglq *sglq; |
| 985 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 986 | unsigned long iflag = 0; |
| 987 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 988 | |
| 989 | if (iocbq->sli4_xritag == NO_XRI) |
| 990 | sglq = NULL; |
| 991 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 992 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 993 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 994 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 995 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 996 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 997 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 998 | iflag); |
| 999 | list_add(&sglq->list, |
| 1000 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 1001 | spin_unlock_irqrestore( |
| 1002 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1003 | } else { |
| 1004 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1005 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1006 | list_add_tail(&sglq->list, |
| 1007 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1008 | |
| 1009 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1010 | if (pring->txq_cnt) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1011 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1012 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | /* |
| 1017 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1018 | */ |
| 1019 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1020 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1021 | iocbq->sli4_xritag = NO_XRI; |
| 1022 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1023 | } |
| 1024 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1025 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1026 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1027 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1028 | * @phba: Pointer to HBA context object. |
| 1029 | * @iocbq: Pointer to driver iocb object. |
| 1030 | * |
| 1031 | * This function is called with hbalock held to release driver |
| 1032 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1033 | * does not change for each use of the iocb object. This function |
| 1034 | * clears all other fields of the iocb object when it is freed. |
| 1035 | **/ |
| 1036 | static void |
| 1037 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1038 | { |
| 1039 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1040 | |
| 1041 | /* |
| 1042 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1043 | */ |
| 1044 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1045 | iocbq->sli4_xritag = NO_XRI; |
| 1046 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1047 | } |
| 1048 | |
| 1049 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1050 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1051 | * @phba: Pointer to HBA context object. |
| 1052 | * @iocbq: Pointer to driver iocb object. |
| 1053 | * |
| 1054 | * This function is called with hbalock held to release driver |
| 1055 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1056 | * does not change for each use of the iocb object. This function |
| 1057 | * clears all other fields of the iocb object when it is freed. |
| 1058 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1059 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1060 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1061 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1062 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1063 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1064 | } |
| 1065 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1066 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1067 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1068 | * @phba: Pointer to HBA context object. |
| 1069 | * @iocbq: Pointer to driver iocb object. |
| 1070 | * |
| 1071 | * This function is called with no lock held to release the iocb to |
| 1072 | * iocb pool. |
| 1073 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1074 | void |
| 1075 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1076 | { |
| 1077 | unsigned long iflags; |
| 1078 | |
| 1079 | /* |
| 1080 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1081 | */ |
| 1082 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1083 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1084 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1085 | } |
| 1086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1087 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1088 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1089 | * @phba: Pointer to HBA context object. |
| 1090 | * @iocblist: List of IOCBs. |
| 1091 | * @ulpstatus: ULP status in IOCB command field. |
| 1092 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1093 | * |
| 1094 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1095 | * on the list by invoking the complete callback function associated with the |
| 1096 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1097 | * fields. |
| 1098 | **/ |
| 1099 | void |
| 1100 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1101 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1102 | { |
| 1103 | struct lpfc_iocbq *piocb; |
| 1104 | |
| 1105 | while (!list_empty(iocblist)) { |
| 1106 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
| 1107 | |
| 1108 | if (!piocb->iocb_cmpl) |
| 1109 | lpfc_sli_release_iocbq(phba, piocb); |
| 1110 | else { |
| 1111 | piocb->iocb.ulpStatus = ulpstatus; |
| 1112 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1113 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1114 | } |
| 1115 | } |
| 1116 | return; |
| 1117 | } |
| 1118 | |
| 1119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1120 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1121 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1122 | * |
| 1123 | * This function is called by ring event handler function to get the iocb type. |
| 1124 | * This function translates the iocb command to an iocb command type used to |
| 1125 | * decide the final disposition of each completed IOCB. |
| 1126 | * The function returns |
| 1127 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1128 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1129 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1130 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1131 | * |
| 1132 | * The caller is not required to hold any lock. |
| 1133 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | static lpfc_iocb_type |
| 1135 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1136 | { |
| 1137 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1138 | |
| 1139 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1140 | return 0; |
| 1141 | |
| 1142 | switch (iocb_cmnd) { |
| 1143 | case CMD_XMIT_SEQUENCE_CR: |
| 1144 | case CMD_XMIT_SEQUENCE_CX: |
| 1145 | case CMD_XMIT_BCAST_CN: |
| 1146 | case CMD_XMIT_BCAST_CX: |
| 1147 | case CMD_ELS_REQUEST_CR: |
| 1148 | case CMD_ELS_REQUEST_CX: |
| 1149 | case CMD_CREATE_XRI_CR: |
| 1150 | case CMD_CREATE_XRI_CX: |
| 1151 | case CMD_GET_RPI_CN: |
| 1152 | case CMD_XMIT_ELS_RSP_CX: |
| 1153 | case CMD_GET_RPI_CR: |
| 1154 | case CMD_FCP_IWRITE_CR: |
| 1155 | case CMD_FCP_IWRITE_CX: |
| 1156 | case CMD_FCP_IREAD_CR: |
| 1157 | case CMD_FCP_IREAD_CX: |
| 1158 | case CMD_FCP_ICMND_CR: |
| 1159 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1160 | case CMD_FCP_TSEND_CX: |
| 1161 | case CMD_FCP_TRSP_CX: |
| 1162 | case CMD_FCP_TRECEIVE_CX: |
| 1163 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1164 | case CMD_ADAPTER_MSG: |
| 1165 | case CMD_ADAPTER_DUMP: |
| 1166 | case CMD_XMIT_SEQUENCE64_CR: |
| 1167 | case CMD_XMIT_SEQUENCE64_CX: |
| 1168 | case CMD_XMIT_BCAST64_CN: |
| 1169 | case CMD_XMIT_BCAST64_CX: |
| 1170 | case CMD_ELS_REQUEST64_CR: |
| 1171 | case CMD_ELS_REQUEST64_CX: |
| 1172 | case CMD_FCP_IWRITE64_CR: |
| 1173 | case CMD_FCP_IWRITE64_CX: |
| 1174 | case CMD_FCP_IREAD64_CR: |
| 1175 | case CMD_FCP_IREAD64_CX: |
| 1176 | case CMD_FCP_ICMND64_CR: |
| 1177 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1178 | case CMD_FCP_TSEND64_CX: |
| 1179 | case CMD_FCP_TRSP64_CX: |
| 1180 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1181 | case CMD_GEN_REQUEST64_CR: |
| 1182 | case CMD_GEN_REQUEST64_CX: |
| 1183 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1184 | case DSSCMD_IWRITE64_CR: |
| 1185 | case DSSCMD_IWRITE64_CX: |
| 1186 | case DSSCMD_IREAD64_CR: |
| 1187 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1188 | type = LPFC_SOL_IOCB; |
| 1189 | break; |
| 1190 | case CMD_ABORT_XRI_CN: |
| 1191 | case CMD_ABORT_XRI_CX: |
| 1192 | case CMD_CLOSE_XRI_CN: |
| 1193 | case CMD_CLOSE_XRI_CX: |
| 1194 | case CMD_XRI_ABORTED_CX: |
| 1195 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1196 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1197 | type = LPFC_ABORT_IOCB; |
| 1198 | break; |
| 1199 | case CMD_RCV_SEQUENCE_CX: |
| 1200 | case CMD_RCV_ELS_REQ_CX: |
| 1201 | case CMD_RCV_SEQUENCE64_CX: |
| 1202 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1203 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1204 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1205 | case CMD_IOCB_RCV_ELS64_CX: |
| 1206 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1207 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1208 | type = LPFC_UNSOL_IOCB; |
| 1209 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1210 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1211 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1212 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1213 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1214 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1215 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1216 | case CMD_IOCB_RET_HBQE64_CN: |
| 1217 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1218 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1219 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1220 | case CMD_IOCB_LOGENTRY_CN: |
| 1221 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1222 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1223 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1224 | type = LPFC_UNKNOWN_IOCB; |
| 1225 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | default: |
| 1227 | type = LPFC_UNKNOWN_IOCB; |
| 1228 | break; |
| 1229 | } |
| 1230 | |
| 1231 | return type; |
| 1232 | } |
| 1233 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1234 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1235 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1236 | * @phba: Pointer to HBA context object. |
| 1237 | * |
| 1238 | * This function is called from SLI initialization code |
| 1239 | * to configure every ring of the HBA's SLI interface. The |
| 1240 | * caller is not required to hold any lock. This function issues |
| 1241 | * a config_ring mailbox command for each ring. |
| 1242 | * This function returns zero if successful else returns a negative |
| 1243 | * error code. |
| 1244 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1245 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1246 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1247 | { |
| 1248 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1249 | LPFC_MBOXQ_t *pmb; |
| 1250 | MAILBOX_t *pmbox; |
| 1251 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1252 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1253 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1254 | if (!pmb) |
| 1255 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1256 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1257 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1258 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | lpfc_config_ring(phba, i, pmb); |
| 1260 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1261 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1262 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1263 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1265 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1266 | rc, pmbox->mbxCommand, |
| 1267 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1268 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1269 | ret = -ENXIO; |
| 1270 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1271 | } |
| 1272 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1273 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1274 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1275 | } |
| 1276 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1277 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1278 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1279 | * @phba: Pointer to HBA context object. |
| 1280 | * @pring: Pointer to driver SLI ring object. |
| 1281 | * @piocb: Pointer to the driver iocb object. |
| 1282 | * |
| 1283 | * This function is called with hbalock held. The function adds the |
| 1284 | * new iocb to txcmplq of the given ring. This function always returns |
| 1285 | * 0. If this function is called for ELS ring, this function checks if |
| 1286 | * there is a vport associated with the ELS command. This function also |
| 1287 | * starts els_tmofunc timer if this is an ELS command. |
| 1288 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1290 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1291 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1292 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1294 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1296 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
| 1297 | pring->txcmplq_max = pring->txcmplq_cnt; |
| 1298 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1299 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1300 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 1301 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1302 | if (!piocb->vport) |
| 1303 | BUG(); |
| 1304 | else |
| 1305 | mod_timer(&piocb->vport->els_tmofunc, |
| 1306 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 1307 | } |
| 1308 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1309 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1310 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | } |
| 1312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1314 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1315 | * @phba: Pointer to HBA context object. |
| 1316 | * @pring: Pointer to driver SLI ring object. |
| 1317 | * |
| 1318 | * This function is called with hbalock held to get next |
| 1319 | * iocb in txq of the given ring. If there is any iocb in |
| 1320 | * the txq, the function returns first iocb in the list after |
| 1321 | * removing the iocb from the list, else it returns NULL. |
| 1322 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1323 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1324 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1325 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1326 | struct lpfc_iocbq *cmd_iocb; |
| 1327 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1328 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 1329 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1330 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1331 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | } |
| 1333 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1334 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1335 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1336 | * @phba: Pointer to HBA context object. |
| 1337 | * @pring: Pointer to driver SLI ring object. |
| 1338 | * |
| 1339 | * This function is called with hbalock held and the caller must post the |
| 1340 | * iocb without releasing the lock. If the caller releases the lock, |
| 1341 | * iocb slot returned by the function is not guaranteed to be available. |
| 1342 | * The function returns pointer to the next available iocb slot if there |
| 1343 | * is available slot in the ring, else it returns NULL. |
| 1344 | * If the get index of the ring is ahead of the put index, the function |
| 1345 | * will post an error attention event to the worker thread to take the |
| 1346 | * HBA to offline state. |
| 1347 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1348 | static IOCB_t * |
| 1349 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1350 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1351 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1352 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
| 1353 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1354 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1355 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1356 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1357 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1358 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1359 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1360 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1361 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1362 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1364 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1365 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1366 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1367 | pring->sli.sli3.local_getidx, |
| 1368 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1369 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1370 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1371 | /* |
| 1372 | * All error attention handlers are posted to |
| 1373 | * worker thread |
| 1374 | */ |
| 1375 | phba->work_ha |= HA_ERATT; |
| 1376 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1377 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1378 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1379 | |
| 1380 | return NULL; |
| 1381 | } |
| 1382 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1383 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1384 | return NULL; |
| 1385 | } |
| 1386 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1387 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | } |
| 1389 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1390 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1391 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1392 | * @phba: Pointer to HBA context object. |
| 1393 | * @iocbq: Pointer to driver iocb object. |
| 1394 | * |
| 1395 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1396 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1397 | * array and assigns a new iotag. |
| 1398 | * The function returns the allocated iotag if successful, else returns zero. |
| 1399 | * Zero is not a valid iotag. |
| 1400 | * The caller is not required to hold any lock. |
| 1401 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1402 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1403 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1404 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1405 | struct lpfc_iocbq **new_arr; |
| 1406 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1407 | size_t new_len; |
| 1408 | struct lpfc_sli *psli = &phba->sli; |
| 1409 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1410 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1411 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1412 | iotag = psli->last_iotag; |
| 1413 | if(++iotag < psli->iocbq_lookup_len) { |
| 1414 | psli->last_iotag = iotag; |
| 1415 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1416 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1417 | iocbq->iotag = iotag; |
| 1418 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1419 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1420 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1421 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1422 | spin_unlock_irq(&phba->hbalock); |
| 1423 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1424 | GFP_KERNEL); |
| 1425 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1426 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1427 | old_arr = psli->iocbq_lookup; |
| 1428 | if (new_len <= psli->iocbq_lookup_len) { |
| 1429 | /* highly unprobable case */ |
| 1430 | kfree(new_arr); |
| 1431 | iotag = psli->last_iotag; |
| 1432 | if(++iotag < psli->iocbq_lookup_len) { |
| 1433 | psli->last_iotag = iotag; |
| 1434 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1435 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1436 | iocbq->iotag = iotag; |
| 1437 | return iotag; |
| 1438 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1439 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
| 1442 | if (psli->iocbq_lookup) |
| 1443 | memcpy(new_arr, old_arr, |
| 1444 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1445 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1446 | psli->iocbq_lookup = new_arr; |
| 1447 | psli->iocbq_lookup_len = new_len; |
| 1448 | psli->last_iotag = iotag; |
| 1449 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1450 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1451 | iocbq->iotag = iotag; |
| 1452 | kfree(old_arr); |
| 1453 | return iotag; |
| 1454 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1455 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1456 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1457 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1458 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1459 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1460 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1462 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | } |
| 1464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1465 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1466 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1467 | * @phba: Pointer to HBA context object. |
| 1468 | * @pring: Pointer to driver SLI ring object. |
| 1469 | * @iocb: Pointer to iocb slot in the ring. |
| 1470 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1471 | * posted to firmware. |
| 1472 | * |
| 1473 | * This function is called with hbalock held to post a new iocb to |
| 1474 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1475 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1476 | * a completion call back for this iocb else the function will free the |
| 1477 | * iocb object. |
| 1478 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1479 | static void |
| 1480 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1481 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1482 | { |
| 1483 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1484 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1486 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1488 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1489 | if (pring->ringno == LPFC_ELS_RING) { |
| 1490 | lpfc_debugfs_slow_ring_trc(phba, |
| 1491 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1492 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1493 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1494 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1495 | } |
| 1496 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | /* |
| 1498 | * Issue iocb command to adapter |
| 1499 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1500 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | wmb(); |
| 1502 | pring->stats.iocb_cmd++; |
| 1503 | |
| 1504 | /* |
| 1505 | * If there is no completion routine to call, we can release the |
| 1506 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1507 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1508 | */ |
| 1509 | if (nextiocb->iocb_cmpl) |
| 1510 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1511 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1512 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | |
| 1514 | /* |
| 1515 | * Let the HBA know what IOCB slot will be the next one the |
| 1516 | * driver will put a command into. |
| 1517 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1518 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1519 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1520 | } |
| 1521 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1522 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1523 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1524 | * @phba: Pointer to HBA context object. |
| 1525 | * @pring: Pointer to driver SLI ring object. |
| 1526 | * |
| 1527 | * The caller is not required to hold any lock for calling this function. |
| 1528 | * This function updates the chip attention bits for the ring to inform firmware |
| 1529 | * that there are pending work to be done for this ring and requests an |
| 1530 | * interrupt when there is space available in the ring. This function is |
| 1531 | * called when the driver is unable to post more iocbs to the ring due |
| 1532 | * to unavailability of space in the ring. |
| 1533 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1535 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1536 | { |
| 1537 | int ringno = pring->ringno; |
| 1538 | |
| 1539 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1540 | |
| 1541 | wmb(); |
| 1542 | |
| 1543 | /* |
| 1544 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1545 | * The HBA will tell us when an IOCB entry is available. |
| 1546 | */ |
| 1547 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1548 | readl(phba->CAregaddr); /* flush */ |
| 1549 | |
| 1550 | pring->stats.iocb_cmd_full++; |
| 1551 | } |
| 1552 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1553 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1554 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1555 | * @phba: Pointer to HBA context object. |
| 1556 | * @pring: Pointer to driver SLI ring object. |
| 1557 | * |
| 1558 | * This function updates the chip attention register bit for the |
| 1559 | * given ring to inform HBA that there is more work to be done |
| 1560 | * in this ring. The caller is not required to hold any lock. |
| 1561 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1562 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1563 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1564 | { |
| 1565 | int ringno = pring->ringno; |
| 1566 | |
| 1567 | /* |
| 1568 | * Tell the HBA that there is work to do in this ring. |
| 1569 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1570 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1571 | wmb(); |
| 1572 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1573 | readl(phba->CAregaddr); /* flush */ |
| 1574 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | } |
| 1576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1578 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1579 | * @phba: Pointer to HBA context object. |
| 1580 | * @pring: Pointer to driver SLI ring object. |
| 1581 | * |
| 1582 | * This function is called with hbalock held to post pending iocbs |
| 1583 | * in the txq to the firmware. This function is called when driver |
| 1584 | * detects space available in the ring. |
| 1585 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1587 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | { |
| 1589 | IOCB_t *iocb; |
| 1590 | struct lpfc_iocbq *nextiocb; |
| 1591 | |
| 1592 | /* |
| 1593 | * Check to see if: |
| 1594 | * (a) there is anything on the txq to send |
| 1595 | * (b) link is up |
| 1596 | * (c) link attention events can be processed (fcp ring only) |
| 1597 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1598 | */ |
| 1599 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1600 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1602 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | |
| 1604 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1605 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1606 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1607 | |
| 1608 | if (iocb) |
| 1609 | lpfc_sli_update_ring(phba, pring); |
| 1610 | else |
| 1611 | lpfc_sli_update_full_ring(phba, pring); |
| 1612 | } |
| 1613 | |
| 1614 | return; |
| 1615 | } |
| 1616 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1617 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1618 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1619 | * @phba: Pointer to HBA context object. |
| 1620 | * @hbqno: HBQ number. |
| 1621 | * |
| 1622 | * This function is called with hbalock held to get the next |
| 1623 | * available slot for the given HBQ. If there is free slot |
| 1624 | * available for the HBQ it will return pointer to the next available |
| 1625 | * HBQ entry else it will return NULL. |
| 1626 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1627 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1628 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1629 | { |
| 1630 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1631 | |
| 1632 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1633 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1634 | hbqp->next_hbqPutIdx = 0; |
| 1635 | |
| 1636 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1637 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1638 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1639 | |
| 1640 | hbqp->local_hbqGetIdx = getidx; |
| 1641 | |
| 1642 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1643 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1644 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1645 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1646 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1647 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1648 | hbqp->entry_count); |
| 1649 | |
| 1650 | phba->link_state = LPFC_HBA_ERROR; |
| 1651 | return NULL; |
| 1652 | } |
| 1653 | |
| 1654 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1655 | return NULL; |
| 1656 | } |
| 1657 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1658 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1659 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1660 | } |
| 1661 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1662 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1663 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1664 | * @phba: Pointer to HBA context object. |
| 1665 | * |
| 1666 | * This function is called with no lock held to free all the |
| 1667 | * hbq buffers while uninitializing the SLI interface. It also |
| 1668 | * frees the HBQ buffers returned by the firmware but not yet |
| 1669 | * processed by the upper layers. |
| 1670 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1671 | void |
| 1672 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1673 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1674 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1675 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1676 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1677 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1678 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1679 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1680 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1681 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1682 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1683 | for (i = 0; i < hbq_count; ++i) { |
| 1684 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1685 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1686 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1687 | list_del(&hbq_buf->dbuf.list); |
| 1688 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1689 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1690 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1691 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1692 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1693 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1694 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1695 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1696 | list_del(&hbq_buf->dbuf.list); |
| 1697 | if (hbq_buf->tag == -1) { |
| 1698 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1699 | (phba, hbq_buf); |
| 1700 | } else { |
| 1701 | hbqno = hbq_buf->tag >> 16; |
| 1702 | if (hbqno >= LPFC_MAX_HBQS) |
| 1703 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1704 | (phba, hbq_buf); |
| 1705 | else |
| 1706 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1707 | hbq_buf); |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | /* Mark the HBQs not in use */ |
| 1712 | phba->hbq_in_use = 0; |
| 1713 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1714 | } |
| 1715 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1716 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1717 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1718 | * @phba: Pointer to HBA context object. |
| 1719 | * @hbqno: HBQ number. |
| 1720 | * @hbq_buf: Pointer to HBQ buffer. |
| 1721 | * |
| 1722 | * This function is called with the hbalock held to post a |
| 1723 | * hbq buffer to the firmware. If the function finds an empty |
| 1724 | * slot in the HBQ, it will post the buffer. The function will return |
| 1725 | * pointer to the hbq entry if it successfully post the buffer |
| 1726 | * else it will return NULL. |
| 1727 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1728 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1729 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1730 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1731 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1732 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1733 | } |
| 1734 | |
| 1735 | /** |
| 1736 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1737 | * @phba: Pointer to HBA context object. |
| 1738 | * @hbqno: HBQ number. |
| 1739 | * @hbq_buf: Pointer to HBQ buffer. |
| 1740 | * |
| 1741 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1742 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1743 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1744 | * it successfully post the buffer else it will return an error. |
| 1745 | **/ |
| 1746 | static int |
| 1747 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1748 | struct hbq_dmabuf *hbq_buf) |
| 1749 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1750 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1751 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1752 | |
| 1753 | /* Get next HBQ entry slot to use */ |
| 1754 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1755 | if (hbqe) { |
| 1756 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1757 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1758 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1759 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1760 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1761 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1762 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1763 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1764 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1765 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1766 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1767 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1768 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1769 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1770 | return 0; |
| 1771 | } else |
| 1772 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1773 | } |
| 1774 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1775 | /** |
| 1776 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1777 | * @phba: Pointer to HBA context object. |
| 1778 | * @hbqno: HBQ number. |
| 1779 | * @hbq_buf: Pointer to HBQ buffer. |
| 1780 | * |
| 1781 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1782 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1783 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1784 | **/ |
| 1785 | static int |
| 1786 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1787 | struct hbq_dmabuf *hbq_buf) |
| 1788 | { |
| 1789 | int rc; |
| 1790 | struct lpfc_rqe hrqe; |
| 1791 | struct lpfc_rqe drqe; |
| 1792 | |
| 1793 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1794 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1795 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1796 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1797 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1798 | &hrqe, &drqe); |
| 1799 | if (rc < 0) |
| 1800 | return rc; |
| 1801 | hbq_buf->tag = rc; |
| 1802 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1806 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1807 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1808 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1809 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1810 | .mask_count = 0, |
| 1811 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1812 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1813 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1814 | .init_count = 40, |
| 1815 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1816 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1817 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1818 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1819 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1820 | .rn = 1, |
| 1821 | .entry_count = 200, |
| 1822 | .mask_count = 0, |
| 1823 | .profile = 0, |
| 1824 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1825 | .buffer_count = 0, |
| 1826 | .init_count = 0, |
| 1827 | .add_count = 5, |
| 1828 | }; |
| 1829 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1830 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1831 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1832 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1833 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1834 | }; |
| 1835 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1836 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1837 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1838 | * @phba: Pointer to HBA context object. |
| 1839 | * @hbqno: HBQ number. |
| 1840 | * @count: Number of HBQ buffers to be posted. |
| 1841 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1842 | * This function is called with no lock held to post more hbq buffers to the |
| 1843 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1844 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1845 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1846 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1847 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1848 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1849 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1850 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1851 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1852 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1853 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1854 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1855 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1856 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1857 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1858 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1859 | phba->hbqs[hbqno].buffer_count; |
| 1860 | if (!count) |
| 1861 | return 0; |
| 1862 | /* Allocate HBQ entries */ |
| 1863 | for (i = 0; i < count; i++) { |
| 1864 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1865 | if (!hbq_buffer) |
| 1866 | break; |
| 1867 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1868 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1869 | /* Check whether HBQ is still in use */ |
| 1870 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1871 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1872 | goto err; |
| 1873 | while (!list_empty(&hbq_buf_list)) { |
| 1874 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1875 | dbuf.list); |
| 1876 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1877 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1878 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1879 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1880 | posted++; |
| 1881 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1882 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1883 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1884 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1885 | return posted; |
| 1886 | err: |
| 1887 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1888 | while (!list_empty(&hbq_buf_list)) { |
| 1889 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1890 | dbuf.list); |
| 1891 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1892 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1893 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1894 | } |
| 1895 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1896 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1897 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1898 | * @phba: Pointer to HBA context object. |
| 1899 | * @qno: HBQ number. |
| 1900 | * |
| 1901 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1902 | * is called with no lock held. The function returns the number of HBQ entries |
| 1903 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1904 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1905 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1906 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1907 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1908 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1909 | return 0; |
| 1910 | else |
| 1911 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1912 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1913 | } |
| 1914 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1915 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1916 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1917 | * @phba: Pointer to HBA context object. |
| 1918 | * @qno: HBQ queue number. |
| 1919 | * |
| 1920 | * This function is called from SLI initialization code path with |
| 1921 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1922 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1923 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1924 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1925 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1926 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1927 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1928 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1929 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1930 | else |
| 1931 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1932 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1933 | } |
| 1934 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1935 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1936 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1937 | * @phba: Pointer to HBA context object. |
| 1938 | * @hbqno: HBQ number. |
| 1939 | * |
| 1940 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1941 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1942 | **/ |
| 1943 | static struct hbq_dmabuf * |
| 1944 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1945 | { |
| 1946 | struct lpfc_dmabuf *d_buf; |
| 1947 | |
| 1948 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1949 | if (!d_buf) |
| 1950 | return NULL; |
| 1951 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1952 | } |
| 1953 | |
| 1954 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1955 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1956 | * @phba: Pointer to HBA context object. |
| 1957 | * @tag: Tag of the hbq buffer. |
| 1958 | * |
| 1959 | * This function is called with hbalock held. This function searches |
| 1960 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1961 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1962 | * it returns NULL. |
| 1963 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1964 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1965 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 1966 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1967 | struct lpfc_dmabuf *d_buf; |
| 1968 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1969 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1970 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1971 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 1972 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1973 | return NULL; |
| 1974 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1975 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1976 | 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] | 1977 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1978 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1979 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1980 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1981 | } |
| 1982 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1983 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1984 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1985 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1986 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1987 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1988 | } |
| 1989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1991 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1992 | * @phba: Pointer to HBA context object. |
| 1993 | * @hbq_buffer: Pointer to HBQ buffer. |
| 1994 | * |
| 1995 | * This function is called with hbalock. This function gives back |
| 1996 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 1997 | * post the buffer, it will free the buffer. |
| 1998 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1999 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2000 | 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] | 2001 | { |
| 2002 | uint32_t hbqno; |
| 2003 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2004 | if (hbq_buffer) { |
| 2005 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2006 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2007 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2008 | } |
| 2009 | } |
| 2010 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2011 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2012 | * 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] | 2013 | * @mbxCommand: mailbox command code. |
| 2014 | * |
| 2015 | * This function is called by the mailbox event handler function to verify |
| 2016 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2017 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2018 | * and the mailbox event handler will take the HBA offline. |
| 2019 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | static int |
| 2021 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2022 | { |
| 2023 | uint8_t ret; |
| 2024 | |
| 2025 | switch (mbxCommand) { |
| 2026 | case MBX_LOAD_SM: |
| 2027 | case MBX_READ_NV: |
| 2028 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2029 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2030 | case MBX_RUN_BIU_DIAG: |
| 2031 | case MBX_INIT_LINK: |
| 2032 | case MBX_DOWN_LINK: |
| 2033 | case MBX_CONFIG_LINK: |
| 2034 | case MBX_CONFIG_RING: |
| 2035 | case MBX_RESET_RING: |
| 2036 | case MBX_READ_CONFIG: |
| 2037 | case MBX_READ_RCONFIG: |
| 2038 | case MBX_READ_SPARM: |
| 2039 | case MBX_READ_STATUS: |
| 2040 | case MBX_READ_RPI: |
| 2041 | case MBX_READ_XRI: |
| 2042 | case MBX_READ_REV: |
| 2043 | case MBX_READ_LNK_STAT: |
| 2044 | case MBX_REG_LOGIN: |
| 2045 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | case MBX_CLEAR_LA: |
| 2047 | case MBX_DUMP_MEMORY: |
| 2048 | case MBX_DUMP_CONTEXT: |
| 2049 | case MBX_RUN_DIAGS: |
| 2050 | case MBX_RESTART: |
| 2051 | case MBX_UPDATE_CFG: |
| 2052 | case MBX_DOWN_LOAD: |
| 2053 | case MBX_DEL_LD_ENTRY: |
| 2054 | case MBX_RUN_PROGRAM: |
| 2055 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2056 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2058 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2060 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | case MBX_LOAD_AREA: |
| 2062 | case MBX_RUN_BIU_DIAG64: |
| 2063 | case MBX_CONFIG_PORT: |
| 2064 | case MBX_READ_SPARM64: |
| 2065 | case MBX_READ_RPI64: |
| 2066 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2067 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2068 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | case MBX_SET_DEBUG: |
| 2070 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2071 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2072 | case MBX_REG_VPI: |
| 2073 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2074 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2075 | case MBX_PORT_CAPABILITIES: |
| 2076 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2077 | case MBX_SLI4_CONFIG: |
| 2078 | case MBX_SLI4_REQ_FTRS: |
| 2079 | case MBX_REG_FCFI: |
| 2080 | case MBX_UNREG_FCFI: |
| 2081 | case MBX_REG_VFI: |
| 2082 | case MBX_UNREG_VFI: |
| 2083 | case MBX_INIT_VPI: |
| 2084 | case MBX_INIT_VFI: |
| 2085 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2086 | case MBX_READ_EVENT_LOG_STATUS: |
| 2087 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2088 | case MBX_SECURITY_MGMT: |
| 2089 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2090 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | ret = mbxCommand; |
| 2092 | break; |
| 2093 | default: |
| 2094 | ret = MBX_SHUTDOWN; |
| 2095 | break; |
| 2096 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2097 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2099 | |
| 2100 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2101 | * 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] | 2102 | * @phba: Pointer to HBA context object. |
| 2103 | * @pmboxq: Pointer to mailbox command. |
| 2104 | * |
| 2105 | * This is completion handler function for mailbox commands issued from |
| 2106 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2107 | * mailbox event handler function with no lock held. This function |
| 2108 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2109 | * of the mailbox. |
| 2110 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2111 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2112 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | { |
| 2114 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2115 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | |
| 2117 | /* |
| 2118 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2119 | * continued running. |
| 2120 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2121 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2122 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2124 | if (pdone_q) |
| 2125 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2126 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | return; |
| 2128 | } |
| 2129 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2130 | |
| 2131 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2132 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2133 | * @phba: Pointer to HBA context object. |
| 2134 | * @pmb: Pointer to mailbox object. |
| 2135 | * |
| 2136 | * This function is the default mailbox completion handler. It |
| 2137 | * frees the memory resources associated with the completed mailbox |
| 2138 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2139 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2140 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2142 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2144 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2146 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2147 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2148 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2149 | int rc; |
| 2150 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2152 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | if (mp) { |
| 2154 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2155 | kfree(mp); |
| 2156 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2157 | |
| 2158 | /* |
| 2159 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2160 | * is in re-discovery driver need to cleanup the RPI. |
| 2161 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2162 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2163 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2164 | !pmb->u.mb.mbxStatus) { |
| 2165 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2166 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2167 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2168 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2169 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2170 | if (rc != MBX_NOT_FINISHED) |
| 2171 | return; |
| 2172 | } |
| 2173 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2174 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2175 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2176 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2177 | shost = lpfc_shost_from_vport(vport); |
| 2178 | spin_lock_irq(shost->host_lock); |
| 2179 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2180 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2181 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2182 | } |
| 2183 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2184 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2185 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2186 | lpfc_nlp_put(ndlp); |
| 2187 | pmb->context2 = NULL; |
| 2188 | } |
| 2189 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2190 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2191 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2192 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2193 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2194 | "2860 SLI authentication is required " |
| 2195 | "for INIT_LINK but has not done yet\n"); |
| 2196 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2197 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2198 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2199 | else |
| 2200 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2201 | } |
| 2202 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2203 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2204 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2205 | * @phba: Pointer to HBA context object. |
| 2206 | * |
| 2207 | * This function is called with no lock held. This function processes all |
| 2208 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2209 | * service routine processes mailbox completion interrupt and adds completed |
| 2210 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2211 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2212 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2213 | * function returns the mailbox commands to the upper layer by calling the |
| 2214 | * completion handler function of each mailbox. |
| 2215 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2217 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2219 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2221 | int rc; |
| 2222 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | |
| 2224 | phba->sli.slistat.mbox_event++; |
| 2225 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2226 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2227 | spin_lock_irq(&phba->hbalock); |
| 2228 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2229 | spin_unlock_irq(&phba->hbalock); |
| 2230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2232 | do { |
| 2233 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2234 | if (pmb == NULL) |
| 2235 | break; |
| 2236 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2237 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2239 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2240 | if (pmb->vport) { |
| 2241 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2242 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2243 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2244 | (uint32_t)pmbox->mbxCommand, |
| 2245 | pmbox->un.varWords[0], |
| 2246 | pmbox->un.varWords[1]); |
| 2247 | } |
| 2248 | else { |
| 2249 | lpfc_debugfs_disc_trc(phba->pport, |
| 2250 | LPFC_DISC_TRC_MBOX, |
| 2251 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2252 | (uint32_t)pmbox->mbxCommand, |
| 2253 | pmbox->un.varWords[0], |
| 2254 | pmbox->un.varWords[1]); |
| 2255 | } |
| 2256 | } |
| 2257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | /* |
| 2259 | * It is a fatal error if unknown mbox command completion. |
| 2260 | */ |
| 2261 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2262 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2263 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2264 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2265 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2266 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2267 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2268 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2269 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2270 | pmb), |
| 2271 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2272 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2273 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2274 | phba->work_hs = HS_FFER3; |
| 2275 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2276 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2277 | } |
| 2278 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 | if (pmbox->mbxStatus) { |
| 2280 | phba->sli.slistat.mbox_stat_err++; |
| 2281 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2282 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2283 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2284 | LOG_MBOX | LOG_SLI, |
| 2285 | "(%d):0305 Mbox cmd cmpl " |
| 2286 | "error - RETRYing Data: x%x " |
| 2287 | "(x%x/x%x) x%x x%x x%x\n", |
| 2288 | pmb->vport ? pmb->vport->vpi : 0, |
| 2289 | pmbox->mbxCommand, |
| 2290 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2291 | pmb), |
| 2292 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2293 | pmb), |
| 2294 | pmbox->mbxStatus, |
| 2295 | pmbox->un.varWords[0], |
| 2296 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2297 | pmbox->mbxStatus = 0; |
| 2298 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2299 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2300 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2301 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2306 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2307 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | "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] | 2309 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2311 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2312 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | pmb->mbox_cmpl, |
| 2314 | *((uint32_t *) pmbox), |
| 2315 | pmbox->un.varWords[0], |
| 2316 | pmbox->un.varWords[1], |
| 2317 | pmbox->un.varWords[2], |
| 2318 | pmbox->un.varWords[3], |
| 2319 | pmbox->un.varWords[4], |
| 2320 | pmbox->un.varWords[5], |
| 2321 | pmbox->un.varWords[6], |
| 2322 | pmbox->un.varWords[7]); |
| 2323 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2324 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2326 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2327 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2329 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2330 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2331 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2332 | * @phba: Pointer to HBA context object. |
| 2333 | * @pring: Pointer to driver SLI ring object. |
| 2334 | * @tag: buffer tag. |
| 2335 | * |
| 2336 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2337 | * is set in the tag the buffer is posted for a particular exchange, |
| 2338 | * the function will return the buffer without replacing the buffer. |
| 2339 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2340 | * returns the buffer and also posts another buffer to the firmware. |
| 2341 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2342 | static struct lpfc_dmabuf * |
| 2343 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2344 | struct lpfc_sli_ring *pring, |
| 2345 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2346 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2347 | struct hbq_dmabuf *hbq_entry; |
| 2348 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2349 | if (tag & QUE_BUFTAG_BIT) |
| 2350 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2351 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2352 | if (!hbq_entry) |
| 2353 | return NULL; |
| 2354 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2355 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2356 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2357 | /** |
| 2358 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2359 | * @phba: Pointer to HBA context object. |
| 2360 | * @pring: Pointer to driver SLI ring object. |
| 2361 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2362 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2363 | * @fch_type: the type for the first frame of the sequence. |
| 2364 | * |
| 2365 | * This function is called with no lock held. This function uses the r_ctl and |
| 2366 | * type of the received sequence to find the correct callback function to call |
| 2367 | * to process the sequence. |
| 2368 | **/ |
| 2369 | static int |
| 2370 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2371 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2372 | uint32_t fch_type) |
| 2373 | { |
| 2374 | int i; |
| 2375 | |
| 2376 | /* unSolicited Responses */ |
| 2377 | if (pring->prt[0].profile) { |
| 2378 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2379 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2380 | saveq); |
| 2381 | return 1; |
| 2382 | } |
| 2383 | /* We must search, based on rctl / type |
| 2384 | for the right routine */ |
| 2385 | for (i = 0; i < pring->num_mask; i++) { |
| 2386 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2387 | (pring->prt[i].type == fch_type)) { |
| 2388 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2389 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2390 | (phba, pring, saveq); |
| 2391 | return 1; |
| 2392 | } |
| 2393 | } |
| 2394 | return 0; |
| 2395 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2396 | |
| 2397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2398 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2399 | * @phba: Pointer to HBA context object. |
| 2400 | * @pring: Pointer to driver SLI ring object. |
| 2401 | * @saveq: Pointer to the unsolicited iocb. |
| 2402 | * |
| 2403 | * This function is called with no lock held by the ring event handler |
| 2404 | * when there is an unsolicited iocb posted to the response ring by the |
| 2405 | * firmware. This function gets the buffer associated with the iocbs |
| 2406 | * and calls the event handler for the ring. This function handles both |
| 2407 | * qring buffers and hbq buffers. |
| 2408 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2409 | * upper layer functions will free the iocb objects. |
| 2410 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | static int |
| 2412 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2413 | struct lpfc_iocbq *saveq) |
| 2414 | { |
| 2415 | IOCB_t * irsp; |
| 2416 | WORD5 * w5p; |
| 2417 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2418 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2419 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2420 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | |
| 2422 | match = 0; |
| 2423 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2424 | |
| 2425 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2426 | if (pring->lpfc_sli_rcv_async_status) |
| 2427 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2428 | else |
| 2429 | lpfc_printf_log(phba, |
| 2430 | KERN_WARNING, |
| 2431 | LOG_SLI, |
| 2432 | "0316 Ring %d handler: unexpected " |
| 2433 | "ASYNC_STATUS iocb received evt_code " |
| 2434 | "0x%x\n", |
| 2435 | pring->ringno, |
| 2436 | irsp->un.asyncstat.evt_code); |
| 2437 | return 1; |
| 2438 | } |
| 2439 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2440 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2441 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2442 | if (irsp->ulpBdeCount > 0) { |
| 2443 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2444 | irsp->un.ulpWord[3]); |
| 2445 | lpfc_in_buf_free(phba, dmzbuf); |
| 2446 | } |
| 2447 | |
| 2448 | if (irsp->ulpBdeCount > 1) { |
| 2449 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2450 | irsp->unsli3.sli3Words[3]); |
| 2451 | lpfc_in_buf_free(phba, dmzbuf); |
| 2452 | } |
| 2453 | |
| 2454 | if (irsp->ulpBdeCount > 2) { |
| 2455 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2456 | irsp->unsli3.sli3Words[7]); |
| 2457 | lpfc_in_buf_free(phba, dmzbuf); |
| 2458 | } |
| 2459 | |
| 2460 | return 1; |
| 2461 | } |
| 2462 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2463 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2464 | if (irsp->ulpBdeCount != 0) { |
| 2465 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2466 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2467 | if (!saveq->context2) |
| 2468 | lpfc_printf_log(phba, |
| 2469 | KERN_ERR, |
| 2470 | LOG_SLI, |
| 2471 | "0341 Ring %d Cannot find buffer for " |
| 2472 | "an unsolicited iocb. tag 0x%x\n", |
| 2473 | pring->ringno, |
| 2474 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2475 | } |
| 2476 | if (irsp->ulpBdeCount == 2) { |
| 2477 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2478 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2479 | if (!saveq->context3) |
| 2480 | lpfc_printf_log(phba, |
| 2481 | KERN_ERR, |
| 2482 | LOG_SLI, |
| 2483 | "0342 Ring %d Cannot find buffer for an" |
| 2484 | " unsolicited iocb. tag 0x%x\n", |
| 2485 | pring->ringno, |
| 2486 | irsp->unsli3.sli3Words[7]); |
| 2487 | } |
| 2488 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2489 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2490 | if (irsp->ulpBdeCount != 0) { |
| 2491 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2492 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2493 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2494 | lpfc_printf_log(phba, |
| 2495 | KERN_ERR, |
| 2496 | LOG_SLI, |
| 2497 | "0343 Ring %d Cannot find " |
| 2498 | "buffer for an unsolicited iocb" |
| 2499 | ". tag 0x%x\n", pring->ringno, |
| 2500 | irsp->un.ulpWord[3]); |
| 2501 | } |
| 2502 | if (irsp->ulpBdeCount == 2) { |
| 2503 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2504 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2505 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2506 | lpfc_printf_log(phba, |
| 2507 | KERN_ERR, |
| 2508 | LOG_SLI, |
| 2509 | "0344 Ring %d Cannot find " |
| 2510 | "buffer for an unsolicited " |
| 2511 | "iocb. tag 0x%x\n", |
| 2512 | pring->ringno, |
| 2513 | irsp->unsli3.sli3Words[7]); |
| 2514 | } |
| 2515 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2516 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2517 | if (irsp->ulpBdeCount != 0 && |
| 2518 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2519 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2520 | int found = 0; |
| 2521 | |
| 2522 | /* search continue save q for same XRI */ |
| 2523 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2524 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2525 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2526 | list_add_tail(&saveq->list, &iocbq->list); |
| 2527 | found = 1; |
| 2528 | break; |
| 2529 | } |
| 2530 | } |
| 2531 | if (!found) |
| 2532 | list_add_tail(&saveq->clist, |
| 2533 | &pring->iocb_continue_saveq); |
| 2534 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2535 | list_del_init(&iocbq->clist); |
| 2536 | saveq = iocbq; |
| 2537 | irsp = &(saveq->iocb); |
| 2538 | } else |
| 2539 | return 0; |
| 2540 | } |
| 2541 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2542 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2543 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2544 | Rctl = FC_RCTL_ELS_REQ; |
| 2545 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2546 | } else { |
| 2547 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2548 | Rctl = w5p->hcsw.Rctl; |
| 2549 | Type = w5p->hcsw.Type; |
| 2550 | |
| 2551 | /* Firmware Workaround */ |
| 2552 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2553 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2554 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2555 | Rctl = FC_RCTL_ELS_REQ; |
| 2556 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2557 | w5p->hcsw.Rctl = Rctl; |
| 2558 | w5p->hcsw.Type = Type; |
| 2559 | } |
| 2560 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2561 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2562 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2563 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2564 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2565 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2566 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2567 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2568 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | } |
| 2570 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2571 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2572 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2573 | * @phba: Pointer to HBA context object. |
| 2574 | * @pring: Pointer to driver SLI ring object. |
| 2575 | * @prspiocb: Pointer to response iocb object. |
| 2576 | * |
| 2577 | * This function looks up the iocb_lookup table to get the command iocb |
| 2578 | * corresponding to the given response iocb using the iotag of the |
| 2579 | * response iocb. This function is called with the hbalock held. |
| 2580 | * This function returns the command iocb object if it finds the command |
| 2581 | * iocb else returns NULL. |
| 2582 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2584 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2585 | struct lpfc_sli_ring *pring, |
| 2586 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2587 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2589 | uint16_t iotag; |
| 2590 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2591 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2593 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2594 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2595 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2596 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2597 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2598 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2599 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2600 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | } |
| 2602 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2604 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2605 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2606 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2607 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 | return NULL; |
| 2609 | } |
| 2610 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2611 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2612 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2613 | * @phba: Pointer to HBA context object. |
| 2614 | * @pring: Pointer to driver SLI ring object. |
| 2615 | * @iotag: IOCB tag. |
| 2616 | * |
| 2617 | * This function looks up the iocb_lookup table to get the command iocb |
| 2618 | * corresponding to the given iotag. This function is called with the |
| 2619 | * hbalock held. |
| 2620 | * This function returns the command iocb object if it finds the command |
| 2621 | * iocb else returns NULL. |
| 2622 | **/ |
| 2623 | static struct lpfc_iocbq * |
| 2624 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2625 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2626 | { |
| 2627 | struct lpfc_iocbq *cmd_iocb; |
| 2628 | |
| 2629 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2630 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2631 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2632 | /* remove from txcmpl queue list */ |
| 2633 | list_del_init(&cmd_iocb->list); |
| 2634 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2635 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2636 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2637 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2638 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2639 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2640 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2641 | iotag, phba->sli.last_iotag); |
| 2642 | return NULL; |
| 2643 | } |
| 2644 | |
| 2645 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2646 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2647 | * @phba: Pointer to HBA context object. |
| 2648 | * @pring: Pointer to driver SLI ring object. |
| 2649 | * @saveq: Pointer to the response iocb to be processed. |
| 2650 | * |
| 2651 | * This function is called by the ring event handler for non-fcp |
| 2652 | * rings when there is a new response iocb in the response ring. |
| 2653 | * The caller is not required to hold any locks. This function |
| 2654 | * gets the command iocb associated with the response iocb and |
| 2655 | * calls the completion handler for the command iocb. If there |
| 2656 | * is no completion handler, the function will free the resources |
| 2657 | * associated with command iocb. If the response iocb is for |
| 2658 | * an already aborted command iocb, the status of the completion |
| 2659 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2660 | * This function always returns 1. |
| 2661 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2663 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | struct lpfc_iocbq *saveq) |
| 2665 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2666 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | int rc = 1; |
| 2668 | unsigned long iflag; |
| 2669 | |
| 2670 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2671 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2672 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2673 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2674 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | if (cmdiocbp) { |
| 2676 | if (cmdiocbp->iocb_cmpl) { |
| 2677 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2678 | * If an ELS command failed send an event to mgmt |
| 2679 | * application. |
| 2680 | */ |
| 2681 | if (saveq->iocb.ulpStatus && |
| 2682 | (pring->ringno == LPFC_ELS_RING) && |
| 2683 | (cmdiocbp->iocb.ulpCommand == |
| 2684 | CMD_ELS_REQUEST64_CR)) |
| 2685 | lpfc_send_els_failure_event(phba, |
| 2686 | cmdiocbp, saveq); |
| 2687 | |
| 2688 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | * Post all ELS completions to the worker thread. |
| 2690 | * All other are passed to the completion callback. |
| 2691 | */ |
| 2692 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2693 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2694 | (cmdiocbp->iocb_flag & |
| 2695 | LPFC_DRIVER_ABORTED)) { |
| 2696 | spin_lock_irqsave(&phba->hbalock, |
| 2697 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2698 | cmdiocbp->iocb_flag &= |
| 2699 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2700 | spin_unlock_irqrestore(&phba->hbalock, |
| 2701 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2702 | saveq->iocb.ulpStatus = |
| 2703 | IOSTAT_LOCAL_REJECT; |
| 2704 | saveq->iocb.un.ulpWord[4] = |
| 2705 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2706 | |
| 2707 | /* Firmware could still be in progress |
| 2708 | * of DMAing payload, so don't free data |
| 2709 | * buffer till after a hbeat. |
| 2710 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2711 | spin_lock_irqsave(&phba->hbalock, |
| 2712 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2713 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2714 | spin_unlock_irqrestore(&phba->hbalock, |
| 2715 | iflag); |
| 2716 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2717 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2718 | if (saveq->iocb_flag & |
| 2719 | LPFC_EXCHANGE_BUSY) { |
| 2720 | /* Set cmdiocb flag for the |
| 2721 | * exchange busy so sgl (xri) |
| 2722 | * will not be released until |
| 2723 | * the abort xri is received |
| 2724 | * from hba. |
| 2725 | */ |
| 2726 | spin_lock_irqsave( |
| 2727 | &phba->hbalock, iflag); |
| 2728 | cmdiocbp->iocb_flag |= |
| 2729 | LPFC_EXCHANGE_BUSY; |
| 2730 | spin_unlock_irqrestore( |
| 2731 | &phba->hbalock, iflag); |
| 2732 | } |
| 2733 | if (cmdiocbp->iocb_flag & |
| 2734 | LPFC_DRIVER_ABORTED) { |
| 2735 | /* |
| 2736 | * Clear LPFC_DRIVER_ABORTED |
| 2737 | * bit in case it was driver |
| 2738 | * initiated abort. |
| 2739 | */ |
| 2740 | spin_lock_irqsave( |
| 2741 | &phba->hbalock, iflag); |
| 2742 | cmdiocbp->iocb_flag &= |
| 2743 | ~LPFC_DRIVER_ABORTED; |
| 2744 | spin_unlock_irqrestore( |
| 2745 | &phba->hbalock, iflag); |
| 2746 | cmdiocbp->iocb.ulpStatus = |
| 2747 | IOSTAT_LOCAL_REJECT; |
| 2748 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2749 | IOERR_ABORT_REQUESTED; |
| 2750 | /* |
| 2751 | * For SLI4, irsiocb contains |
| 2752 | * NO_XRI in sli_xritag, it |
| 2753 | * shall not affect releasing |
| 2754 | * sgl (xri) process. |
| 2755 | */ |
| 2756 | saveq->iocb.ulpStatus = |
| 2757 | IOSTAT_LOCAL_REJECT; |
| 2758 | saveq->iocb.un.ulpWord[4] = |
| 2759 | IOERR_SLI_ABORTED; |
| 2760 | spin_lock_irqsave( |
| 2761 | &phba->hbalock, iflag); |
| 2762 | saveq->iocb_flag |= |
| 2763 | LPFC_DELAY_MEM_FREE; |
| 2764 | spin_unlock_irqrestore( |
| 2765 | &phba->hbalock, iflag); |
| 2766 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2767 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2769 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2770 | } else |
| 2771 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2772 | } else { |
| 2773 | /* |
| 2774 | * Unknown initiating command based on the response iotag. |
| 2775 | * This could be the case on the ELS ring because of |
| 2776 | * lpfc_els_abort(). |
| 2777 | */ |
| 2778 | if (pring->ringno != LPFC_ELS_RING) { |
| 2779 | /* |
| 2780 | * Ring <ringno> handler: unexpected completion IoTag |
| 2781 | * <IoTag> |
| 2782 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2783 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2784 | "0322 Ring %d handler: " |
| 2785 | "unexpected completion IoTag x%x " |
| 2786 | "Data: x%x x%x x%x x%x\n", |
| 2787 | pring->ringno, |
| 2788 | saveq->iocb.ulpIoTag, |
| 2789 | saveq->iocb.ulpStatus, |
| 2790 | saveq->iocb.un.ulpWord[4], |
| 2791 | saveq->iocb.ulpCommand, |
| 2792 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2793 | } |
| 2794 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2795 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2796 | return rc; |
| 2797 | } |
| 2798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2800 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2801 | * @phba: Pointer to HBA context object. |
| 2802 | * @pring: Pointer to driver SLI ring object. |
| 2803 | * |
| 2804 | * This function is called from the iocb ring event handlers when |
| 2805 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2806 | * an error attention condition to the worker thread and the worker |
| 2807 | * thread will transition the HBA to offline state. |
| 2808 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2809 | static void |
| 2810 | 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] | 2811 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2812 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2813 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2814 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2815 | * rsp ring <portRspMax> |
| 2816 | */ |
| 2817 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2818 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2819 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2820 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2821 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2822 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2823 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2824 | |
| 2825 | /* |
| 2826 | * All error attention handlers are posted to |
| 2827 | * worker thread |
| 2828 | */ |
| 2829 | phba->work_ha |= HA_ERATT; |
| 2830 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2831 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2832 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2833 | |
| 2834 | return; |
| 2835 | } |
| 2836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2837 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2838 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2839 | * @ptr: Pointer to address of HBA context object. |
| 2840 | * |
| 2841 | * This function is invoked by the Error Attention polling timer when the |
| 2842 | * timer times out. It will check the SLI Error Attention register for |
| 2843 | * possible attention events. If so, it will post an Error Attention event |
| 2844 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2845 | * Error Attention polling timer for the next poll. |
| 2846 | **/ |
| 2847 | void lpfc_poll_eratt(unsigned long ptr) |
| 2848 | { |
| 2849 | struct lpfc_hba *phba; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2850 | uint32_t eratt = 0, rem; |
| 2851 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2852 | |
| 2853 | phba = (struct lpfc_hba *)ptr; |
| 2854 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2855 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 2856 | sli_intr = phba->sli.slistat.sli_intr; |
| 2857 | |
| 2858 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 2859 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 2860 | sli_intr); |
| 2861 | else |
| 2862 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 2863 | |
| 2864 | /* 64-bit integer division not supporte on 32-bit x86 - use do_div */ |
| 2865 | rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL); |
| 2866 | phba->sli.slistat.sli_ips = cnt; |
| 2867 | |
| 2868 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 2869 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2870 | /* Check chip HA register for error event */ |
| 2871 | eratt = lpfc_sli_check_eratt(phba); |
| 2872 | |
| 2873 | if (eratt) |
| 2874 | /* Tell the worker thread there is work to do */ |
| 2875 | lpfc_worker_wake_up(phba); |
| 2876 | else |
| 2877 | /* Restart the timer for next eratt poll */ |
| 2878 | mod_timer(&phba->eratt_poll, jiffies + |
| 2879 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 2880 | return; |
| 2881 | } |
| 2882 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2883 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2884 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2885 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2886 | * @phba: Pointer to HBA context object. |
| 2887 | * @pring: Pointer to driver SLI ring object. |
| 2888 | * @mask: Host attention register mask for this ring. |
| 2889 | * |
| 2890 | * This function is called from the interrupt context when there is a ring |
| 2891 | * event for the fcp ring. The caller does not hold any lock. |
| 2892 | * 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] | 2893 | * 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] | 2894 | * LE bit set. The function will call the completion handler of the command iocb |
| 2895 | * if the response iocb indicates a completion for a command iocb or it is |
| 2896 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2897 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2899 | * to check it explicitly. |
| 2900 | */ |
| 2901 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2902 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2903 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2904 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2905 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2906 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2907 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2908 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2909 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2910 | uint32_t status; |
| 2911 | uint32_t portRspPut, portRspMax; |
| 2912 | int rc = 1; |
| 2913 | lpfc_iocb_type type; |
| 2914 | unsigned long iflag; |
| 2915 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2916 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2917 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | pring->stats.iocb_event++; |
| 2919 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2920 | /* |
| 2921 | * The next available response entry should never exceed the maximum |
| 2922 | * entries. If it does, treat it as an adapter hardware error. |
| 2923 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2924 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2925 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2926 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2927 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2928 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2929 | return 1; |
| 2930 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2931 | if (phba->fcp_ring_in_use) { |
| 2932 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2933 | return 1; |
| 2934 | } else |
| 2935 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2936 | |
| 2937 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2938 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2939 | /* |
| 2940 | * Fetch an entry off the ring and copy it into a local data |
| 2941 | * structure. The copy involves a byte-swap since the |
| 2942 | * network byte order and pci byte orders are different. |
| 2943 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2944 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2945 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2946 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2947 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 2948 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2949 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2950 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2951 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2952 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2953 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2954 | irsp = &rspiocbq.iocb; |
| 2955 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2956 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2957 | pring->stats.iocb_rsp++; |
| 2958 | rsp_cmpl++; |
| 2959 | |
| 2960 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2961 | /* |
| 2962 | * If resource errors reported from HBA, reduce |
| 2963 | * queuedepths of the SCSI device. |
| 2964 | */ |
| 2965 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 2966 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 2967 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2968 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2969 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2970 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2971 | } |
| 2972 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2973 | /* Rsp ring <ringno> error: IOCB */ |
| 2974 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2975 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2976 | "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] | 2977 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2978 | irsp->un.ulpWord[0], |
| 2979 | irsp->un.ulpWord[1], |
| 2980 | irsp->un.ulpWord[2], |
| 2981 | irsp->un.ulpWord[3], |
| 2982 | irsp->un.ulpWord[4], |
| 2983 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2984 | *(uint32_t *)&irsp->un1, |
| 2985 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | switch (type) { |
| 2989 | case LPFC_ABORT_IOCB: |
| 2990 | case LPFC_SOL_IOCB: |
| 2991 | /* |
| 2992 | * Idle exchange closed via ABTS from port. No iocb |
| 2993 | * resources need to be recovered. |
| 2994 | */ |
| 2995 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2996 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2997 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2998 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2999 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3000 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | break; |
| 3002 | } |
| 3003 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3004 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3005 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3006 | if (unlikely(!cmdiocbq)) |
| 3007 | break; |
| 3008 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3009 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3010 | if (cmdiocbq->iocb_cmpl) { |
| 3011 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3012 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3013 | &rspiocbq); |
| 3014 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3015 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3016 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3017 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3018 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3019 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3020 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3021 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | default: |
| 3023 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3024 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3025 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3026 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3027 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3028 | dev_warn(&((phba->pcidev)->dev), |
| 3029 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | phba->brd_no, adaptermsg); |
| 3031 | } else { |
| 3032 | /* Unknown IOCB command */ |
| 3033 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3034 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3035 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3036 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3037 | irsp->ulpStatus, |
| 3038 | irsp->ulpIoTag, |
| 3039 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3040 | } |
| 3041 | break; |
| 3042 | } |
| 3043 | |
| 3044 | /* |
| 3045 | * The response IOCB has been processed. Update the ring |
| 3046 | * pointer in SLIM. If the port response put pointer has not |
| 3047 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3048 | * response put pointer. |
| 3049 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3050 | writel(pring->sli.sli3.rspidx, |
| 3051 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3052 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3053 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3054 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3055 | } |
| 3056 | |
| 3057 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3058 | pring->stats.iocb_rsp_full++; |
| 3059 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3060 | writel(status, phba->CAregaddr); |
| 3061 | readl(phba->CAregaddr); |
| 3062 | } |
| 3063 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3064 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3065 | pring->stats.iocb_cmd_empty++; |
| 3066 | |
| 3067 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3068 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | lpfc_sli_resume_iocb(phba, pring); |
| 3070 | |
| 3071 | if ((pring->lpfc_sli_cmd_available)) |
| 3072 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3073 | |
| 3074 | } |
| 3075 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3076 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3077 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | return rc; |
| 3079 | } |
| 3080 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3081 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3082 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3083 | * @phba: Pointer to HBA context object. |
| 3084 | * @pring: Pointer to driver SLI ring object. |
| 3085 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3086 | * |
| 3087 | * This function is called from the worker thread when there is a slow-path |
| 3088 | * response IOCB to process. This function chains all the response iocbs until |
| 3089 | * seeing the iocb with the LE bit set. The function will call |
| 3090 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3091 | * completion of a command iocb. The function will call the |
| 3092 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3093 | * The function frees the resources or calls the completion handler if this |
| 3094 | * iocb is an abort completion. The function returns NULL when the response |
| 3095 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3096 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3097 | * response iocb passed in. |
| 3098 | **/ |
| 3099 | static struct lpfc_iocbq * |
| 3100 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3101 | struct lpfc_iocbq *rspiocbp) |
| 3102 | { |
| 3103 | struct lpfc_iocbq *saveq; |
| 3104 | struct lpfc_iocbq *cmdiocbp; |
| 3105 | struct lpfc_iocbq *next_iocb; |
| 3106 | IOCB_t *irsp = NULL; |
| 3107 | uint32_t free_saveq; |
| 3108 | uint8_t iocb_cmd_type; |
| 3109 | lpfc_iocb_type type; |
| 3110 | unsigned long iflag; |
| 3111 | int rc; |
| 3112 | |
| 3113 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3114 | /* First add the response iocb to the countinueq list */ |
| 3115 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3116 | pring->iocb_continueq_cnt++; |
| 3117 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3118 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3119 | irsp = &rspiocbp->iocb; |
| 3120 | if (irsp->ulpLe) { |
| 3121 | /* |
| 3122 | * By default, the driver expects to free all resources |
| 3123 | * associated with this iocb completion. |
| 3124 | */ |
| 3125 | free_saveq = 1; |
| 3126 | saveq = list_get_first(&pring->iocb_continueq, |
| 3127 | struct lpfc_iocbq, list); |
| 3128 | irsp = &(saveq->iocb); |
| 3129 | list_del_init(&pring->iocb_continueq); |
| 3130 | pring->iocb_continueq_cnt = 0; |
| 3131 | |
| 3132 | pring->stats.iocb_rsp++; |
| 3133 | |
| 3134 | /* |
| 3135 | * If resource errors reported from HBA, reduce |
| 3136 | * queuedepths of the SCSI device. |
| 3137 | */ |
| 3138 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3139 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3140 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3141 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3142 | phba->lpfc_rampdown_queue_depth(phba); |
| 3143 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3144 | } |
| 3145 | |
| 3146 | if (irsp->ulpStatus) { |
| 3147 | /* Rsp ring <ringno> error: IOCB */ |
| 3148 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3149 | "0328 Rsp Ring %d error: " |
| 3150 | "IOCB Data: " |
| 3151 | "x%x x%x x%x x%x " |
| 3152 | "x%x x%x x%x x%x " |
| 3153 | "x%x x%x x%x x%x " |
| 3154 | "x%x x%x x%x x%x\n", |
| 3155 | pring->ringno, |
| 3156 | irsp->un.ulpWord[0], |
| 3157 | irsp->un.ulpWord[1], |
| 3158 | irsp->un.ulpWord[2], |
| 3159 | irsp->un.ulpWord[3], |
| 3160 | irsp->un.ulpWord[4], |
| 3161 | irsp->un.ulpWord[5], |
| 3162 | *(((uint32_t *) irsp) + 6), |
| 3163 | *(((uint32_t *) irsp) + 7), |
| 3164 | *(((uint32_t *) irsp) + 8), |
| 3165 | *(((uint32_t *) irsp) + 9), |
| 3166 | *(((uint32_t *) irsp) + 10), |
| 3167 | *(((uint32_t *) irsp) + 11), |
| 3168 | *(((uint32_t *) irsp) + 12), |
| 3169 | *(((uint32_t *) irsp) + 13), |
| 3170 | *(((uint32_t *) irsp) + 14), |
| 3171 | *(((uint32_t *) irsp) + 15)); |
| 3172 | } |
| 3173 | |
| 3174 | /* |
| 3175 | * Fetch the IOCB command type and call the correct completion |
| 3176 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3177 | * get freed back to the lpfc_iocb_list by the discovery |
| 3178 | * kernel thread. |
| 3179 | */ |
| 3180 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3181 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3182 | switch (type) { |
| 3183 | case LPFC_SOL_IOCB: |
| 3184 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3185 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3186 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3187 | break; |
| 3188 | |
| 3189 | case LPFC_UNSOL_IOCB: |
| 3190 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3191 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3192 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3193 | if (!rc) |
| 3194 | free_saveq = 0; |
| 3195 | break; |
| 3196 | |
| 3197 | case LPFC_ABORT_IOCB: |
| 3198 | cmdiocbp = NULL; |
| 3199 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3200 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3201 | saveq); |
| 3202 | if (cmdiocbp) { |
| 3203 | /* Call the specified completion routine */ |
| 3204 | if (cmdiocbp->iocb_cmpl) { |
| 3205 | spin_unlock_irqrestore(&phba->hbalock, |
| 3206 | iflag); |
| 3207 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3208 | saveq); |
| 3209 | spin_lock_irqsave(&phba->hbalock, |
| 3210 | iflag); |
| 3211 | } else |
| 3212 | __lpfc_sli_release_iocbq(phba, |
| 3213 | cmdiocbp); |
| 3214 | } |
| 3215 | break; |
| 3216 | |
| 3217 | case LPFC_UNKNOWN_IOCB: |
| 3218 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3219 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3220 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3221 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3222 | MAX_MSG_DATA); |
| 3223 | dev_warn(&((phba->pcidev)->dev), |
| 3224 | "lpfc%d: %s\n", |
| 3225 | phba->brd_no, adaptermsg); |
| 3226 | } else { |
| 3227 | /* Unknown IOCB command */ |
| 3228 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3229 | "0335 Unknown IOCB " |
| 3230 | "command Data: x%x " |
| 3231 | "x%x x%x x%x\n", |
| 3232 | irsp->ulpCommand, |
| 3233 | irsp->ulpStatus, |
| 3234 | irsp->ulpIoTag, |
| 3235 | irsp->ulpContext); |
| 3236 | } |
| 3237 | break; |
| 3238 | } |
| 3239 | |
| 3240 | if (free_saveq) { |
| 3241 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3242 | &saveq->list, list) { |
| 3243 | list_del(&rspiocbp->list); |
| 3244 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3245 | } |
| 3246 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3247 | } |
| 3248 | rspiocbp = NULL; |
| 3249 | } |
| 3250 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3251 | return rspiocbp; |
| 3252 | } |
| 3253 | |
| 3254 | /** |
| 3255 | * 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] | 3256 | * @phba: Pointer to HBA context object. |
| 3257 | * @pring: Pointer to driver SLI ring object. |
| 3258 | * @mask: Host attention register mask for this ring. |
| 3259 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3260 | * This routine wraps the actual slow_ring event process routine from the |
| 3261 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3262 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3263 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3264 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3265 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3267 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3268 | } |
| 3269 | |
| 3270 | /** |
| 3271 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3272 | * @phba: Pointer to HBA context object. |
| 3273 | * @pring: Pointer to driver SLI ring object. |
| 3274 | * @mask: Host attention register mask for this ring. |
| 3275 | * |
| 3276 | * This function is called from the worker thread when there is a ring event |
| 3277 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3278 | * remove each response iocb in the response ring and calls the handle |
| 3279 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3280 | **/ |
| 3281 | static void |
| 3282 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3283 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3284 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3285 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3286 | IOCB_t *entry; |
| 3287 | IOCB_t *irsp = NULL; |
| 3288 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3289 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3290 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3291 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3292 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3293 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3294 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | pring->stats.iocb_event++; |
| 3296 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3297 | /* |
| 3298 | * The next available response entry should never exceed the maximum |
| 3299 | * entries. If it does, treat it as an adapter hardware error. |
| 3300 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3301 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3303 | if (portRspPut >= portRspMax) { |
| 3304 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3305 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3306 | * rsp ring <portRspMax> |
| 3307 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3308 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3309 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3310 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3311 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3313 | phba->link_state = LPFC_HBA_ERROR; |
| 3314 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | |
| 3316 | phba->work_hs = HS_FFER3; |
| 3317 | lpfc_handle_eratt(phba); |
| 3318 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3319 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3323 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | /* |
| 3325 | * Build a completion list and call the appropriate handler. |
| 3326 | * The process is to get the next available response iocb, get |
| 3327 | * a free iocb from the list, copy the response data into the |
| 3328 | * free iocb, insert to the continuation list, and update the |
| 3329 | * next response index to slim. This process makes response |
| 3330 | * iocb's in the ring available to DMA as fast as possible but |
| 3331 | * pays a penalty for a copy operation. Since the iocb is |
| 3332 | * only 32 bytes, this penalty is considered small relative to |
| 3333 | * the PCI reads for register values and a slim write. When |
| 3334 | * the ulpLe field is set, the entire Command has been |
| 3335 | * received. |
| 3336 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3337 | entry = lpfc_resp_iocb(phba, pring); |
| 3338 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3339 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3340 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | if (rspiocbp == NULL) { |
| 3342 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3343 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | break; |
| 3345 | } |
| 3346 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3347 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3348 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | irsp = &rspiocbp->iocb; |
| 3350 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3351 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3352 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3353 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3354 | if (pring->ringno == LPFC_ELS_RING) { |
| 3355 | lpfc_debugfs_slow_ring_trc(phba, |
| 3356 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3357 | *(((uint32_t *) irsp) + 4), |
| 3358 | *(((uint32_t *) irsp) + 6), |
| 3359 | *(((uint32_t *) irsp) + 7)); |
| 3360 | } |
| 3361 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3362 | writel(pring->sli.sli3.rspidx, |
| 3363 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3364 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3365 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3366 | /* Handle the response IOCB */ |
| 3367 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3368 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | |
| 3370 | /* |
| 3371 | * If the port response put pointer has not been updated, sync |
| 3372 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3373 | * response put pointer. |
| 3374 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3375 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3377 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3378 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3380 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | /* At least one response entry has been freed */ |
| 3382 | pring->stats.iocb_rsp_full++; |
| 3383 | /* SET RxRE_RSP in Chip Att register */ |
| 3384 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3385 | writel(status, phba->CAregaddr); |
| 3386 | readl(phba->CAregaddr); /* flush */ |
| 3387 | } |
| 3388 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3389 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3390 | pring->stats.iocb_cmd_empty++; |
| 3391 | |
| 3392 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3393 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3394 | lpfc_sli_resume_iocb(phba, pring); |
| 3395 | |
| 3396 | if ((pring->lpfc_sli_cmd_available)) |
| 3397 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3398 | |
| 3399 | } |
| 3400 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3401 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3402 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | } |
| 3404 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3405 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3406 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3407 | * @phba: Pointer to HBA context object. |
| 3408 | * @pring: Pointer to driver SLI ring object. |
| 3409 | * @mask: Host attention register mask for this ring. |
| 3410 | * |
| 3411 | * This function is called from the worker thread when there is a pending |
| 3412 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3413 | * queue. The caller does not hold any lock. The function will remove each |
| 3414 | * response iocb from the response worker queue and calls the handle |
| 3415 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3416 | **/ |
| 3417 | static void |
| 3418 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3419 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3420 | { |
| 3421 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3422 | struct hbq_dmabuf *dmabuf; |
| 3423 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3424 | unsigned long iflag; |
| 3425 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3426 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3427 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3428 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3429 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3430 | /* Get the response iocb from the head of work queue */ |
| 3431 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3432 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3433 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3434 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3435 | |
| 3436 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3437 | case CQE_CODE_COMPL_WQE: |
| 3438 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3439 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3440 | /* Translate ELS WCQE to response IOCBQ */ |
| 3441 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3442 | irspiocbq); |
| 3443 | if (irspiocbq) |
| 3444 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3445 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3446 | break; |
| 3447 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3448 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3449 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3450 | cq_event); |
| 3451 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3452 | break; |
| 3453 | default: |
| 3454 | break; |
| 3455 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3460 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3461 | * @phba: Pointer to HBA context object. |
| 3462 | * @pring: Pointer to driver SLI ring object. |
| 3463 | * |
| 3464 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3465 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3466 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3467 | * the return of this function. The caller is not required to hold any locks. |
| 3468 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3469 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3470 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3471 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3472 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3475 | if (pring->ringno == LPFC_ELS_RING) { |
| 3476 | lpfc_fabric_abort_hba(phba); |
| 3477 | } |
| 3478 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3479 | /* Error everything on txq and txcmplq |
| 3480 | * First do the txq. |
| 3481 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3482 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3483 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | |
| 3486 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3487 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3488 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3489 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3490 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3491 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3492 | /* Cancel all the IOCBs from the completions list */ |
| 3493 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3494 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3495 | } |
| 3496 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3497 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3498 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3499 | * @phba: Pointer to HBA context object. |
| 3500 | * |
| 3501 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3502 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3503 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3504 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3505 | * slot has been permanently disabled. |
| 3506 | **/ |
| 3507 | void |
| 3508 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3509 | { |
| 3510 | LIST_HEAD(txq); |
| 3511 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3512 | struct lpfc_sli *psli = &phba->sli; |
| 3513 | struct lpfc_sli_ring *pring; |
| 3514 | |
| 3515 | /* Currently, only one fcp ring */ |
| 3516 | pring = &psli->ring[psli->fcp_ring]; |
| 3517 | |
| 3518 | spin_lock_irq(&phba->hbalock); |
| 3519 | /* Retrieve everything on txq */ |
| 3520 | list_splice_init(&pring->txq, &txq); |
| 3521 | pring->txq_cnt = 0; |
| 3522 | |
| 3523 | /* Retrieve everything on the txcmplq */ |
| 3524 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3525 | pring->txcmplq_cnt = 0; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3526 | |
| 3527 | /* Indicate the I/O queues are flushed */ |
| 3528 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3529 | spin_unlock_irq(&phba->hbalock); |
| 3530 | |
| 3531 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3532 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3533 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3534 | |
| 3535 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3536 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3537 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3541 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3542 | * @phba: Pointer to HBA context object. |
| 3543 | * @mask: Bit mask to be checked. |
| 3544 | * |
| 3545 | * This function reads the host status register and compares |
| 3546 | * with the provided bit mask to check if HBA completed |
| 3547 | * the restart. This function will wait in a loop for the |
| 3548 | * HBA to complete restart. If the HBA does not restart within |
| 3549 | * 15 iterations, the function will reset the HBA again. The |
| 3550 | * function returns 1 when HBA fail to restart otherwise returns |
| 3551 | * zero. |
| 3552 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3553 | static int |
| 3554 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3556 | uint32_t status; |
| 3557 | int i = 0; |
| 3558 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3560 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3561 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3562 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3564 | /* |
| 3565 | * Check status register every 100ms for 5 retries, then every |
| 3566 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3567 | * every 2.5 sec for 4. |
| 3568 | * Break our of the loop if errors occurred during init. |
| 3569 | */ |
| 3570 | while (((status & mask) != mask) && |
| 3571 | !(status & HS_FFERM) && |
| 3572 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3573 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3574 | if (i <= 5) |
| 3575 | msleep(10); |
| 3576 | else if (i <= 10) |
| 3577 | msleep(500); |
| 3578 | else |
| 3579 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3581 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3582 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3583 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3584 | lpfc_sli_brdrestart(phba); |
| 3585 | } |
| 3586 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3587 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3588 | retval = 1; |
| 3589 | break; |
| 3590 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3593 | /* Check to see if any errors occurred during init */ |
| 3594 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3595 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3596 | "2751 Adapter failed to restart, " |
| 3597 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3598 | status, |
| 3599 | readl(phba->MBslimaddr + 0xa8), |
| 3600 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3601 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3602 | retval = 1; |
| 3603 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3604 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3605 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | } |
| 3607 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3608 | /** |
| 3609 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3610 | * @phba: Pointer to HBA context object. |
| 3611 | * @mask: Bit mask to be checked. |
| 3612 | * |
| 3613 | * This function checks the host status register to check if HBA is |
| 3614 | * ready. This function will wait in a loop for the HBA to be ready |
| 3615 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3616 | * function again. The function returns 1 when HBA fail to be ready |
| 3617 | * otherwise returns zero. |
| 3618 | **/ |
| 3619 | static int |
| 3620 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3621 | { |
| 3622 | uint32_t status; |
| 3623 | int retval = 0; |
| 3624 | |
| 3625 | /* Read the HBA Host Status Register */ |
| 3626 | status = lpfc_sli4_post_status_check(phba); |
| 3627 | |
| 3628 | if (status) { |
| 3629 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3630 | lpfc_sli_brdrestart(phba); |
| 3631 | status = lpfc_sli4_post_status_check(phba); |
| 3632 | } |
| 3633 | |
| 3634 | /* Check to see if any errors occurred during init */ |
| 3635 | if (status) { |
| 3636 | phba->link_state = LPFC_HBA_ERROR; |
| 3637 | retval = 1; |
| 3638 | } else |
| 3639 | phba->sli4_hba.intr_enable = 0; |
| 3640 | |
| 3641 | return retval; |
| 3642 | } |
| 3643 | |
| 3644 | /** |
| 3645 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3646 | * @phba: Pointer to HBA context object. |
| 3647 | * @mask: Bit mask to be checked. |
| 3648 | * |
| 3649 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3650 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3651 | **/ |
| 3652 | int |
| 3653 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3654 | { |
| 3655 | return phba->lpfc_sli_brdready(phba, mask); |
| 3656 | } |
| 3657 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3658 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3661 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3662 | * @phba: Pointer to HBA context object. |
| 3663 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3664 | * This function is called before resetting an HBA. This function is called |
| 3665 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3666 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3667 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3668 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3669 | uint32_t __iomem *resp_buf; |
| 3670 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3671 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3672 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3673 | int i; |
| 3674 | uint8_t hdrtype; |
| 3675 | |
| 3676 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3677 | if (hdrtype != 0x80 || |
| 3678 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3679 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3680 | return; |
| 3681 | |
| 3682 | /* |
| 3683 | * Tell the other part of the chip to suspend temporarily all |
| 3684 | * its DMA activity. |
| 3685 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3686 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3687 | |
| 3688 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3689 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3690 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3691 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3692 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3693 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3694 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3695 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3696 | return; |
| 3697 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3698 | /* Clear Chip error bit */ |
| 3699 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3700 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | mbox = 0; |
| 3704 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3705 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3706 | |
| 3707 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3708 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3709 | writel(mbox, mbox_buf); |
| 3710 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3711 | for (i = 0; i < 50; i++) { |
| 3712 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3713 | return; |
| 3714 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3715 | mdelay(1); |
| 3716 | else |
| 3717 | break; |
| 3718 | } |
| 3719 | resp_data = 0; |
| 3720 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3721 | return; |
| 3722 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3723 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3724 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3725 | goto restore_hc; |
| 3726 | else |
| 3727 | goto clear_errat; |
| 3728 | } |
| 3729 | |
| 3730 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3731 | resp_data = 0; |
| 3732 | for (i = 0; i < 500; i++) { |
| 3733 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3734 | return; |
| 3735 | if (resp_data != mbox) |
| 3736 | mdelay(1); |
| 3737 | else |
| 3738 | break; |
| 3739 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3740 | |
| 3741 | clear_errat: |
| 3742 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3743 | while (++i < 500) { |
| 3744 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3745 | return; |
| 3746 | if (!(ha_copy & HA_ERATT)) |
| 3747 | mdelay(1); |
| 3748 | else |
| 3749 | break; |
| 3750 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3751 | |
| 3752 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3753 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3754 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3758 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3759 | writel(hc_copy, phba->HCregaddr); |
| 3760 | readl(phba->HCregaddr); /* flush */ |
| 3761 | } |
| 3762 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3763 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3764 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3765 | * @phba: Pointer to HBA context object. |
| 3766 | * |
| 3767 | * This function issues a kill_board mailbox command and waits for |
| 3768 | * the error attention interrupt. This function is called for stopping |
| 3769 | * the firmware processing. The caller is not required to hold any |
| 3770 | * locks. This function calls lpfc_hba_down_post function to free |
| 3771 | * any pending commands after the kill. The function will return 1 when it |
| 3772 | * fails to kill the board else will return 0. |
| 3773 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3774 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3775 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3776 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3777 | struct lpfc_sli *psli; |
| 3778 | LPFC_MBOXQ_t *pmb; |
| 3779 | uint32_t status; |
| 3780 | uint32_t ha_copy; |
| 3781 | int retval; |
| 3782 | int i = 0; |
| 3783 | |
| 3784 | psli = &phba->sli; |
| 3785 | |
| 3786 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3787 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3788 | "0329 Kill HBA Data: x%x x%x\n", |
| 3789 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3790 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3791 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3792 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3793 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3794 | |
| 3795 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3796 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3797 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3798 | spin_unlock_irq(&phba->hbalock); |
| 3799 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3800 | return 1; |
| 3801 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3802 | status &= ~HC_ERINT_ENA; |
| 3803 | writel(status, phba->HCregaddr); |
| 3804 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3805 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3806 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3807 | |
| 3808 | lpfc_kill_board(phba, pmb); |
| 3809 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3810 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3811 | |
| 3812 | if (retval != MBX_SUCCESS) { |
| 3813 | if (retval != MBX_BUSY) |
| 3814 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3815 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3816 | "2752 KILL_BOARD command failed retval %d\n", |
| 3817 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3818 | spin_lock_irq(&phba->hbalock); |
| 3819 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3820 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3821 | return 1; |
| 3822 | } |
| 3823 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3824 | spin_lock_irq(&phba->hbalock); |
| 3825 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3826 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3827 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3828 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3829 | |
| 3830 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3831 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3832 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3833 | * board is now undefined. |
| 3834 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3835 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3836 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3837 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3838 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3839 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3840 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3844 | if (ha_copy & HA_ERATT) { |
| 3845 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3846 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3847 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3848 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3849 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3850 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3851 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3852 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3853 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3854 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3855 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3856 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3857 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3858 | } |
| 3859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3860 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3861 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3862 | * @phba: Pointer to HBA context object. |
| 3863 | * |
| 3864 | * This function resets the HBA by writing HC_INITFF to the control |
| 3865 | * register. After the HBA resets, this function resets all the iocb ring |
| 3866 | * indices. This function disables PCI layer parity checking during |
| 3867 | * the reset. |
| 3868 | * This function returns 0 always. |
| 3869 | * The caller is not required to hold any locks. |
| 3870 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3871 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3872 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3873 | { |
| 3874 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3876 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3878 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3879 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3881 | /* Reset HBA */ |
| 3882 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3883 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3884 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | |
| 3886 | /* perform board reset */ |
| 3887 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3888 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3889 | phba->pport->fc_myDID = 0; |
| 3890 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3891 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3892 | /* Turn off parity checking and serr during the physical reset */ |
| 3893 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3894 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 3895 | (cfg_value & |
| 3896 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3897 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3898 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 3899 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3900 | /* Now toggle INITFF bit in the Host Control Register */ |
| 3901 | writel(HC_INITFF, phba->HCregaddr); |
| 3902 | mdelay(1); |
| 3903 | readl(phba->HCregaddr); /* flush */ |
| 3904 | writel(0, phba->HCregaddr); |
| 3905 | readl(phba->HCregaddr); /* flush */ |
| 3906 | |
| 3907 | /* Restore PCI cmd register */ |
| 3908 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | |
| 3910 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3911 | for (i = 0; i < psli->num_rings; i++) { |
| 3912 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3914 | pring->sli.sli3.rspidx = 0; |
| 3915 | pring->sli.sli3.next_cmdidx = 0; |
| 3916 | pring->sli.sli3.local_getidx = 0; |
| 3917 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3918 | pring->missbufcnt = 0; |
| 3919 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3920 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3921 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3922 | return 0; |
| 3923 | } |
| 3924 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3925 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3926 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 3927 | * @phba: Pointer to HBA context object. |
| 3928 | * |
| 3929 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 3930 | * checking during resets the device. The caller is not required to hold |
| 3931 | * any locks. |
| 3932 | * |
| 3933 | * This function returns 0 always. |
| 3934 | **/ |
| 3935 | int |
| 3936 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 3937 | { |
| 3938 | struct lpfc_sli *psli = &phba->sli; |
| 3939 | uint16_t cfg_value; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3940 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3941 | |
| 3942 | /* Reset HBA */ |
| 3943 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3944 | "0295 Reset HBA Data: x%x x%x\n", |
| 3945 | phba->pport->port_state, psli->sli_flag); |
| 3946 | |
| 3947 | /* perform board reset */ |
| 3948 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3949 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3950 | phba->pport->fc_myDID = 0; |
| 3951 | phba->pport->fc_prevDID = 0; |
| 3952 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3953 | spin_lock_irq(&phba->hbalock); |
| 3954 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 3955 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3956 | spin_unlock_irq(&phba->hbalock); |
| 3957 | |
| 3958 | /* Now physically reset the device */ |
| 3959 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3960 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3961 | |
| 3962 | /* Turn off parity checking and serr during the physical reset */ |
| 3963 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3964 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 3965 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3966 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 3967 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3968 | rc = lpfc_pci_function_reset(phba); |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 3969 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3970 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3971 | /* Restore PCI cmd register */ |
| 3972 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 3973 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3974 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | /** |
| 3978 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3979 | * @phba: Pointer to HBA context object. |
| 3980 | * |
| 3981 | * This function is called in the SLI initialization code path to |
| 3982 | * restart the HBA. The caller is not required to hold any lock. |
| 3983 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 3984 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 3985 | * function to free any pending commands. The function enables |
| 3986 | * POST only during the first initialization. The function returns zero. |
| 3987 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 3988 | * command before the return of this function. |
| 3989 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3990 | static int |
| 3991 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3992 | { |
| 3993 | MAILBOX_t *mb; |
| 3994 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3995 | volatile uint32_t word0; |
| 3996 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3997 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3998 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3999 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4000 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4001 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4002 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4003 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4004 | psli = &phba->sli; |
| 4005 | |
| 4006 | /* Restart HBA */ |
| 4007 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4008 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4009 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4010 | |
| 4011 | word0 = 0; |
| 4012 | mb = (MAILBOX_t *) &word0; |
| 4013 | mb->mbxCommand = MBX_RESTART; |
| 4014 | mb->mbxHc = 1; |
| 4015 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4016 | lpfc_reset_barrier(phba); |
| 4017 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4018 | to_slim = phba->MBslimaddr; |
| 4019 | writel(*(uint32_t *) mb, to_slim); |
| 4020 | readl(to_slim); /* flush */ |
| 4021 | |
| 4022 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4023 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4024 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4025 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4026 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4027 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4028 | writel(*(uint32_t *) mb, to_slim); |
| 4029 | readl(to_slim); /* flush */ |
| 4030 | |
| 4031 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4032 | phba->pport->stopped = 0; |
| 4033 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4034 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4035 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4036 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4037 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4038 | psli->stats_start = get_seconds(); |
| 4039 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4040 | /* Give the INITFF and Post time to settle. */ |
| 4041 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4043 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4044 | if (hba_aer_enabled) |
| 4045 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4046 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4047 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 | |
| 4049 | return 0; |
| 4050 | } |
| 4051 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4052 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4053 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4054 | * @phba: Pointer to HBA context object. |
| 4055 | * |
| 4056 | * This function is called in the SLI initialization code path to restart |
| 4057 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4058 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4059 | * free any pending commands. |
| 4060 | **/ |
| 4061 | static int |
| 4062 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4063 | { |
| 4064 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4065 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4066 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4067 | |
| 4068 | /* Restart HBA */ |
| 4069 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4070 | "0296 Restart HBA Data: x%x x%x\n", |
| 4071 | phba->pport->port_state, psli->sli_flag); |
| 4072 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4073 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4074 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4075 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4076 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4077 | |
| 4078 | spin_lock_irq(&phba->hbalock); |
| 4079 | phba->pport->stopped = 0; |
| 4080 | phba->link_state = LPFC_INIT_START; |
| 4081 | phba->hba_flag = 0; |
| 4082 | spin_unlock_irq(&phba->hbalock); |
| 4083 | |
| 4084 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4085 | psli->stats_start = get_seconds(); |
| 4086 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4087 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4088 | if (hba_aer_enabled) |
| 4089 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4090 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4091 | lpfc_hba_down_post(phba); |
| 4092 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4093 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | /** |
| 4097 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4098 | * @phba: Pointer to HBA context object. |
| 4099 | * |
| 4100 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4101 | * API jump table function pointer from the lpfc_hba struct. |
| 4102 | **/ |
| 4103 | int |
| 4104 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4105 | { |
| 4106 | return phba->lpfc_sli_brdrestart(phba); |
| 4107 | } |
| 4108 | |
| 4109 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4110 | * 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] | 4111 | * @phba: Pointer to HBA context object. |
| 4112 | * |
| 4113 | * This function is called after a HBA restart to wait for successful |
| 4114 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4115 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4116 | * iteration, the function will restart the HBA again. The function returns |
| 4117 | * zero if HBA successfully restarted else returns negative error code. |
| 4118 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | static int |
| 4120 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4121 | { |
| 4122 | uint32_t status, i = 0; |
| 4123 | |
| 4124 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4125 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4126 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | |
| 4128 | /* Check status register to see what current state is */ |
| 4129 | i = 0; |
| 4130 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4131 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4132 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4133 | * retries, then every 1 sec for 50 retires for a total of |
| 4134 | * ~60 seconds before reset the board again and check every |
| 4135 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4136 | * board ready is required by the Falcon FIPS zeroization |
| 4137 | * complete, and any reset the board in between shall cause |
| 4138 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4140 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | /* Adapter failed to init, timeout, status reg |
| 4142 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4143 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4144 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4145 | "timeout, status reg x%x, " |
| 4146 | "FW Data: A8 x%x AC x%x\n", status, |
| 4147 | readl(phba->MBslimaddr + 0xa8), |
| 4148 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4149 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4150 | return -ETIMEDOUT; |
| 4151 | } |
| 4152 | |
| 4153 | /* Check to see if any errors occurred during init */ |
| 4154 | if (status & HS_FFERM) { |
| 4155 | /* ERROR: During chipset initialization */ |
| 4156 | /* Adapter failed to init, chipset, status reg |
| 4157 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4158 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4159 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4160 | "chipset, status reg x%x, " |
| 4161 | "FW Data: A8 x%x AC x%x\n", status, |
| 4162 | readl(phba->MBslimaddr + 0xa8), |
| 4163 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4164 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4165 | return -EIO; |
| 4166 | } |
| 4167 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4168 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4169 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4170 | else if (i <= 100) |
| 4171 | msleep(100); |
| 4172 | else |
| 4173 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4174 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4175 | if (i == 150) { |
| 4176 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4177 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4178 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | } |
| 4180 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4181 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4182 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | /* Check to see if any errors occurred during init */ |
| 4186 | if (status & HS_FFERM) { |
| 4187 | /* ERROR: During chipset initialization */ |
| 4188 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4189 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4190 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4191 | "status reg x%x, " |
| 4192 | "FW Data: A8 x%x AC x%x\n", status, |
| 4193 | readl(phba->MBslimaddr + 0xa8), |
| 4194 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4195 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4196 | return -EIO; |
| 4197 | } |
| 4198 | |
| 4199 | /* Clear all interrupt enable conditions */ |
| 4200 | writel(0, phba->HCregaddr); |
| 4201 | readl(phba->HCregaddr); /* flush */ |
| 4202 | |
| 4203 | /* setup host attn register */ |
| 4204 | writel(0xffffffff, phba->HAregaddr); |
| 4205 | readl(phba->HAregaddr); /* flush */ |
| 4206 | return 0; |
| 4207 | } |
| 4208 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4209 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4210 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4211 | * |
| 4212 | * This function calculates and returns the number of HBQs required to be |
| 4213 | * configured. |
| 4214 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4215 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4216 | lpfc_sli_hbq_count(void) |
| 4217 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4218 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4219 | } |
| 4220 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4221 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4222 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4223 | * |
| 4224 | * This function adds the number of hbq entries in every HBQ to get |
| 4225 | * the total number of hbq entries required for the HBA and returns |
| 4226 | * the total count. |
| 4227 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4228 | static int |
| 4229 | lpfc_sli_hbq_entry_count(void) |
| 4230 | { |
| 4231 | int hbq_count = lpfc_sli_hbq_count(); |
| 4232 | int count = 0; |
| 4233 | int i; |
| 4234 | |
| 4235 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4236 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4237 | return count; |
| 4238 | } |
| 4239 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4240 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4241 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4242 | * |
| 4243 | * This function calculates amount of memory required for all hbq entries |
| 4244 | * to be configured and returns the total memory required. |
| 4245 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4246 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4247 | lpfc_sli_hbq_size(void) |
| 4248 | { |
| 4249 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4250 | } |
| 4251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4253 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4254 | * @phba: Pointer to HBA context object. |
| 4255 | * |
| 4256 | * This function is called during the SLI initialization to configure |
| 4257 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4258 | * required to hold any locks. This function will return zero if successful |
| 4259 | * else it will return negative error code. |
| 4260 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4261 | static int |
| 4262 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4263 | { |
| 4264 | int hbq_count = lpfc_sli_hbq_count(); |
| 4265 | LPFC_MBOXQ_t *pmb; |
| 4266 | MAILBOX_t *pmbox; |
| 4267 | uint32_t hbqno; |
| 4268 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4269 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4270 | /* Get a Mailbox buffer to setup mailbox |
| 4271 | * commands for HBA initialization |
| 4272 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4273 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4274 | |
| 4275 | if (!pmb) |
| 4276 | return -ENOMEM; |
| 4277 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4278 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4279 | |
| 4280 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4281 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4282 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4283 | |
| 4284 | hbq_entry_index = 0; |
| 4285 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4286 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4287 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4288 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4289 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4290 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4291 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4292 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4293 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4294 | |
| 4295 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4296 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4297 | mbxStatus <status>, ring <num> */ |
| 4298 | |
| 4299 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4300 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4301 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4302 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4303 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4304 | pmbox->mbxStatus, hbqno); |
| 4305 | |
| 4306 | phba->link_state = LPFC_HBA_ERROR; |
| 4307 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4308 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4309 | } |
| 4310 | } |
| 4311 | phba->hbq_count = hbq_count; |
| 4312 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4313 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4314 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4315 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4316 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4317 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4318 | return 0; |
| 4319 | } |
| 4320 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4321 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4322 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4323 | * @phba: Pointer to HBA context object. |
| 4324 | * |
| 4325 | * This function is called during the SLI initialization to configure |
| 4326 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4327 | * required to hold any locks. This function will return zero if successful |
| 4328 | * else it will return negative error code. |
| 4329 | **/ |
| 4330 | static int |
| 4331 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4332 | { |
| 4333 | phba->hbq_in_use = 1; |
| 4334 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4335 | phba->hbq_count = 1; |
| 4336 | /* Initially populate or replenish the HBQs */ |
| 4337 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4338 | return 0; |
| 4339 | } |
| 4340 | |
| 4341 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4342 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4343 | * @phba: Pointer to HBA context object. |
| 4344 | * @sli_mode: sli mode - 2/3 |
| 4345 | * |
| 4346 | * This function is called by the sli intialization code path |
| 4347 | * to issue config_port mailbox command. This function restarts the |
| 4348 | * HBA firmware and issues a config_port mailbox command to configure |
| 4349 | * the SLI interface in the sli mode specified by sli_mode |
| 4350 | * variable. The caller is not required to hold any locks. |
| 4351 | * The function returns 0 if successful, else returns negative error |
| 4352 | * code. |
| 4353 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4354 | int |
| 4355 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4356 | { |
| 4357 | LPFC_MBOXQ_t *pmb; |
| 4358 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4359 | |
| 4360 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4361 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4362 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | return -ENOMEM; |
| 4364 | } |
| 4365 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4366 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4367 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4368 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4369 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4371 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4372 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | rc = lpfc_sli_chipset_init(phba); |
| 4374 | if (rc) |
| 4375 | break; |
| 4376 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4377 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4378 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4379 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | resetcount++; |
| 4381 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4382 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4383 | * value of 0 means the call was successful. Any other |
| 4384 | * nonzero value is a failure, but if ERESTART is returned, |
| 4385 | * the driver may reset the HBA and try again. |
| 4386 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4387 | rc = lpfc_config_port_prep(phba); |
| 4388 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4389 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4390 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4391 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4393 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4394 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4395 | lpfc_config_port(phba, pmb); |
| 4396 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4397 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4398 | LPFC_SLI3_HBQ_ENABLED | |
| 4399 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4400 | LPFC_SLI3_BG_ENABLED | |
| 4401 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4402 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4404 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4405 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4406 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4407 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4408 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4409 | spin_unlock_irq(&phba->hbalock); |
| 4410 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4411 | } else { |
| 4412 | /* Allow asynchronous mailbox command to go through */ |
| 4413 | spin_lock_irq(&phba->hbalock); |
| 4414 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4415 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4416 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4417 | |
| 4418 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4419 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4420 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4421 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4422 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4423 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4424 | if (!done) { |
| 4425 | rc = -EINVAL; |
| 4426 | goto do_prep_failed; |
| 4427 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4428 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4429 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4430 | rc = -ENXIO; |
| 4431 | goto do_prep_failed; |
| 4432 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4433 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4434 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4435 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4436 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4437 | phba->max_vpi : phba->max_vports; |
| 4438 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4439 | } else |
| 4440 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4441 | phba->fips_level = 0; |
| 4442 | phba->fips_spec_rev = 0; |
| 4443 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4444 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4445 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4446 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4447 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4448 | "2850 Security Crypto Active. FIPS x%d " |
| 4449 | "(Spec Rev: x%d)", |
| 4450 | phba->fips_level, phba->fips_spec_rev); |
| 4451 | } |
| 4452 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4453 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4454 | "2856 Config Port Security Crypto " |
| 4455 | "Error: x%x ", |
| 4456 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4457 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4458 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4459 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4460 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4461 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4462 | |
| 4463 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4464 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4465 | |
| 4466 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4467 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4468 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4469 | else |
| 4470 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4471 | "0443 Adapter did not grant " |
| 4472 | "BlockGuard\n"); |
| 4473 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4474 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4475 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4476 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4477 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4478 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4479 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4480 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4481 | return rc; |
| 4482 | } |
| 4483 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4484 | |
| 4485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4486 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4487 | * @phba: Pointer to HBA context object. |
| 4488 | * |
| 4489 | * This function is the main SLI intialization function. This function |
| 4490 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4491 | * error attention handler code. Caller is not required to hold any |
| 4492 | * locks. This function issues config_port mailbox command to configure |
| 4493 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4494 | * calls the config_port_post function to issue init_link mailbox |
| 4495 | * command and to start the discovery. The function will return zero |
| 4496 | * if successful, else it will return negative error code. |
| 4497 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4498 | int |
| 4499 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4500 | { |
| 4501 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4502 | int mode = 3, i; |
| 4503 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4504 | |
| 4505 | switch (lpfc_sli_mode) { |
| 4506 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4507 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4508 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4509 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4510 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4511 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4512 | break; |
| 4513 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4514 | mode = 2; |
| 4515 | break; |
| 4516 | case 0: |
| 4517 | case 3: |
| 4518 | break; |
| 4519 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4520 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4521 | "1819 Unrecognized lpfc_sli_mode " |
| 4522 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4523 | |
| 4524 | break; |
| 4525 | } |
| 4526 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4527 | rc = lpfc_sli_config_port(phba, mode); |
| 4528 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4529 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4530 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4531 | "1820 Unable to select SLI-3. " |
| 4532 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4533 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4534 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4535 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4536 | goto lpfc_sli_hba_setup_error; |
| 4537 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4538 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4539 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4540 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4541 | if (!rc) { |
| 4542 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4543 | "2709 This device supports " |
| 4544 | "Advanced Error Reporting (AER)\n"); |
| 4545 | spin_lock_irq(&phba->hbalock); |
| 4546 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4547 | spin_unlock_irq(&phba->hbalock); |
| 4548 | } else { |
| 4549 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4550 | "2708 This device does not support " |
| 4551 | "Advanced Error Reporting (AER)\n"); |
| 4552 | phba->cfg_aer_support = 0; |
| 4553 | } |
| 4554 | } |
| 4555 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4556 | if (phba->sli_rev == 3) { |
| 4557 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4558 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4559 | } else { |
| 4560 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4561 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4562 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4563 | } |
| 4564 | |
| 4565 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4566 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4567 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4568 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | |
| 4570 | if (rc) |
| 4571 | goto lpfc_sli_hba_setup_error; |
| 4572 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4573 | /* Initialize VPIs. */ |
| 4574 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4575 | /* |
| 4576 | * The VPI bitmask and physical ID array are allocated |
| 4577 | * and initialized once only - at driver load. A port |
| 4578 | * reset doesn't need to reinitialize this memory. |
| 4579 | */ |
| 4580 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4581 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4582 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4583 | GFP_KERNEL); |
| 4584 | if (!phba->vpi_bmask) { |
| 4585 | rc = -ENOMEM; |
| 4586 | goto lpfc_sli_hba_setup_error; |
| 4587 | } |
| 4588 | |
| 4589 | phba->vpi_ids = kzalloc( |
| 4590 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4591 | GFP_KERNEL); |
| 4592 | if (!phba->vpi_ids) { |
| 4593 | kfree(phba->vpi_bmask); |
| 4594 | rc = -ENOMEM; |
| 4595 | goto lpfc_sli_hba_setup_error; |
| 4596 | } |
| 4597 | for (i = 0; i < phba->max_vpi; i++) |
| 4598 | phba->vpi_ids[i] = i; |
| 4599 | } |
| 4600 | } |
| 4601 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4602 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4603 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4604 | rc = lpfc_sli_hbq_setup(phba); |
| 4605 | if (rc) |
| 4606 | goto lpfc_sli_hba_setup_error; |
| 4607 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4608 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4609 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4610 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | |
| 4612 | rc = lpfc_config_port_post(phba); |
| 4613 | if (rc) |
| 4614 | goto lpfc_sli_hba_setup_error; |
| 4615 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4616 | return rc; |
| 4617 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4618 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4620 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4621 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | return rc; |
| 4623 | } |
| 4624 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4625 | /** |
| 4626 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4627 | * @phba: Pointer to HBA context object. |
| 4628 | * @mboxq: mailbox pointer. |
| 4629 | * This function issue a dump mailbox command to read config region |
| 4630 | * 23 and parse the records in the region and populate driver |
| 4631 | * data structure. |
| 4632 | **/ |
| 4633 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4634 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4635 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4636 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4637 | struct lpfc_dmabuf *mp; |
| 4638 | struct lpfc_mqe *mqe; |
| 4639 | uint32_t data_length; |
| 4640 | int rc; |
| 4641 | |
| 4642 | /* Program the default value of vlan_id and fc_map */ |
| 4643 | phba->valid_vlan = 0; |
| 4644 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4645 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4646 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4647 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4648 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4649 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4650 | return -ENOMEM; |
| 4651 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4652 | mqe = &mboxq->u.mqe; |
| 4653 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4654 | rc = -ENOMEM; |
| 4655 | goto out_free_mboxq; |
| 4656 | } |
| 4657 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4658 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4659 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4660 | |
| 4661 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4662 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4663 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4664 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4665 | "CQ: x%x x%x x%x x%x\n", |
| 4666 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4667 | bf_get(lpfc_mqe_command, mqe), |
| 4668 | bf_get(lpfc_mqe_status, mqe), |
| 4669 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4670 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4671 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4672 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4673 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4674 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4675 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4676 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4677 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4678 | mboxq->mcqe.word0, |
| 4679 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4680 | mboxq->mcqe.trailer); |
| 4681 | |
| 4682 | if (rc) { |
| 4683 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4684 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4685 | rc = -EIO; |
| 4686 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4687 | } |
| 4688 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4689 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4690 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4691 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4692 | rc = -EIO; |
| 4693 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4694 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4695 | |
| 4696 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4697 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4698 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4699 | rc = 0; |
| 4700 | |
| 4701 | out_free_mboxq: |
| 4702 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4703 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4704 | } |
| 4705 | |
| 4706 | /** |
| 4707 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4708 | * @phba: pointer to lpfc hba data structure. |
| 4709 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4710 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4711 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4712 | * On output, the number of data bytes in @vpd. |
| 4713 | * |
| 4714 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4715 | * addition, this routine gets the port vpd data. |
| 4716 | * |
| 4717 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4718 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4719 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4720 | **/ |
| 4721 | static int |
| 4722 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4723 | uint8_t *vpd, uint32_t *vpd_size) |
| 4724 | { |
| 4725 | int rc = 0; |
| 4726 | uint32_t dma_size; |
| 4727 | struct lpfc_dmabuf *dmabuf; |
| 4728 | struct lpfc_mqe *mqe; |
| 4729 | |
| 4730 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4731 | if (!dmabuf) |
| 4732 | return -ENOMEM; |
| 4733 | |
| 4734 | /* |
| 4735 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4736 | * mailbox command. |
| 4737 | */ |
| 4738 | dma_size = *vpd_size; |
| 4739 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 4740 | dma_size, |
| 4741 | &dmabuf->phys, |
| 4742 | GFP_KERNEL); |
| 4743 | if (!dmabuf->virt) { |
| 4744 | kfree(dmabuf); |
| 4745 | return -ENOMEM; |
| 4746 | } |
| 4747 | memset(dmabuf->virt, 0, dma_size); |
| 4748 | |
| 4749 | /* |
| 4750 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4751 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4752 | * in SLI3. This code corrects the conflicts. |
| 4753 | */ |
| 4754 | lpfc_read_rev(phba, mboxq); |
| 4755 | mqe = &mboxq->u.mqe; |
| 4756 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4757 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4758 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4759 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4760 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4761 | |
| 4762 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4763 | if (rc) { |
| 4764 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4765 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4766 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4767 | return -EIO; |
| 4768 | } |
| 4769 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4770 | /* |
| 4771 | * The available vpd length cannot be bigger than the |
| 4772 | * DMA buffer passed to the port. Catch the less than |
| 4773 | * case and update the caller's size. |
| 4774 | */ |
| 4775 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4776 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4777 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4778 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4779 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4780 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4781 | dmabuf->virt, dmabuf->phys); |
| 4782 | kfree(dmabuf); |
| 4783 | return 0; |
| 4784 | } |
| 4785 | |
| 4786 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4787 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4788 | * @phba: pointer to lpfc hba data structure. |
| 4789 | * |
| 4790 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4791 | * is attached to. |
| 4792 | * |
| 4793 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 4794 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4795 | * otherwise - failed to retrieve physical port name |
| 4796 | **/ |
| 4797 | static int |
| 4798 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4799 | { |
| 4800 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4801 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4802 | struct lpfc_controller_attribute *cntl_attr; |
| 4803 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4804 | void *virtaddr = NULL; |
| 4805 | uint32_t alloclen, reqlen; |
| 4806 | uint32_t shdr_status, shdr_add_status; |
| 4807 | union lpfc_sli4_cfg_shdr *shdr; |
| 4808 | char cport_name = 0; |
| 4809 | int rc; |
| 4810 | |
| 4811 | /* We assume nothing at this point */ |
| 4812 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4813 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4814 | |
| 4815 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4816 | if (!mboxq) |
| 4817 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4818 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4819 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4820 | lpfc_sli4_read_config(phba); |
| 4821 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4822 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4823 | |
| 4824 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4825 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4826 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4827 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4828 | LPFC_SLI4_MBX_NEMBED); |
| 4829 | if (alloclen < reqlen) { |
| 4830 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4831 | "3084 Allocated DMA memory size (%d) is " |
| 4832 | "less than the requested DMA memory size " |
| 4833 | "(%d)\n", alloclen, reqlen); |
| 4834 | rc = -ENOMEM; |
| 4835 | goto out_free_mboxq; |
| 4836 | } |
| 4837 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4838 | virtaddr = mboxq->sge_array->addr[0]; |
| 4839 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 4840 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 4841 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4842 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4843 | if (shdr_status || shdr_add_status || rc) { |
| 4844 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4845 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 4846 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4847 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4848 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4849 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4850 | rc, shdr_status, shdr_add_status); |
| 4851 | rc = -ENXIO; |
| 4852 | goto out_free_mboxq; |
| 4853 | } |
| 4854 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 4855 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 4856 | phba->sli4_hba.lnk_info.lnk_tp = |
| 4857 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 4858 | phba->sli4_hba.lnk_info.lnk_no = |
| 4859 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 4860 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4861 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 4862 | phba->sli4_hba.lnk_info.lnk_tp, |
| 4863 | phba->sli4_hba.lnk_info.lnk_no); |
| 4864 | |
| 4865 | retrieve_ppname: |
| 4866 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4867 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 4868 | sizeof(struct lpfc_mbx_get_port_name) - |
| 4869 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 4870 | LPFC_SLI4_MBX_EMBED); |
| 4871 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 4872 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 4873 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 4874 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 4875 | phba->sli4_hba.lnk_info.lnk_tp); |
| 4876 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4877 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4878 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4879 | if (shdr_status || shdr_add_status || rc) { |
| 4880 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4881 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 4882 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4883 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4884 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4885 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4886 | rc, shdr_status, shdr_add_status); |
| 4887 | rc = -ENXIO; |
| 4888 | goto out_free_mboxq; |
| 4889 | } |
| 4890 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4891 | case LPFC_LINK_NUMBER_0: |
| 4892 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 4893 | &get_port_name->u.response); |
| 4894 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4895 | break; |
| 4896 | case LPFC_LINK_NUMBER_1: |
| 4897 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 4898 | &get_port_name->u.response); |
| 4899 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4900 | break; |
| 4901 | case LPFC_LINK_NUMBER_2: |
| 4902 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 4903 | &get_port_name->u.response); |
| 4904 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4905 | break; |
| 4906 | case LPFC_LINK_NUMBER_3: |
| 4907 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 4908 | &get_port_name->u.response); |
| 4909 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4910 | break; |
| 4911 | default: |
| 4912 | break; |
| 4913 | } |
| 4914 | |
| 4915 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 4916 | phba->Port[0] = cport_name; |
| 4917 | phba->Port[1] = '\0'; |
| 4918 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4919 | "3091 SLI get port name: %s\n", phba->Port); |
| 4920 | } |
| 4921 | |
| 4922 | out_free_mboxq: |
| 4923 | if (rc != MBX_TIMEOUT) { |
| 4924 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 4925 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 4926 | else |
| 4927 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4928 | } |
| 4929 | return rc; |
| 4930 | } |
| 4931 | |
| 4932 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4933 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 4934 | * @phba: pointer to lpfc hba data structure. |
| 4935 | * |
| 4936 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 4937 | * event queues |
| 4938 | **/ |
| 4939 | static void |
| 4940 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 4941 | { |
| 4942 | uint8_t fcp_eqidx; |
| 4943 | |
| 4944 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 4945 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4946 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4947 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4948 | do { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4949 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 4950 | LPFC_QUEUE_REARM); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4951 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4952 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4953 | if (phba->sli4_hba.hba_eq) { |
| 4954 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4955 | fcp_eqidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4956 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4957 | LPFC_QUEUE_REARM); |
| 4958 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4962 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 4963 | * @phba: Pointer to HBA context object. |
| 4964 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4965 | * @extnt_count: buffer to hold port available extent count. |
| 4966 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4967 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4968 | * This function calls the port and retrievs the number of available |
| 4969 | * extents and their size for a particular extent type. |
| 4970 | * |
| 4971 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4972 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4973 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4974 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 4975 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 4976 | { |
| 4977 | int rc = 0; |
| 4978 | uint32_t length; |
| 4979 | uint32_t mbox_tmo; |
| 4980 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 4981 | LPFC_MBOXQ_t *mbox; |
| 4982 | |
| 4983 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4984 | if (!mbox) |
| 4985 | return -ENOMEM; |
| 4986 | |
| 4987 | /* Find out how many extents are available for this resource type */ |
| 4988 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 4989 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 4990 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4991 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 4992 | length, LPFC_SLI4_MBX_EMBED); |
| 4993 | |
| 4994 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 4995 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 4996 | LPFC_SLI4_MBX_EMBED); |
| 4997 | if (unlikely(rc)) { |
| 4998 | rc = -EIO; |
| 4999 | goto err_exit; |
| 5000 | } |
| 5001 | |
| 5002 | if (!phba->sli4_hba.intr_enable) |
| 5003 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5004 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5005 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5006 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5007 | } |
| 5008 | if (unlikely(rc)) { |
| 5009 | rc = -EIO; |
| 5010 | goto err_exit; |
| 5011 | } |
| 5012 | |
| 5013 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5014 | if (bf_get(lpfc_mbox_hdr_status, |
| 5015 | &rsrc_info->header.cfg_shdr.response)) { |
| 5016 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5017 | "2930 Failed to get resource extents " |
| 5018 | "Status 0x%x Add'l Status 0x%x\n", |
| 5019 | bf_get(lpfc_mbox_hdr_status, |
| 5020 | &rsrc_info->header.cfg_shdr.response), |
| 5021 | bf_get(lpfc_mbox_hdr_add_status, |
| 5022 | &rsrc_info->header.cfg_shdr.response)); |
| 5023 | rc = -EIO; |
| 5024 | goto err_exit; |
| 5025 | } |
| 5026 | |
| 5027 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5028 | &rsrc_info->u.rsp); |
| 5029 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5030 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5031 | |
| 5032 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5033 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5034 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5035 | |
| 5036 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5037 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5038 | return rc; |
| 5039 | } |
| 5040 | |
| 5041 | /** |
| 5042 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5043 | * @phba: Pointer to HBA context object. |
| 5044 | * @type: The extent type to check. |
| 5045 | * |
| 5046 | * This function reads the current available extents from the port and checks |
| 5047 | * if the extent count or extent size has changed since the last access. |
| 5048 | * Callers use this routine post port reset to understand if there is a |
| 5049 | * extent reprovisioning requirement. |
| 5050 | * |
| 5051 | * Returns: |
| 5052 | * -Error: error indicates problem. |
| 5053 | * 1: Extent count or size has changed. |
| 5054 | * 0: No changes. |
| 5055 | **/ |
| 5056 | static int |
| 5057 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5058 | { |
| 5059 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5060 | uint16_t size_diff, rsrc_ext_size; |
| 5061 | int rc = 0; |
| 5062 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5063 | struct list_head *rsrc_blk_list = NULL; |
| 5064 | |
| 5065 | size_diff = 0; |
| 5066 | curr_ext_cnt = 0; |
| 5067 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5068 | &rsrc_ext_cnt, |
| 5069 | &rsrc_ext_size); |
| 5070 | if (unlikely(rc)) |
| 5071 | return -EIO; |
| 5072 | |
| 5073 | switch (type) { |
| 5074 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5075 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5076 | break; |
| 5077 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5078 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5079 | break; |
| 5080 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5081 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5082 | break; |
| 5083 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5084 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5085 | break; |
| 5086 | default: |
| 5087 | break; |
| 5088 | } |
| 5089 | |
| 5090 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5091 | curr_ext_cnt++; |
| 5092 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5093 | size_diff++; |
| 5094 | } |
| 5095 | |
| 5096 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5097 | rc = 1; |
| 5098 | |
| 5099 | return rc; |
| 5100 | } |
| 5101 | |
| 5102 | /** |
| 5103 | * lpfc_sli4_cfg_post_extnts - |
| 5104 | * @phba: Pointer to HBA context object. |
| 5105 | * @extnt_cnt - number of available extents. |
| 5106 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5107 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5108 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5109 | * |
| 5110 | * This function executes the extents allocation request. It also |
| 5111 | * takes care of the amount of memory needed to allocate or get the |
| 5112 | * allocated extents. It is the caller's responsibility to evaluate |
| 5113 | * the response. |
| 5114 | * |
| 5115 | * Returns: |
| 5116 | * -Error: Error value describes the condition found. |
| 5117 | * 0: if successful |
| 5118 | **/ |
| 5119 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5120 | 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] | 5121 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5122 | { |
| 5123 | int rc = 0; |
| 5124 | uint32_t req_len; |
| 5125 | uint32_t emb_len; |
| 5126 | uint32_t alloc_len, mbox_tmo; |
| 5127 | |
| 5128 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5129 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5130 | |
| 5131 | /* |
| 5132 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5133 | * accounts for extents-specific word. |
| 5134 | */ |
| 5135 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5136 | sizeof(uint32_t); |
| 5137 | |
| 5138 | /* |
| 5139 | * Presume the allocation and response will fit into an embedded |
| 5140 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5141 | */ |
| 5142 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5143 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5144 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5145 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5146 | sizeof(uint32_t); |
| 5147 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5148 | } |
| 5149 | |
| 5150 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5151 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5152 | req_len, *emb); |
| 5153 | if (alloc_len < req_len) { |
| 5154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5155 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5156 | "less than the requested DMA memory " |
| 5157 | "size (x%x)\n", alloc_len, req_len); |
| 5158 | return -ENOMEM; |
| 5159 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5160 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5161 | if (unlikely(rc)) |
| 5162 | return -EIO; |
| 5163 | |
| 5164 | if (!phba->sli4_hba.intr_enable) |
| 5165 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5166 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5167 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5168 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5169 | } |
| 5170 | |
| 5171 | if (unlikely(rc)) |
| 5172 | rc = -EIO; |
| 5173 | return rc; |
| 5174 | } |
| 5175 | |
| 5176 | /** |
| 5177 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5178 | * @phba: Pointer to HBA context object. |
| 5179 | * @type: The resource extent type to allocate. |
| 5180 | * |
| 5181 | * This function allocates the number of elements for the specified |
| 5182 | * resource type. |
| 5183 | **/ |
| 5184 | static int |
| 5185 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5186 | { |
| 5187 | bool emb = false; |
| 5188 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5189 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5190 | uint16_t *ids; |
| 5191 | int i, rc; |
| 5192 | unsigned long longs; |
| 5193 | unsigned long *bmask; |
| 5194 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5195 | LPFC_MBOXQ_t *mbox; |
| 5196 | uint32_t length; |
| 5197 | struct lpfc_id_range *id_array = NULL; |
| 5198 | void *virtaddr = NULL; |
| 5199 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5200 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5201 | struct list_head *ext_blk_list; |
| 5202 | |
| 5203 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5204 | &rsrc_cnt, |
| 5205 | &rsrc_size); |
| 5206 | if (unlikely(rc)) |
| 5207 | return -EIO; |
| 5208 | |
| 5209 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5210 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5211 | "3009 No available Resource Extents " |
| 5212 | "for resource type 0x%x: Count: 0x%x, " |
| 5213 | "Size 0x%x\n", type, rsrc_cnt, |
| 5214 | rsrc_size); |
| 5215 | return -ENOMEM; |
| 5216 | } |
| 5217 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5218 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5219 | "2903 Post resource extents type-0x%x: " |
| 5220 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5221 | |
| 5222 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5223 | if (!mbox) |
| 5224 | return -ENOMEM; |
| 5225 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5226 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5227 | if (unlikely(rc)) { |
| 5228 | rc = -EIO; |
| 5229 | goto err_exit; |
| 5230 | } |
| 5231 | |
| 5232 | /* |
| 5233 | * Figure out where the response is located. Then get local pointers |
| 5234 | * to the response data. The port does not guarantee to respond to |
| 5235 | * all extents counts request so update the local variable with the |
| 5236 | * allocated count from the port. |
| 5237 | */ |
| 5238 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5239 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5240 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5241 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5242 | } else { |
| 5243 | virtaddr = mbox->sge_array->addr[0]; |
| 5244 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5245 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5246 | id_array = &n_rsrc->id; |
| 5247 | } |
| 5248 | |
| 5249 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5250 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5251 | |
| 5252 | /* |
| 5253 | * Based on the resource size and count, correct the base and max |
| 5254 | * resource values. |
| 5255 | */ |
| 5256 | length = sizeof(struct lpfc_rsrc_blks); |
| 5257 | switch (type) { |
| 5258 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5259 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5260 | sizeof(unsigned long), |
| 5261 | GFP_KERNEL); |
| 5262 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5263 | rc = -ENOMEM; |
| 5264 | goto err_exit; |
| 5265 | } |
| 5266 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5267 | sizeof(uint16_t), |
| 5268 | GFP_KERNEL); |
| 5269 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5270 | kfree(phba->sli4_hba.rpi_bmask); |
| 5271 | rc = -ENOMEM; |
| 5272 | goto err_exit; |
| 5273 | } |
| 5274 | |
| 5275 | /* |
| 5276 | * The next_rpi was initialized with the maximum available |
| 5277 | * count but the port may allocate a smaller number. Catch |
| 5278 | * that case and update the next_rpi. |
| 5279 | */ |
| 5280 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5281 | |
| 5282 | /* Initialize local ptrs for common extent processing later. */ |
| 5283 | bmask = phba->sli4_hba.rpi_bmask; |
| 5284 | ids = phba->sli4_hba.rpi_ids; |
| 5285 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5286 | break; |
| 5287 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5288 | phba->vpi_bmask = kzalloc(longs * |
| 5289 | sizeof(unsigned long), |
| 5290 | GFP_KERNEL); |
| 5291 | if (unlikely(!phba->vpi_bmask)) { |
| 5292 | rc = -ENOMEM; |
| 5293 | goto err_exit; |
| 5294 | } |
| 5295 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5296 | sizeof(uint16_t), |
| 5297 | GFP_KERNEL); |
| 5298 | if (unlikely(!phba->vpi_ids)) { |
| 5299 | kfree(phba->vpi_bmask); |
| 5300 | rc = -ENOMEM; |
| 5301 | goto err_exit; |
| 5302 | } |
| 5303 | |
| 5304 | /* Initialize local ptrs for common extent processing later. */ |
| 5305 | bmask = phba->vpi_bmask; |
| 5306 | ids = phba->vpi_ids; |
| 5307 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5308 | break; |
| 5309 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5310 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5311 | sizeof(unsigned long), |
| 5312 | GFP_KERNEL); |
| 5313 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5314 | rc = -ENOMEM; |
| 5315 | goto err_exit; |
| 5316 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5317 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5318 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5319 | sizeof(uint16_t), |
| 5320 | GFP_KERNEL); |
| 5321 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5322 | kfree(phba->sli4_hba.xri_bmask); |
| 5323 | rc = -ENOMEM; |
| 5324 | goto err_exit; |
| 5325 | } |
| 5326 | |
| 5327 | /* Initialize local ptrs for common extent processing later. */ |
| 5328 | bmask = phba->sli4_hba.xri_bmask; |
| 5329 | ids = phba->sli4_hba.xri_ids; |
| 5330 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5331 | break; |
| 5332 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5333 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5334 | sizeof(unsigned long), |
| 5335 | GFP_KERNEL); |
| 5336 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5337 | rc = -ENOMEM; |
| 5338 | goto err_exit; |
| 5339 | } |
| 5340 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5341 | sizeof(uint16_t), |
| 5342 | GFP_KERNEL); |
| 5343 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5344 | kfree(phba->sli4_hba.vfi_bmask); |
| 5345 | rc = -ENOMEM; |
| 5346 | goto err_exit; |
| 5347 | } |
| 5348 | |
| 5349 | /* Initialize local ptrs for common extent processing later. */ |
| 5350 | bmask = phba->sli4_hba.vfi_bmask; |
| 5351 | ids = phba->sli4_hba.vfi_ids; |
| 5352 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5353 | break; |
| 5354 | default: |
| 5355 | /* Unsupported Opcode. Fail call. */ |
| 5356 | id_array = NULL; |
| 5357 | bmask = NULL; |
| 5358 | ids = NULL; |
| 5359 | ext_blk_list = NULL; |
| 5360 | goto err_exit; |
| 5361 | } |
| 5362 | |
| 5363 | /* |
| 5364 | * Complete initializing the extent configuration with the |
| 5365 | * allocated ids assigned to this function. The bitmask serves |
| 5366 | * as an index into the array and manages the available ids. The |
| 5367 | * array just stores the ids communicated to the port via the wqes. |
| 5368 | */ |
| 5369 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5370 | if ((i % 2) == 0) |
| 5371 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5372 | &id_array[k]); |
| 5373 | else |
| 5374 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5375 | &id_array[k]); |
| 5376 | |
| 5377 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5378 | if (unlikely(!rsrc_blks)) { |
| 5379 | rc = -ENOMEM; |
| 5380 | kfree(bmask); |
| 5381 | kfree(ids); |
| 5382 | goto err_exit; |
| 5383 | } |
| 5384 | rsrc_blks->rsrc_start = rsrc_id; |
| 5385 | rsrc_blks->rsrc_size = rsrc_size; |
| 5386 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5387 | rsrc_start = rsrc_id; |
| 5388 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5389 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5390 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5391 | |
| 5392 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5393 | ids[j] = rsrc_id; |
| 5394 | rsrc_id++; |
| 5395 | j++; |
| 5396 | } |
| 5397 | /* Entire word processed. Get next word.*/ |
| 5398 | if ((i % 2) == 1) |
| 5399 | k++; |
| 5400 | } |
| 5401 | err_exit: |
| 5402 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5403 | return rc; |
| 5404 | } |
| 5405 | |
| 5406 | /** |
| 5407 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5408 | * @phba: Pointer to HBA context object. |
| 5409 | * @type: the extent's type. |
| 5410 | * |
| 5411 | * This function deallocates all extents of a particular resource type. |
| 5412 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5413 | * is the caller's responsibility to release all kernel memory resources. |
| 5414 | **/ |
| 5415 | static int |
| 5416 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5417 | { |
| 5418 | int rc; |
| 5419 | uint32_t length, mbox_tmo = 0; |
| 5420 | LPFC_MBOXQ_t *mbox; |
| 5421 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5422 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5423 | |
| 5424 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5425 | if (!mbox) |
| 5426 | return -ENOMEM; |
| 5427 | |
| 5428 | /* |
| 5429 | * This function sends an embedded mailbox because it only sends the |
| 5430 | * the resource type. All extents of this type are released by the |
| 5431 | * port. |
| 5432 | */ |
| 5433 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5434 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5435 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5436 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5437 | length, LPFC_SLI4_MBX_EMBED); |
| 5438 | |
| 5439 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5440 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5441 | LPFC_SLI4_MBX_EMBED); |
| 5442 | if (unlikely(rc)) { |
| 5443 | rc = -EIO; |
| 5444 | goto out_free_mbox; |
| 5445 | } |
| 5446 | if (!phba->sli4_hba.intr_enable) |
| 5447 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5448 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5449 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5450 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5451 | } |
| 5452 | if (unlikely(rc)) { |
| 5453 | rc = -EIO; |
| 5454 | goto out_free_mbox; |
| 5455 | } |
| 5456 | |
| 5457 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5458 | if (bf_get(lpfc_mbox_hdr_status, |
| 5459 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5460 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5461 | "2919 Failed to release resource extents " |
| 5462 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5463 | "Resource memory not released.\n", |
| 5464 | type, |
| 5465 | bf_get(lpfc_mbox_hdr_status, |
| 5466 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5467 | bf_get(lpfc_mbox_hdr_add_status, |
| 5468 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5469 | rc = -EIO; |
| 5470 | goto out_free_mbox; |
| 5471 | } |
| 5472 | |
| 5473 | /* Release kernel memory resources for the specific type. */ |
| 5474 | switch (type) { |
| 5475 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5476 | kfree(phba->vpi_bmask); |
| 5477 | kfree(phba->vpi_ids); |
| 5478 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5479 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5480 | &phba->lpfc_vpi_blk_list, list) { |
| 5481 | list_del_init(&rsrc_blk->list); |
| 5482 | kfree(rsrc_blk); |
| 5483 | } |
| 5484 | break; |
| 5485 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5486 | kfree(phba->sli4_hba.xri_bmask); |
| 5487 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5488 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5489 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5490 | list_del_init(&rsrc_blk->list); |
| 5491 | kfree(rsrc_blk); |
| 5492 | } |
| 5493 | break; |
| 5494 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5495 | kfree(phba->sli4_hba.vfi_bmask); |
| 5496 | kfree(phba->sli4_hba.vfi_ids); |
| 5497 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5498 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5499 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5500 | list_del_init(&rsrc_blk->list); |
| 5501 | kfree(rsrc_blk); |
| 5502 | } |
| 5503 | break; |
| 5504 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5505 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5506 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5507 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5508 | list_del_init(&rsrc_blk->list); |
| 5509 | kfree(rsrc_blk); |
| 5510 | } |
| 5511 | break; |
| 5512 | default: |
| 5513 | break; |
| 5514 | } |
| 5515 | |
| 5516 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5517 | |
| 5518 | out_free_mbox: |
| 5519 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5520 | return rc; |
| 5521 | } |
| 5522 | |
| 5523 | /** |
| 5524 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5525 | * @phba: Pointer to HBA context object. |
| 5526 | * |
| 5527 | * This function allocates all SLI4 resource identifiers. |
| 5528 | **/ |
| 5529 | int |
| 5530 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5531 | { |
| 5532 | int i, rc, error = 0; |
| 5533 | uint16_t count, base; |
| 5534 | unsigned long longs; |
| 5535 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5536 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5537 | 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] | 5538 | if (phba->sli4_hba.extents_in_use) { |
| 5539 | /* |
| 5540 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5541 | * resource extent count must be read and allocated before |
| 5542 | * provisioning the resource id arrays. |
| 5543 | */ |
| 5544 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5545 | LPFC_IDX_RSRC_RDY) { |
| 5546 | /* |
| 5547 | * Extent-based resources are set - the driver could |
| 5548 | * be in a port reset. Figure out if any corrective |
| 5549 | * actions need to be taken. |
| 5550 | */ |
| 5551 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5552 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5553 | if (rc != 0) |
| 5554 | error++; |
| 5555 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5556 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5557 | if (rc != 0) |
| 5558 | error++; |
| 5559 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5560 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5561 | if (rc != 0) |
| 5562 | error++; |
| 5563 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5564 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5565 | if (rc != 0) |
| 5566 | error++; |
| 5567 | |
| 5568 | /* |
| 5569 | * It's possible that the number of resources |
| 5570 | * provided to this port instance changed between |
| 5571 | * resets. Detect this condition and reallocate |
| 5572 | * resources. Otherwise, there is no action. |
| 5573 | */ |
| 5574 | if (error) { |
| 5575 | lpfc_printf_log(phba, KERN_INFO, |
| 5576 | LOG_MBOX | LOG_INIT, |
| 5577 | "2931 Detected extent resource " |
| 5578 | "change. Reallocating all " |
| 5579 | "extents.\n"); |
| 5580 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5581 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5582 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5583 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5584 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5585 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5586 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5587 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5588 | } else |
| 5589 | return 0; |
| 5590 | } |
| 5591 | |
| 5592 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5593 | if (unlikely(rc)) |
| 5594 | goto err_exit; |
| 5595 | |
| 5596 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5597 | if (unlikely(rc)) |
| 5598 | goto err_exit; |
| 5599 | |
| 5600 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5601 | if (unlikely(rc)) |
| 5602 | goto err_exit; |
| 5603 | |
| 5604 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5605 | if (unlikely(rc)) |
| 5606 | goto err_exit; |
| 5607 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5608 | LPFC_IDX_RSRC_RDY); |
| 5609 | return rc; |
| 5610 | } else { |
| 5611 | /* |
| 5612 | * The port does not support resource extents. The XRI, VPI, |
| 5613 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5614 | * Just allocate the bitmasks and provision the resource id |
| 5615 | * arrays. If a port reset is active, the resources don't |
| 5616 | * need any action - just exit. |
| 5617 | */ |
| 5618 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5619 | LPFC_IDX_RSRC_RDY) { |
| 5620 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5621 | lpfc_sli4_remove_rpis(phba); |
| 5622 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5623 | /* RPIs. */ |
| 5624 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
| 5625 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5626 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5627 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5628 | sizeof(unsigned long), |
| 5629 | GFP_KERNEL); |
| 5630 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5631 | rc = -ENOMEM; |
| 5632 | goto err_exit; |
| 5633 | } |
| 5634 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5635 | sizeof(uint16_t), |
| 5636 | GFP_KERNEL); |
| 5637 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5638 | rc = -ENOMEM; |
| 5639 | goto free_rpi_bmask; |
| 5640 | } |
| 5641 | |
| 5642 | for (i = 0; i < count; i++) |
| 5643 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5644 | |
| 5645 | /* VPIs. */ |
| 5646 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
| 5647 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5648 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5649 | phba->vpi_bmask = kzalloc(longs * |
| 5650 | sizeof(unsigned long), |
| 5651 | GFP_KERNEL); |
| 5652 | if (unlikely(!phba->vpi_bmask)) { |
| 5653 | rc = -ENOMEM; |
| 5654 | goto free_rpi_ids; |
| 5655 | } |
| 5656 | phba->vpi_ids = kzalloc(count * |
| 5657 | sizeof(uint16_t), |
| 5658 | GFP_KERNEL); |
| 5659 | if (unlikely(!phba->vpi_ids)) { |
| 5660 | rc = -ENOMEM; |
| 5661 | goto free_vpi_bmask; |
| 5662 | } |
| 5663 | |
| 5664 | for (i = 0; i < count; i++) |
| 5665 | phba->vpi_ids[i] = base + i; |
| 5666 | |
| 5667 | /* XRIs. */ |
| 5668 | count = phba->sli4_hba.max_cfg_param.max_xri; |
| 5669 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5670 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5671 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5672 | sizeof(unsigned long), |
| 5673 | GFP_KERNEL); |
| 5674 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5675 | rc = -ENOMEM; |
| 5676 | goto free_vpi_ids; |
| 5677 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5678 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5679 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5680 | sizeof(uint16_t), |
| 5681 | GFP_KERNEL); |
| 5682 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5683 | rc = -ENOMEM; |
| 5684 | goto free_xri_bmask; |
| 5685 | } |
| 5686 | |
| 5687 | for (i = 0; i < count; i++) |
| 5688 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5689 | |
| 5690 | /* VFIs. */ |
| 5691 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
| 5692 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5693 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5694 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5695 | sizeof(unsigned long), |
| 5696 | GFP_KERNEL); |
| 5697 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5698 | rc = -ENOMEM; |
| 5699 | goto free_xri_ids; |
| 5700 | } |
| 5701 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5702 | sizeof(uint16_t), |
| 5703 | GFP_KERNEL); |
| 5704 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5705 | rc = -ENOMEM; |
| 5706 | goto free_vfi_bmask; |
| 5707 | } |
| 5708 | |
| 5709 | for (i = 0; i < count; i++) |
| 5710 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5711 | |
| 5712 | /* |
| 5713 | * Mark all resources ready. An HBA reset doesn't need |
| 5714 | * to reset the initialization. |
| 5715 | */ |
| 5716 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5717 | LPFC_IDX_RSRC_RDY); |
| 5718 | return 0; |
| 5719 | } |
| 5720 | |
| 5721 | free_vfi_bmask: |
| 5722 | kfree(phba->sli4_hba.vfi_bmask); |
| 5723 | free_xri_ids: |
| 5724 | kfree(phba->sli4_hba.xri_ids); |
| 5725 | free_xri_bmask: |
| 5726 | kfree(phba->sli4_hba.xri_bmask); |
| 5727 | free_vpi_ids: |
| 5728 | kfree(phba->vpi_ids); |
| 5729 | free_vpi_bmask: |
| 5730 | kfree(phba->vpi_bmask); |
| 5731 | free_rpi_ids: |
| 5732 | kfree(phba->sli4_hba.rpi_ids); |
| 5733 | free_rpi_bmask: |
| 5734 | kfree(phba->sli4_hba.rpi_bmask); |
| 5735 | err_exit: |
| 5736 | return rc; |
| 5737 | } |
| 5738 | |
| 5739 | /** |
| 5740 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5741 | * @phba: Pointer to HBA context object. |
| 5742 | * |
| 5743 | * This function allocates the number of elements for the specified |
| 5744 | * resource type. |
| 5745 | **/ |
| 5746 | int |
| 5747 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5748 | { |
| 5749 | if (phba->sli4_hba.extents_in_use) { |
| 5750 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5751 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5752 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5753 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5754 | } else { |
| 5755 | kfree(phba->vpi_bmask); |
| 5756 | kfree(phba->vpi_ids); |
| 5757 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5758 | kfree(phba->sli4_hba.xri_bmask); |
| 5759 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5760 | kfree(phba->sli4_hba.vfi_bmask); |
| 5761 | kfree(phba->sli4_hba.vfi_ids); |
| 5762 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5763 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5764 | } |
| 5765 | |
| 5766 | return 0; |
| 5767 | } |
| 5768 | |
| 5769 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5770 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5771 | * @phba: Pointer to HBA context object. |
| 5772 | * @type: The resource extent type. |
| 5773 | * @extnt_count: buffer to hold port extent count response |
| 5774 | * @extnt_size: buffer to hold port extent size response. |
| 5775 | * |
| 5776 | * This function calls the port to read the host allocated extents |
| 5777 | * for a particular type. |
| 5778 | **/ |
| 5779 | int |
| 5780 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5781 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5782 | { |
| 5783 | bool emb; |
| 5784 | int rc = 0; |
| 5785 | uint16_t curr_blks = 0; |
| 5786 | uint32_t req_len, emb_len; |
| 5787 | uint32_t alloc_len, mbox_tmo; |
| 5788 | struct list_head *blk_list_head; |
| 5789 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5790 | LPFC_MBOXQ_t *mbox; |
| 5791 | void *virtaddr = NULL; |
| 5792 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5793 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5794 | union lpfc_sli4_cfg_shdr *shdr; |
| 5795 | |
| 5796 | switch (type) { |
| 5797 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5798 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 5799 | break; |
| 5800 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5801 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5802 | break; |
| 5803 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5804 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5805 | break; |
| 5806 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5807 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5808 | break; |
| 5809 | default: |
| 5810 | return -EIO; |
| 5811 | } |
| 5812 | |
| 5813 | /* Count the number of extents currently allocatd for this type. */ |
| 5814 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 5815 | if (curr_blks == 0) { |
| 5816 | /* |
| 5817 | * The GET_ALLOCATED mailbox does not return the size, |
| 5818 | * just the count. The size should be just the size |
| 5819 | * stored in the current allocated block and all sizes |
| 5820 | * for an extent type are the same so set the return |
| 5821 | * value now. |
| 5822 | */ |
| 5823 | *extnt_size = rsrc_blk->rsrc_size; |
| 5824 | } |
| 5825 | curr_blks++; |
| 5826 | } |
| 5827 | |
| 5828 | /* Calculate the total requested length of the dma memory. */ |
| 5829 | req_len = curr_blks * sizeof(uint16_t); |
| 5830 | |
| 5831 | /* |
| 5832 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5833 | * accounts for extents-specific word. |
| 5834 | */ |
| 5835 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5836 | sizeof(uint32_t); |
| 5837 | |
| 5838 | /* |
| 5839 | * Presume the allocation and response will fit into an embedded |
| 5840 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5841 | */ |
| 5842 | emb = LPFC_SLI4_MBX_EMBED; |
| 5843 | req_len = emb_len; |
| 5844 | if (req_len > emb_len) { |
| 5845 | req_len = curr_blks * sizeof(uint16_t) + |
| 5846 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5847 | sizeof(uint32_t); |
| 5848 | emb = LPFC_SLI4_MBX_NEMBED; |
| 5849 | } |
| 5850 | |
| 5851 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5852 | if (!mbox) |
| 5853 | return -ENOMEM; |
| 5854 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 5855 | |
| 5856 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5857 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 5858 | req_len, emb); |
| 5859 | if (alloc_len < req_len) { |
| 5860 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5861 | "2983 Allocated DMA memory size (x%x) is " |
| 5862 | "less than the requested DMA memory " |
| 5863 | "size (x%x)\n", alloc_len, req_len); |
| 5864 | rc = -ENOMEM; |
| 5865 | goto err_exit; |
| 5866 | } |
| 5867 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 5868 | if (unlikely(rc)) { |
| 5869 | rc = -EIO; |
| 5870 | goto err_exit; |
| 5871 | } |
| 5872 | |
| 5873 | if (!phba->sli4_hba.intr_enable) |
| 5874 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5875 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5876 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5877 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5878 | } |
| 5879 | |
| 5880 | if (unlikely(rc)) { |
| 5881 | rc = -EIO; |
| 5882 | goto err_exit; |
| 5883 | } |
| 5884 | |
| 5885 | /* |
| 5886 | * Figure out where the response is located. Then get local pointers |
| 5887 | * to the response data. The port does not guarantee to respond to |
| 5888 | * all extents counts request so update the local variable with the |
| 5889 | * allocated count from the port. |
| 5890 | */ |
| 5891 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5892 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5893 | shdr = &rsrc_ext->header.cfg_shdr; |
| 5894 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5895 | } else { |
| 5896 | virtaddr = mbox->sge_array->addr[0]; |
| 5897 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5898 | shdr = &n_rsrc->cfg_shdr; |
| 5899 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5900 | } |
| 5901 | |
| 5902 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 5903 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5904 | "2984 Failed to read allocated resources " |
| 5905 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 5906 | type, |
| 5907 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 5908 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 5909 | rc = -EIO; |
| 5910 | goto err_exit; |
| 5911 | } |
| 5912 | err_exit: |
| 5913 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5914 | return rc; |
| 5915 | } |
| 5916 | |
| 5917 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5918 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 5919 | * @phba: pointer to lpfc hba data structure. |
| 5920 | * |
| 5921 | * This routine walks the list of els buffers that have been allocated and |
| 5922 | * repost them to the port by using SGL block post. This is needed after a |
| 5923 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 5924 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 5925 | * SGL block post mailbox commands to post them to the port. For single els |
| 5926 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 5927 | * mailbox command for posting. |
| 5928 | * |
| 5929 | * Returns: 0 = success, non-zero failure. |
| 5930 | **/ |
| 5931 | static int |
| 5932 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 5933 | { |
| 5934 | struct lpfc_sglq *sglq_entry = NULL; |
| 5935 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 5936 | struct lpfc_sglq *sglq_entry_first = NULL; |
| 5937 | int status, post_cnt = 0, num_posted = 0, block_cnt = 0; |
| 5938 | int last_xritag = NO_XRI; |
| 5939 | LIST_HEAD(prep_sgl_list); |
| 5940 | LIST_HEAD(blck_sgl_list); |
| 5941 | LIST_HEAD(allc_sgl_list); |
| 5942 | LIST_HEAD(post_sgl_list); |
| 5943 | LIST_HEAD(free_sgl_list); |
| 5944 | |
| 5945 | spin_lock(&phba->hbalock); |
| 5946 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
| 5947 | spin_unlock(&phba->hbalock); |
| 5948 | |
| 5949 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 5950 | &allc_sgl_list, list) { |
| 5951 | list_del_init(&sglq_entry->list); |
| 5952 | block_cnt++; |
| 5953 | if ((last_xritag != NO_XRI) && |
| 5954 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 5955 | /* a hole in xri block, form a sgl posting block */ |
| 5956 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 5957 | post_cnt = block_cnt - 1; |
| 5958 | /* prepare list for next posting block */ |
| 5959 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 5960 | block_cnt = 1; |
| 5961 | } else { |
| 5962 | /* prepare list for next posting block */ |
| 5963 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 5964 | /* enough sgls for non-embed sgl mbox command */ |
| 5965 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 5966 | list_splice_init(&prep_sgl_list, |
| 5967 | &blck_sgl_list); |
| 5968 | post_cnt = block_cnt; |
| 5969 | block_cnt = 0; |
| 5970 | } |
| 5971 | } |
| 5972 | num_posted++; |
| 5973 | |
| 5974 | /* keep track of last sgl's xritag */ |
| 5975 | last_xritag = sglq_entry->sli4_xritag; |
| 5976 | |
| 5977 | /* end of repost sgl list condition for els buffers */ |
| 5978 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 5979 | if (post_cnt == 0) { |
| 5980 | list_splice_init(&prep_sgl_list, |
| 5981 | &blck_sgl_list); |
| 5982 | post_cnt = block_cnt; |
| 5983 | } else if (block_cnt == 1) { |
| 5984 | status = lpfc_sli4_post_sgl(phba, |
| 5985 | sglq_entry->phys, 0, |
| 5986 | sglq_entry->sli4_xritag); |
| 5987 | if (!status) { |
| 5988 | /* successful, put sgl to posted list */ |
| 5989 | list_add_tail(&sglq_entry->list, |
| 5990 | &post_sgl_list); |
| 5991 | } else { |
| 5992 | /* Failure, put sgl to free list */ |
| 5993 | lpfc_printf_log(phba, KERN_WARNING, |
| 5994 | LOG_SLI, |
| 5995 | "3159 Failed to post els " |
| 5996 | "sgl, xritag:x%x\n", |
| 5997 | sglq_entry->sli4_xritag); |
| 5998 | list_add_tail(&sglq_entry->list, |
| 5999 | &free_sgl_list); |
| 6000 | spin_lock_irq(&phba->hbalock); |
| 6001 | phba->sli4_hba.els_xri_cnt--; |
| 6002 | spin_unlock_irq(&phba->hbalock); |
| 6003 | } |
| 6004 | } |
| 6005 | } |
| 6006 | |
| 6007 | /* continue until a nembed page worth of sgls */ |
| 6008 | if (post_cnt == 0) |
| 6009 | continue; |
| 6010 | |
| 6011 | /* post the els buffer list sgls as a block */ |
| 6012 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 6013 | post_cnt); |
| 6014 | |
| 6015 | if (!status) { |
| 6016 | /* success, put sgl list to posted sgl list */ |
| 6017 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6018 | } else { |
| 6019 | /* Failure, put sgl list to free sgl list */ |
| 6020 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6021 | struct lpfc_sglq, |
| 6022 | list); |
| 6023 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6024 | "3160 Failed to post els sgl-list, " |
| 6025 | "xritag:x%x-x%x\n", |
| 6026 | sglq_entry_first->sli4_xritag, |
| 6027 | (sglq_entry_first->sli4_xritag + |
| 6028 | post_cnt - 1)); |
| 6029 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
| 6030 | spin_lock_irq(&phba->hbalock); |
| 6031 | phba->sli4_hba.els_xri_cnt -= post_cnt; |
| 6032 | spin_unlock_irq(&phba->hbalock); |
| 6033 | } |
| 6034 | |
| 6035 | /* don't reset xirtag due to hole in xri block */ |
| 6036 | if (block_cnt == 0) |
| 6037 | last_xritag = NO_XRI; |
| 6038 | |
| 6039 | /* reset els sgl post count for next round of posting */ |
| 6040 | post_cnt = 0; |
| 6041 | } |
| 6042 | |
| 6043 | /* free the els sgls failed to post */ |
| 6044 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6045 | |
| 6046 | /* push els sgls posted to the availble list */ |
| 6047 | if (!list_empty(&post_sgl_list)) { |
| 6048 | spin_lock(&phba->hbalock); |
| 6049 | list_splice_init(&post_sgl_list, |
| 6050 | &phba->sli4_hba.lpfc_sgl_list); |
| 6051 | spin_unlock(&phba->hbalock); |
| 6052 | } else { |
| 6053 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6054 | "3161 Failure to post els sgl to port.\n"); |
| 6055 | return -EIO; |
| 6056 | } |
| 6057 | return 0; |
| 6058 | } |
| 6059 | |
| 6060 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6061 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6062 | * @phba: Pointer to HBA context object. |
| 6063 | * |
| 6064 | * This function is the main SLI4 device intialization PCI function. This |
| 6065 | * function is called by the HBA intialization code, HBA reset code and |
| 6066 | * HBA error attention handler code. Caller is not required to hold any |
| 6067 | * locks. |
| 6068 | **/ |
| 6069 | int |
| 6070 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6071 | { |
| 6072 | int rc; |
| 6073 | LPFC_MBOXQ_t *mboxq; |
| 6074 | struct lpfc_mqe *mqe; |
| 6075 | uint8_t *vpd; |
| 6076 | uint32_t vpd_size; |
| 6077 | uint32_t ftr_rsp = 0; |
| 6078 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6079 | struct lpfc_vport *vport = phba->pport; |
| 6080 | struct lpfc_dmabuf *mp; |
| 6081 | |
| 6082 | /* Perform a PCI function reset to start from clean */ |
| 6083 | rc = lpfc_pci_function_reset(phba); |
| 6084 | if (unlikely(rc)) |
| 6085 | return -ENODEV; |
| 6086 | |
| 6087 | /* Check the HBA Host Status Register for readyness */ |
| 6088 | rc = lpfc_sli4_post_status_check(phba); |
| 6089 | if (unlikely(rc)) |
| 6090 | return -ENODEV; |
| 6091 | else { |
| 6092 | spin_lock_irq(&phba->hbalock); |
| 6093 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6094 | spin_unlock_irq(&phba->hbalock); |
| 6095 | } |
| 6096 | |
| 6097 | /* |
| 6098 | * Allocate a single mailbox container for initializing the |
| 6099 | * port. |
| 6100 | */ |
| 6101 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6102 | if (!mboxq) |
| 6103 | return -ENOMEM; |
| 6104 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6105 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6106 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6107 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6108 | if (!vpd) { |
| 6109 | rc = -ENOMEM; |
| 6110 | goto out_free_mbox; |
| 6111 | } |
| 6112 | |
| 6113 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6114 | if (unlikely(rc)) { |
| 6115 | kfree(vpd); |
| 6116 | goto out_free_mbox; |
| 6117 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6118 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6119 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
| 6120 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6121 | phba->hba_flag |= HBA_FCOE_MODE; |
| 6122 | else |
| 6123 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6124 | |
| 6125 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6126 | LPFC_DCBX_CEE_MODE) |
| 6127 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6128 | else |
| 6129 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6130 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6131 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6132 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6133 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6134 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6135 | "0376 READ_REV Error. SLI Level %d " |
| 6136 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6137 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6138 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6139 | kfree(vpd); |
| 6140 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6141 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6142 | |
| 6143 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6144 | * Continue initialization with default values even if driver failed |
| 6145 | * to read FCoE param config regions, only read parameters if the |
| 6146 | * board is FCoE |
| 6147 | */ |
| 6148 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6149 | lpfc_sli4_read_fcoe_params(phba)) |
| 6150 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6151 | "2570 Failed to read FCoE parameters\n"); |
| 6152 | |
| 6153 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6154 | * Retrieve sli4 device physical port name, failure of doing it |
| 6155 | * is considered as non-fatal. |
| 6156 | */ |
| 6157 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6158 | if (!rc) |
| 6159 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6160 | "3080 Successful retrieving SLI4 device " |
| 6161 | "physical port name: %s.\n", phba->Port); |
| 6162 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6163 | /* |
| 6164 | * Evaluate the read rev and vpd data. Populate the driver |
| 6165 | * state with the results. If this routine fails, the failure |
| 6166 | * is not fatal as the driver will use generic values. |
| 6167 | */ |
| 6168 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6169 | if (unlikely(!rc)) { |
| 6170 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6171 | "0377 Error %d parsing vpd. " |
| 6172 | "Using defaults.\n", rc); |
| 6173 | rc = 0; |
| 6174 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6175 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6176 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6177 | /* Save information as VPD data */ |
| 6178 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6179 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6180 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6181 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6182 | &mqe->un.read_rev); |
| 6183 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6184 | &mqe->un.read_rev); |
| 6185 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6186 | &mqe->un.read_rev); |
| 6187 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6188 | &mqe->un.read_rev); |
| 6189 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6190 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6191 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6192 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6193 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6194 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6195 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6196 | "(%d):0380 READ_REV Status x%x " |
| 6197 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6198 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6199 | bf_get(lpfc_mqe_status, mqe), |
| 6200 | phba->vpd.rev.opFwName, |
| 6201 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6202 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6203 | |
| 6204 | /* |
| 6205 | * Discover the port's supported feature set and match it against the |
| 6206 | * hosts requests. |
| 6207 | */ |
| 6208 | lpfc_request_features(phba, mboxq); |
| 6209 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6210 | if (unlikely(rc)) { |
| 6211 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6212 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | /* |
| 6216 | * The port must support FCP initiator mode as this is the |
| 6217 | * only mode running in the host. |
| 6218 | */ |
| 6219 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6220 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6221 | "0378 No support for fcpi mode.\n"); |
| 6222 | ftr_rsp++; |
| 6223 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6224 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6225 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6226 | else |
| 6227 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6228 | /* |
| 6229 | * If the port cannot support the host's requested features |
| 6230 | * then turn off the global config parameters to disable the |
| 6231 | * feature in the driver. This is not a fatal error. |
| 6232 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6233 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6234 | if (phba->cfg_enable_bg) { |
| 6235 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6236 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6237 | else |
| 6238 | ftr_rsp++; |
| 6239 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6240 | |
| 6241 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6242 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6243 | ftr_rsp++; |
| 6244 | |
| 6245 | if (ftr_rsp) { |
| 6246 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6247 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6248 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6249 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6250 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6251 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6252 | phba->cfg_enable_bg = 0; |
| 6253 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6254 | phba->cfg_enable_npiv = 0; |
| 6255 | } |
| 6256 | |
| 6257 | /* These SLI3 features are assumed in SLI4 */ |
| 6258 | spin_lock_irq(&phba->hbalock); |
| 6259 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6260 | spin_unlock_irq(&phba->hbalock); |
| 6261 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6262 | /* |
| 6263 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6264 | * calls depends on these resources to complete port setup. |
| 6265 | */ |
| 6266 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6267 | if (rc) { |
| 6268 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6269 | "2920 Failed to alloc Resource IDs " |
| 6270 | "rc = x%x\n", rc); |
| 6271 | goto out_free_mbox; |
| 6272 | } |
| 6273 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6274 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6275 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6276 | if (rc) { |
| 6277 | phba->link_state = LPFC_HBA_ERROR; |
| 6278 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6279 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6280 | } |
| 6281 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6282 | mboxq->vport = vport; |
| 6283 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6284 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6285 | if (rc == MBX_SUCCESS) { |
| 6286 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6287 | rc = 0; |
| 6288 | } |
| 6289 | |
| 6290 | /* |
| 6291 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6292 | * it to the mbuf pool. |
| 6293 | */ |
| 6294 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6295 | kfree(mp); |
| 6296 | mboxq->context1 = NULL; |
| 6297 | if (unlikely(rc)) { |
| 6298 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6299 | "0382 READ_SPARAM command failed " |
| 6300 | "status %d, mbxStatus x%x\n", |
| 6301 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6302 | phba->link_state = LPFC_HBA_ERROR; |
| 6303 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6304 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6305 | } |
| 6306 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6307 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6308 | |
| 6309 | /* Update the fc_host data structures with new wwn. */ |
| 6310 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6311 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6312 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6313 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6314 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6315 | if (unlikely(rc)) { |
| 6316 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6317 | "1400 Failed to update xri-sgl size and " |
| 6318 | "mapping: %d\n", rc); |
| 6319 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6320 | } |
| 6321 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6322 | /* register the els sgl pool to the port */ |
| 6323 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6324 | if (unlikely(rc)) { |
| 6325 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6326 | "0582 Error %d during els sgl post " |
| 6327 | "operation\n", rc); |
| 6328 | rc = -ENODEV; |
| 6329 | goto out_free_mbox; |
| 6330 | } |
| 6331 | |
| 6332 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6333 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6334 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6335 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6336 | "0383 Error %d during scsi sgl post " |
| 6337 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6338 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6339 | /* A pci function reset will repost them */ |
| 6340 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6341 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | /* Post the rpi header region to the device. */ |
| 6345 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6346 | if (unlikely(rc)) { |
| 6347 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6348 | "0393 Error %d during rpi post operation\n", |
| 6349 | rc); |
| 6350 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6351 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6352 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6353 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6354 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6355 | /* Create all the SLI4 queues */ |
| 6356 | rc = lpfc_sli4_queue_create(phba); |
| 6357 | if (rc) { |
| 6358 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6359 | "3089 Failed to allocate queues\n"); |
| 6360 | rc = -ENODEV; |
| 6361 | goto out_stop_timers; |
| 6362 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6363 | /* Set up all the queues to the device */ |
| 6364 | rc = lpfc_sli4_queue_setup(phba); |
| 6365 | if (unlikely(rc)) { |
| 6366 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6367 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6368 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | /* Arm the CQs and then EQs on device */ |
| 6372 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6373 | |
| 6374 | /* Indicate device interrupt mode */ |
| 6375 | phba->sli4_hba.intr_enable = 1; |
| 6376 | |
| 6377 | /* Allow asynchronous mailbox command to go through */ |
| 6378 | spin_lock_irq(&phba->hbalock); |
| 6379 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6380 | spin_unlock_irq(&phba->hbalock); |
| 6381 | |
| 6382 | /* Post receive buffers to the device */ |
| 6383 | lpfc_sli4_rb_setup(phba); |
| 6384 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6385 | /* Reset HBA FCF states after HBA reset */ |
| 6386 | phba->fcf.fcf_flag = 0; |
| 6387 | phba->fcf.current_rec.flag = 0; |
| 6388 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6389 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6390 | mod_timer(&vport->els_tmofunc, |
| 6391 | jiffies + HZ * (phba->fc_ratov * 2)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6392 | |
| 6393 | /* Start heart beat timer */ |
| 6394 | mod_timer(&phba->hb_tmofunc, |
| 6395 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 6396 | phba->hb_outstanding = 0; |
| 6397 | phba->last_completion_time = jiffies; |
| 6398 | |
| 6399 | /* Start error attention (ERATT) polling timer */ |
| 6400 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| 6401 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6402 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6403 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6404 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6405 | if (!rc) { |
| 6406 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6407 | "2829 This device supports " |
| 6408 | "Advanced Error Reporting (AER)\n"); |
| 6409 | spin_lock_irq(&phba->hbalock); |
| 6410 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6411 | spin_unlock_irq(&phba->hbalock); |
| 6412 | } else { |
| 6413 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6414 | "2830 This device does not support " |
| 6415 | "Advanced Error Reporting (AER)\n"); |
| 6416 | phba->cfg_aer_support = 0; |
| 6417 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6418 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6419 | } |
| 6420 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6421 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6422 | /* |
| 6423 | * The FC Port needs to register FCFI (index 0) |
| 6424 | */ |
| 6425 | lpfc_reg_fcfi(phba, mboxq); |
| 6426 | mboxq->vport = phba->pport; |
| 6427 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6428 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6429 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6430 | rc = 0; |
| 6431 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6432 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6433 | |
| 6434 | /* Check if the port is configured to be disabled */ |
| 6435 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6436 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6437 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6438 | /* |
| 6439 | * The port is ready, set the host's link state to LINK_DOWN |
| 6440 | * in preparation for link interrupts. |
| 6441 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6442 | spin_lock_irq(&phba->hbalock); |
| 6443 | phba->link_state = LPFC_LINK_DOWN; |
| 6444 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6445 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6446 | (phba->hba_flag & LINK_DISABLED)) { |
| 6447 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6448 | "3103 Adapter Link is disabled.\n"); |
| 6449 | lpfc_down_link(phba, mboxq); |
| 6450 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6451 | if (rc != MBX_SUCCESS) { |
| 6452 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6453 | "3104 Adapter failed to issue " |
| 6454 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6455 | goto out_unset_queue; |
| 6456 | } |
| 6457 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6458 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6459 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6460 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6461 | if (rc) |
| 6462 | goto out_unset_queue; |
| 6463 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6464 | } |
| 6465 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6466 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6467 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6468 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6469 | lpfc_sli4_queue_unset(phba); |
| 6470 | out_destroy_queue: |
| 6471 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6472 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6473 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6474 | out_free_mbox: |
| 6475 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6476 | return rc; |
| 6477 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6478 | |
| 6479 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6480 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6481 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6482 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6483 | * This is the callback function for mailbox timer. The mailbox |
| 6484 | * timer is armed when a new mailbox command is issued and the timer |
| 6485 | * is deleted when the mailbox complete. The function is called by |
| 6486 | * the kernel timer code when a mailbox does not complete within |
| 6487 | * expected time. This function wakes up the worker thread to |
| 6488 | * process the mailbox timeout and returns. All the processing is |
| 6489 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6490 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6491 | void |
| 6492 | lpfc_mbox_timeout(unsigned long ptr) |
| 6493 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6494 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6495 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6496 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6497 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6498 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6499 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6500 | if (!tmo_posted) |
| 6501 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6502 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6503 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6504 | if (!tmo_posted) |
| 6505 | lpfc_worker_wake_up(phba); |
| 6506 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6507 | } |
| 6508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6509 | |
| 6510 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6511 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6512 | * @phba: Pointer to HBA context object. |
| 6513 | * |
| 6514 | * This function is called from worker thread when a mailbox command times out. |
| 6515 | * The caller is not required to hold any locks. This function will reset the |
| 6516 | * HBA and recover all the pending commands. |
| 6517 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6518 | void |
| 6519 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6520 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6521 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6522 | MAILBOX_t *mb = &pmbox->u.mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6523 | struct lpfc_sli *psli = &phba->sli; |
| 6524 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6525 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6526 | /* Check the pmbox pointer first. There is a race condition |
| 6527 | * between the mbox timeout handler getting executed in the |
| 6528 | * worklist and the mailbox actually completing. When this |
| 6529 | * race condition occurs, the mbox_active will be NULL. |
| 6530 | */ |
| 6531 | spin_lock_irq(&phba->hbalock); |
| 6532 | if (pmbox == NULL) { |
| 6533 | lpfc_printf_log(phba, KERN_WARNING, |
| 6534 | LOG_MBOX | LOG_SLI, |
| 6535 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6536 | "exiting\n"); |
| 6537 | spin_unlock_irq(&phba->hbalock); |
| 6538 | return; |
| 6539 | } |
| 6540 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6541 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6542 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6543 | "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] | 6544 | mb->mbxCommand, |
| 6545 | phba->pport->port_state, |
| 6546 | phba->sli.sli_flag, |
| 6547 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6548 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6549 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6550 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6551 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6552 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6553 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6554 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6555 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6556 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6557 | spin_lock_irq(&phba->hbalock); |
| 6558 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6559 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6560 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6561 | |
| 6562 | pring = &psli->ring[psli->fcp_ring]; |
| 6563 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 6564 | |
| 6565 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6566 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6567 | |
| 6568 | /* Reset the HBA device */ |
| 6569 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6570 | } |
| 6571 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6572 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6573 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6574 | * @phba: Pointer to HBA context object. |
| 6575 | * @pmbox: Pointer to mailbox object. |
| 6576 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6577 | * |
| 6578 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6579 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6580 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6581 | * The mailbox command can be submitted in polling mode, in which case |
| 6582 | * this function will wait in a polling loop for the completion of the |
| 6583 | * mailbox. |
| 6584 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6585 | * function will submit the command and returns immediately without waiting |
| 6586 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6587 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6588 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6589 | * mailbox is issued in polling mode and there is already a mailbox |
| 6590 | * pending, then the function will return an error. If the mailbox is issued |
| 6591 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6592 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6593 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6594 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6595 | * return codes the caller owns the mailbox command after the return of |
| 6596 | * the function. |
| 6597 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6598 | static int |
| 6599 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6600 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6601 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6602 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6603 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6604 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6605 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6606 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6607 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6608 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6609 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6610 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6611 | int processing_queue = 0; |
| 6612 | |
| 6613 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6614 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6615 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6616 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6617 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6618 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6619 | return MBX_SUCCESS; |
| 6620 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6621 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6622 | pmbox = lpfc_mbox_get(phba); |
| 6623 | if (!pmbox) { |
| 6624 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6625 | return MBX_SUCCESS; |
| 6626 | } |
| 6627 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6628 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6629 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6630 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6631 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6632 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6633 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6634 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6635 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6636 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6637 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6638 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6639 | } |
| 6640 | } |
| 6641 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6642 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6643 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6644 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6645 | goto out_not_finished; |
| 6646 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6647 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6648 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6649 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6650 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6651 | goto out_not_finished; |
| 6652 | } |
| 6653 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6654 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6655 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6656 | mb = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6657 | status = MBX_SUCCESS; |
| 6658 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6659 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6660 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6661 | |
| 6662 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6663 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6664 | "(%d):0311 Mailbox command x%x cannot " |
| 6665 | "issue Data: x%x x%x\n", |
| 6666 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6667 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6668 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6669 | } |
| 6670 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6671 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
| 6672 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6673 | !(hc_copy & HC_MBINT_ENA)) { |
| 6674 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6675 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6676 | "(%d):2528 Mailbox command x%x cannot " |
| 6677 | "issue Data: x%x x%x\n", |
| 6678 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6679 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6680 | goto out_not_finished; |
| 6681 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6682 | } |
| 6683 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6684 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6685 | /* Polling for a mbox command when another one is already active |
| 6686 | * is not allowed in SLI. Also, the driver must have established |
| 6687 | * SLI2 mode to queue and process multiple mbox commands. |
| 6688 | */ |
| 6689 | |
| 6690 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6691 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6692 | |
| 6693 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6694 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6695 | "(%d):2529 Mailbox command x%x " |
| 6696 | "cannot issue Data: x%x x%x\n", |
| 6697 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6698 | pmbox->u.mb.mbxCommand, |
| 6699 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6700 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6701 | } |
| 6702 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6703 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6704 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6705 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6706 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6707 | "(%d):2530 Mailbox command x%x " |
| 6708 | "cannot issue Data: x%x x%x\n", |
| 6709 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6710 | pmbox->u.mb.mbxCommand, |
| 6711 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6712 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6713 | } |
| 6714 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6715 | /* Another mailbox command is still being processed, queue this |
| 6716 | * command to be processed later. |
| 6717 | */ |
| 6718 | lpfc_mbox_put(phba, pmbox); |
| 6719 | |
| 6720 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6721 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6722 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6723 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6724 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 6725 | mb->mbxCommand, phba->pport->port_state, |
| 6726 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6727 | |
| 6728 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6729 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6730 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6731 | if (pmbox->vport) { |
| 6732 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6733 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6734 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 6735 | (uint32_t)mb->mbxCommand, |
| 6736 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6737 | } |
| 6738 | else { |
| 6739 | lpfc_debugfs_disc_trc(phba->pport, |
| 6740 | LPFC_DISC_TRC_MBOX, |
| 6741 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 6742 | (uint32_t)mb->mbxCommand, |
| 6743 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6744 | } |
| 6745 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6746 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6747 | } |
| 6748 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6749 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6750 | |
| 6751 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 6752 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6753 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6754 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6755 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6756 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6757 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6758 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6759 | "(%d):2531 Mailbox command x%x " |
| 6760 | "cannot issue Data: x%x x%x\n", |
| 6761 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6762 | pmbox->u.mb.mbxCommand, |
| 6763 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6764 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6765 | } |
| 6766 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 6767 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6768 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6772 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6773 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6774 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6775 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6776 | mb->mbxCommand, phba->pport->port_state, |
| 6777 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6778 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6779 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 6780 | if (pmbox->vport) { |
| 6781 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6782 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6783 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 6784 | (uint32_t)mb->mbxCommand, |
| 6785 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6786 | } |
| 6787 | else { |
| 6788 | lpfc_debugfs_disc_trc(phba->pport, |
| 6789 | LPFC_DISC_TRC_MBOX, |
| 6790 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 6791 | (uint32_t)mb->mbxCommand, |
| 6792 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6793 | } |
| 6794 | } |
| 6795 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6796 | psli->slistat.mbox_cmd++; |
| 6797 | evtctr = psli->slistat.mbox_event; |
| 6798 | |
| 6799 | /* next set own bit for the adapter and copy over command word */ |
| 6800 | mb->mbxOwner = OWN_CHIP; |
| 6801 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6802 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6803 | /* Populate mbox extension offset word. */ |
| 6804 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
| 6805 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6806 | = (uint8_t *)phba->mbox_ext |
| 6807 | - (uint8_t *)phba->mbox; |
| 6808 | } |
| 6809 | |
| 6810 | /* Copy the mailbox extension data */ |
| 6811 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6812 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 6813 | (uint8_t *)phba->mbox_ext, |
| 6814 | pmbox->in_ext_byte_len); |
| 6815 | } |
| 6816 | /* Copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6817 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6818 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6819 | /* Populate mbox extension offset word. */ |
| 6820 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
| 6821 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6822 | = MAILBOX_HBA_EXT_OFFSET; |
| 6823 | |
| 6824 | /* Copy the mailbox extension data */ |
| 6825 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6826 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 6827 | MAILBOX_HBA_EXT_OFFSET, |
| 6828 | pmbox->context2, pmbox->in_ext_byte_len); |
| 6829 | |
| 6830 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6831 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6832 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6833 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6834 | } |
| 6835 | |
| 6836 | /* First copy mbox command data to HBA SLIM, skip past first |
| 6837 | word */ |
| 6838 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 6839 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 6840 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 6841 | |
| 6842 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6843 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6844 | to_slim = phba->MBslimaddr; |
| 6845 | writel(ldata, to_slim); |
| 6846 | readl(to_slim); /* flush */ |
| 6847 | |
| 6848 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6849 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6850 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6851 | } |
| 6852 | } |
| 6853 | |
| 6854 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6855 | |
| 6856 | switch (flag) { |
| 6857 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6858 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6859 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6860 | /* Interrupt board to do it */ |
| 6861 | writel(CA_MBATT, phba->CAregaddr); |
| 6862 | readl(phba->CAregaddr); /* flush */ |
| 6863 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6864 | break; |
| 6865 | |
| 6866 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6867 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6868 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6869 | /* Interrupt board to do it */ |
| 6870 | writel(CA_MBATT, phba->CAregaddr); |
| 6871 | readl(phba->CAregaddr); /* flush */ |
| 6872 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6873 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6874 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6875 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6876 | word0 = le32_to_cpu(word0); |
| 6877 | } else { |
| 6878 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6879 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 6880 | spin_unlock_irqrestore(&phba->hbalock, |
| 6881 | drvr_flag); |
| 6882 | goto out_not_finished; |
| 6883 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6884 | } |
| 6885 | |
| 6886 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6887 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6888 | spin_unlock_irqrestore(&phba->hbalock, |
| 6889 | drvr_flag); |
| 6890 | goto out_not_finished; |
| 6891 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6892 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 6893 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6894 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6895 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6896 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 6897 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6898 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6899 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6900 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6901 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6902 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6903 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6904 | } |
| 6905 | |
| 6906 | /* Check if we took a mbox interrupt while we were |
| 6907 | polling */ |
| 6908 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 6909 | && (evtctr != psli->slistat.mbox_event)) |
| 6910 | break; |
| 6911 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6912 | if (i++ > 10) { |
| 6913 | spin_unlock_irqrestore(&phba->hbalock, |
| 6914 | drvr_flag); |
| 6915 | msleep(1); |
| 6916 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6917 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6918 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6919 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6920 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6921 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6922 | word0 = le32_to_cpu(word0); |
| 6923 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6924 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6925 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6926 | /* Check real SLIM for any errors */ |
| 6927 | slimword0 = readl(phba->MBslimaddr); |
| 6928 | slimmb = (MAILBOX_t *) & slimword0; |
| 6929 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 6930 | && slimmb->mbxStatus) { |
| 6931 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6932 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6933 | word0 = slimword0; |
| 6934 | } |
| 6935 | } |
| 6936 | } else { |
| 6937 | /* First copy command data */ |
| 6938 | word0 = readl(phba->MBslimaddr); |
| 6939 | } |
| 6940 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6941 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6942 | spin_unlock_irqrestore(&phba->hbalock, |
| 6943 | drvr_flag); |
| 6944 | goto out_not_finished; |
| 6945 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6946 | } |
| 6947 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6948 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6949 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6950 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6951 | /* Copy the mailbox extension data */ |
| 6952 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6953 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 6954 | pmbox->context2, |
| 6955 | pmbox->out_ext_byte_len); |
| 6956 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6957 | } else { |
| 6958 | /* First copy command data */ |
| 6959 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 6960 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6961 | /* Copy the mailbox extension data */ |
| 6962 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6963 | lpfc_memcpy_from_slim(pmbox->context2, |
| 6964 | phba->MBslimaddr + |
| 6965 | MAILBOX_HBA_EXT_OFFSET, |
| 6966 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6967 | } |
| 6968 | } |
| 6969 | |
| 6970 | writel(HA_MBATT, phba->HAregaddr); |
| 6971 | readl(phba->HAregaddr); /* flush */ |
| 6972 | |
| 6973 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 6974 | status = mb->mbxStatus; |
| 6975 | } |
| 6976 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6977 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6978 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6979 | |
| 6980 | out_not_finished: |
| 6981 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6982 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6983 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 6984 | } |
| 6985 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6986 | } |
| 6987 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6988 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6989 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 6990 | * @phba: Pointer to HBA context object. |
| 6991 | * |
| 6992 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 6993 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 6994 | * possible outstanding mailbox command before return. |
| 6995 | * |
| 6996 | * Returns: |
| 6997 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 6998 | * the outstanding mailbox command timed out. |
| 6999 | **/ |
| 7000 | static int |
| 7001 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7002 | { |
| 7003 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7004 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7005 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7006 | |
| 7007 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7008 | spin_lock_irq(&phba->hbalock); |
| 7009 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7010 | /* Determine how long we might wait for the active mailbox |
| 7011 | * command to be gracefully completed by firmware. |
| 7012 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7013 | if (phba->sli.mbox_active) |
| 7014 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7015 | phba->sli.mbox_active) * |
| 7016 | 1000) + jiffies; |
| 7017 | spin_unlock_irq(&phba->hbalock); |
| 7018 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7019 | /* Wait for the outstnading mailbox command to complete */ |
| 7020 | while (phba->sli.mbox_active) { |
| 7021 | /* Check active mailbox complete status every 2ms */ |
| 7022 | msleep(2); |
| 7023 | if (time_after(jiffies, timeout)) { |
| 7024 | /* Timeout, marked the outstanding cmd not complete */ |
| 7025 | rc = 1; |
| 7026 | break; |
| 7027 | } |
| 7028 | } |
| 7029 | |
| 7030 | /* Can not cleanly block async mailbox command, fails it */ |
| 7031 | if (rc) { |
| 7032 | spin_lock_irq(&phba->hbalock); |
| 7033 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7034 | spin_unlock_irq(&phba->hbalock); |
| 7035 | } |
| 7036 | return rc; |
| 7037 | } |
| 7038 | |
| 7039 | /** |
| 7040 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7041 | * @phba: Pointer to HBA context object. |
| 7042 | * |
| 7043 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7044 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7045 | * that there is no outstanding mailbox command before resuming posting |
| 7046 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7047 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7048 | * mailbox command posting. |
| 7049 | **/ |
| 7050 | static void |
| 7051 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7052 | { |
| 7053 | struct lpfc_sli *psli = &phba->sli; |
| 7054 | |
| 7055 | spin_lock_irq(&phba->hbalock); |
| 7056 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7057 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7058 | spin_unlock_irq(&phba->hbalock); |
| 7059 | return; |
| 7060 | } |
| 7061 | |
| 7062 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7063 | * successful or timeout, after timing-out the outstanding mailbox |
| 7064 | * command shall always be removed, so just unblock posting async |
| 7065 | * mailbox command and resume |
| 7066 | */ |
| 7067 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7068 | spin_unlock_irq(&phba->hbalock); |
| 7069 | |
| 7070 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7071 | lpfc_worker_wake_up(phba); |
| 7072 | } |
| 7073 | |
| 7074 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7075 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7076 | * @phba: Pointer to HBA context object. |
| 7077 | * @mboxq: Pointer to mailbox object. |
| 7078 | * |
| 7079 | * The function waits for the bootstrap mailbox register ready bit from |
| 7080 | * port for twice the regular mailbox command timeout value. |
| 7081 | * |
| 7082 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7083 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7084 | **/ |
| 7085 | static int |
| 7086 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7087 | { |
| 7088 | uint32_t db_ready; |
| 7089 | unsigned long timeout; |
| 7090 | struct lpfc_register bmbx_reg; |
| 7091 | |
| 7092 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7093 | * 1000) + jiffies; |
| 7094 | |
| 7095 | do { |
| 7096 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7097 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7098 | if (!db_ready) |
| 7099 | msleep(2); |
| 7100 | |
| 7101 | if (time_after(jiffies, timeout)) |
| 7102 | return MBXERR_ERROR; |
| 7103 | } while (!db_ready); |
| 7104 | |
| 7105 | return 0; |
| 7106 | } |
| 7107 | |
| 7108 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7109 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7110 | * @phba: Pointer to HBA context object. |
| 7111 | * @mboxq: Pointer to mailbox object. |
| 7112 | * |
| 7113 | * The function posts a mailbox to the port. The mailbox is expected |
| 7114 | * to be comletely filled in and ready for the port to operate on it. |
| 7115 | * This routine executes a synchronous completion operation on the |
| 7116 | * mailbox by polling for its completion. |
| 7117 | * |
| 7118 | * The caller must not be holding any locks when calling this routine. |
| 7119 | * |
| 7120 | * Returns: |
| 7121 | * MBX_SUCCESS - mailbox posted successfully |
| 7122 | * Any of the MBX error values. |
| 7123 | **/ |
| 7124 | static int |
| 7125 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7126 | { |
| 7127 | int rc = MBX_SUCCESS; |
| 7128 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7129 | uint32_t mcqe_status; |
| 7130 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7131 | struct lpfc_sli *psli = &phba->sli; |
| 7132 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7133 | struct lpfc_bmbx_create *mbox_rgn; |
| 7134 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7135 | |
| 7136 | /* |
| 7137 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7138 | * at a time and there is no queueing provided. |
| 7139 | */ |
| 7140 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7141 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7142 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7143 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7144 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7145 | "cannot issue Data: x%x x%x\n", |
| 7146 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7147 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7148 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7149 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7150 | psli->sli_flag, MBX_POLL); |
| 7151 | return MBXERR_ERROR; |
| 7152 | } |
| 7153 | /* The server grabs the token and owns it until release */ |
| 7154 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7155 | phba->sli.mbox_active = mboxq; |
| 7156 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7157 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7158 | /* wait for bootstrap mbox register for readyness */ |
| 7159 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7160 | if (rc) |
| 7161 | goto exit; |
| 7162 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7163 | /* |
| 7164 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7165 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7166 | * the bmbx mailbox region. |
| 7167 | */ |
| 7168 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7169 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7170 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7171 | sizeof(struct lpfc_mqe)); |
| 7172 | |
| 7173 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7174 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7175 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7176 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7177 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7178 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7179 | if (rc) |
| 7180 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7181 | |
| 7182 | /* Post the low mailbox dma address to the port. */ |
| 7183 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7184 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7185 | /* wait for bootstrap mbox register for low address write done */ |
| 7186 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7187 | if (rc) |
| 7188 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7189 | |
| 7190 | /* |
| 7191 | * Read the CQ to ensure the mailbox has completed. |
| 7192 | * If so, update the mailbox status so that the upper layers |
| 7193 | * can complete the request normally. |
| 7194 | */ |
| 7195 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7196 | sizeof(struct lpfc_mqe)); |
| 7197 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7198 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7199 | sizeof(struct lpfc_mcqe)); |
| 7200 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7201 | /* |
| 7202 | * When the CQE status indicates a failure and the mailbox status |
| 7203 | * indicates success then copy the CQE status into the mailbox status |
| 7204 | * (and prefix it with x4000). |
| 7205 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7206 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7207 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7208 | bf_set(lpfc_mqe_status, mb, |
| 7209 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7210 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7211 | } else |
| 7212 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7213 | |
| 7214 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7215 | "(%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] | 7216 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7217 | " 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] | 7218 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7219 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7220 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7221 | bf_get(lpfc_mqe_status, mb), |
| 7222 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7223 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7224 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7225 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7226 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7227 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7228 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7229 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7230 | mboxq->mcqe.trailer); |
| 7231 | exit: |
| 7232 | /* We are holding the token, no needed for lock when release */ |
| 7233 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7234 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7235 | phba->sli.mbox_active = NULL; |
| 7236 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7237 | return rc; |
| 7238 | } |
| 7239 | |
| 7240 | /** |
| 7241 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7242 | * @phba: Pointer to HBA context object. |
| 7243 | * @pmbox: Pointer to mailbox object. |
| 7244 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7245 | * |
| 7246 | * This function is called by discovery code and HBA management code to submit |
| 7247 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7248 | * |
| 7249 | * Return codes the caller owns the mailbox command after the return of the |
| 7250 | * function. |
| 7251 | **/ |
| 7252 | static int |
| 7253 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7254 | uint32_t flag) |
| 7255 | { |
| 7256 | struct lpfc_sli *psli = &phba->sli; |
| 7257 | unsigned long iflags; |
| 7258 | int rc; |
| 7259 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7260 | /* dump from issue mailbox command if setup */ |
| 7261 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7262 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7263 | rc = lpfc_mbox_dev_check(phba); |
| 7264 | if (unlikely(rc)) { |
| 7265 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7266 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7267 | "cannot issue Data: x%x x%x\n", |
| 7268 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7269 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7270 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7271 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7272 | psli->sli_flag, flag); |
| 7273 | goto out_not_finished; |
| 7274 | } |
| 7275 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7276 | /* Detect polling mode and jump to a handler */ |
| 7277 | if (!phba->sli4_hba.intr_enable) { |
| 7278 | if (flag == MBX_POLL) |
| 7279 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7280 | else |
| 7281 | rc = -EIO; |
| 7282 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7283 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7284 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7285 | "(x%x/x%x) failure: " |
| 7286 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7287 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7288 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7289 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7290 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7291 | mboxq), |
| 7292 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7293 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7294 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7295 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7296 | bf_get(lpfc_mcqe_ext_status, |
| 7297 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7298 | psli->sli_flag, flag); |
| 7299 | return rc; |
| 7300 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7301 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7302 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7303 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7304 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7305 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7306 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7307 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7308 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7309 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7310 | /* Try to block the asynchronous mailbox posting */ |
| 7311 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7312 | if (!rc) { |
| 7313 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7314 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7315 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7316 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7317 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7318 | "(%d):2597 Sync Mailbox command " |
| 7319 | "x%x (x%x/x%x) failure: " |
| 7320 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7321 | "Data: x%x x%x\n,", |
| 7322 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7323 | mboxq->u.mb.mbxCommand, |
| 7324 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7325 | mboxq), |
| 7326 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7327 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7328 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7329 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7330 | bf_get(lpfc_mcqe_ext_status, |
| 7331 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7332 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7333 | /* Unblock the async mailbox posting afterward */ |
| 7334 | lpfc_sli4_async_mbox_unblock(phba); |
| 7335 | } |
| 7336 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7337 | } |
| 7338 | |
| 7339 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7340 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7341 | if (rc) { |
| 7342 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7343 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7344 | "cannot issue Data: x%x x%x\n", |
| 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, mboxq), |
| 7348 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7349 | psli->sli_flag, flag); |
| 7350 | goto out_not_finished; |
| 7351 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7352 | |
| 7353 | /* Put the mailbox command to the driver internal FIFO */ |
| 7354 | psli->slistat.mbox_busy++; |
| 7355 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7356 | lpfc_mbox_put(phba, mboxq); |
| 7357 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7358 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7359 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7360 | "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] | 7361 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7362 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7363 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7364 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7365 | phba->pport->port_state, |
| 7366 | psli->sli_flag, MBX_NOWAIT); |
| 7367 | /* Wake up worker thread to transport mailbox command from head */ |
| 7368 | lpfc_worker_wake_up(phba); |
| 7369 | |
| 7370 | return MBX_BUSY; |
| 7371 | |
| 7372 | out_not_finished: |
| 7373 | return MBX_NOT_FINISHED; |
| 7374 | } |
| 7375 | |
| 7376 | /** |
| 7377 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7378 | * @phba: Pointer to HBA context object. |
| 7379 | * |
| 7380 | * This function is called by worker thread to send a mailbox command to |
| 7381 | * SLI4 HBA firmware. |
| 7382 | * |
| 7383 | **/ |
| 7384 | int |
| 7385 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7386 | { |
| 7387 | struct lpfc_sli *psli = &phba->sli; |
| 7388 | LPFC_MBOXQ_t *mboxq; |
| 7389 | int rc = MBX_SUCCESS; |
| 7390 | unsigned long iflags; |
| 7391 | struct lpfc_mqe *mqe; |
| 7392 | uint32_t mbx_cmnd; |
| 7393 | |
| 7394 | /* Check interrupt mode before post async mailbox command */ |
| 7395 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7396 | return MBX_NOT_FINISHED; |
| 7397 | |
| 7398 | /* Check for mailbox command service token */ |
| 7399 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7400 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7401 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7402 | return MBX_NOT_FINISHED; |
| 7403 | } |
| 7404 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7405 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7406 | return MBX_NOT_FINISHED; |
| 7407 | } |
| 7408 | if (unlikely(phba->sli.mbox_active)) { |
| 7409 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7410 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7411 | "0384 There is pending active mailbox cmd\n"); |
| 7412 | return MBX_NOT_FINISHED; |
| 7413 | } |
| 7414 | /* Take the mailbox command service token */ |
| 7415 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7416 | |
| 7417 | /* Get the next mailbox command from head of queue */ |
| 7418 | mboxq = lpfc_mbox_get(phba); |
| 7419 | |
| 7420 | /* If no more mailbox command waiting for post, we're done */ |
| 7421 | if (!mboxq) { |
| 7422 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7423 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7424 | return MBX_SUCCESS; |
| 7425 | } |
| 7426 | phba->sli.mbox_active = mboxq; |
| 7427 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7428 | |
| 7429 | /* Check device readiness for posting mailbox command */ |
| 7430 | rc = lpfc_mbox_dev_check(phba); |
| 7431 | if (unlikely(rc)) |
| 7432 | /* Driver clean routine will clean up pending mailbox */ |
| 7433 | goto out_not_finished; |
| 7434 | |
| 7435 | /* Prepare the mbox command to be posted */ |
| 7436 | mqe = &mboxq->u.mqe; |
| 7437 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7438 | |
| 7439 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7440 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7441 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7442 | |
| 7443 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7444 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7445 | "x%x x%x\n", |
| 7446 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7447 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7448 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7449 | phba->pport->port_state, psli->sli_flag); |
| 7450 | |
| 7451 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7452 | if (mboxq->vport) { |
| 7453 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7454 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7455 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7456 | mbx_cmnd, mqe->un.mb_words[0], |
| 7457 | mqe->un.mb_words[1]); |
| 7458 | } else { |
| 7459 | lpfc_debugfs_disc_trc(phba->pport, |
| 7460 | LPFC_DISC_TRC_MBOX, |
| 7461 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7462 | mbx_cmnd, mqe->un.mb_words[0], |
| 7463 | mqe->un.mb_words[1]); |
| 7464 | } |
| 7465 | } |
| 7466 | psli->slistat.mbox_cmd++; |
| 7467 | |
| 7468 | /* Post the mailbox command to the port */ |
| 7469 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7470 | if (rc != MBX_SUCCESS) { |
| 7471 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7472 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7473 | "cannot issue Data: x%x x%x\n", |
| 7474 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7475 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7476 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7477 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7478 | psli->sli_flag, MBX_NOWAIT); |
| 7479 | goto out_not_finished; |
| 7480 | } |
| 7481 | |
| 7482 | return rc; |
| 7483 | |
| 7484 | out_not_finished: |
| 7485 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7486 | if (phba->sli.mbox_active) { |
| 7487 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7488 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7489 | /* Release the token */ |
| 7490 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7491 | phba->sli.mbox_active = NULL; |
| 7492 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7493 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7494 | |
| 7495 | return MBX_NOT_FINISHED; |
| 7496 | } |
| 7497 | |
| 7498 | /** |
| 7499 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7500 | * @phba: Pointer to HBA context object. |
| 7501 | * @pmbox: Pointer to mailbox object. |
| 7502 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7503 | * |
| 7504 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7505 | * the API jump table function pointer from the lpfc_hba struct. |
| 7506 | * |
| 7507 | * Return codes the caller owns the mailbox command after the return of the |
| 7508 | * function. |
| 7509 | **/ |
| 7510 | int |
| 7511 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7512 | { |
| 7513 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7514 | } |
| 7515 | |
| 7516 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7517 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7518 | * @phba: The hba struct for which this call is being executed. |
| 7519 | * @dev_grp: The HBA PCI-Device group number. |
| 7520 | * |
| 7521 | * This routine sets up the mbox interface API function jump table in @phba |
| 7522 | * struct. |
| 7523 | * Returns: 0 - success, -ENODEV - failure. |
| 7524 | **/ |
| 7525 | int |
| 7526 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7527 | { |
| 7528 | |
| 7529 | switch (dev_grp) { |
| 7530 | case LPFC_PCI_DEV_LP: |
| 7531 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7532 | phba->lpfc_sli_handle_slow_ring_event = |
| 7533 | lpfc_sli_handle_slow_ring_event_s3; |
| 7534 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7535 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7536 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7537 | break; |
| 7538 | case LPFC_PCI_DEV_OC: |
| 7539 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7540 | phba->lpfc_sli_handle_slow_ring_event = |
| 7541 | lpfc_sli_handle_slow_ring_event_s4; |
| 7542 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7543 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7544 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7545 | break; |
| 7546 | default: |
| 7547 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7548 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7549 | dev_grp); |
| 7550 | return -ENODEV; |
| 7551 | break; |
| 7552 | } |
| 7553 | return 0; |
| 7554 | } |
| 7555 | |
| 7556 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7557 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7558 | * @phba: Pointer to HBA context object. |
| 7559 | * @pring: Pointer to driver SLI ring object. |
| 7560 | * @piocb: Pointer to address of newly added command iocb. |
| 7561 | * |
| 7562 | * This function is called with hbalock held to add a command |
| 7563 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7564 | * to the ring. |
| 7565 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7566 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7567 | __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] | 7568 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7569 | { |
| 7570 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7571 | list_add_tail(&piocb->list, &pring->txq); |
| 7572 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7573 | } |
| 7574 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7575 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7576 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7577 | * @phba: Pointer to HBA context object. |
| 7578 | * @pring: Pointer to driver SLI ring object. |
| 7579 | * @piocb: Pointer to address of newly added command iocb. |
| 7580 | * |
| 7581 | * This function is called with hbalock held before a new |
| 7582 | * iocb is submitted to the firmware. This function checks |
| 7583 | * txq to flush the iocbs in txq to Firmware before |
| 7584 | * submitting new iocbs to the Firmware. |
| 7585 | * If there are iocbs in the txq which need to be submitted |
| 7586 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7587 | * of the txq after dequeuing it from txq. |
| 7588 | * If there is no iocb in the txq then the function will return |
| 7589 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7590 | * *piocb to find if there are more commands in the txq. |
| 7591 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7592 | static struct lpfc_iocbq * |
| 7593 | 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] | 7594 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7595 | { |
| 7596 | struct lpfc_iocbq * nextiocb; |
| 7597 | |
| 7598 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7599 | if (!nextiocb) { |
| 7600 | nextiocb = *piocb; |
| 7601 | *piocb = NULL; |
| 7602 | } |
| 7603 | |
| 7604 | return nextiocb; |
| 7605 | } |
| 7606 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7607 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7608 | * __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] | 7609 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7610 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7611 | * @piocb: Pointer to command iocb. |
| 7612 | * @flag: Flag indicating if this command can be put into txq. |
| 7613 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7614 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7615 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7616 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7617 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7618 | * this function allows only iocbs for posting buffers. This function finds |
| 7619 | * next available slot in the command ring and posts the command to the |
| 7620 | * available slot and writes the port attention register to request HBA start |
| 7621 | * processing new iocb. If there is no slot available in the ring and |
| 7622 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7623 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7624 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7625 | * This function is called with hbalock held. The function will return success |
| 7626 | * after it successfully submit the iocb to firmware or after adding to the |
| 7627 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7628 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7629 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7630 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7631 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7632 | { |
| 7633 | struct lpfc_iocbq *nextiocb; |
| 7634 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7635 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7636 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7637 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7638 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7639 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7640 | lpfc_printf_log(phba, KERN_ERR, |
| 7641 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7642 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7643 | piocb->iocb.ulpCommand); |
| 7644 | dump_stack(); |
| 7645 | return IOCB_ERROR; |
| 7646 | } |
| 7647 | |
| 7648 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7649 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7650 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7651 | return IOCB_ERROR; |
| 7652 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7653 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7654 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7655 | return IOCB_ERROR; |
| 7656 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7657 | /* |
| 7658 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7659 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7660 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7661 | return IOCB_ERROR; |
| 7662 | |
| 7663 | /* |
| 7664 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7665 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7666 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7667 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7668 | goto iocb_busy; |
| 7669 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7670 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7671 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7672 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7673 | * can be issued if the link is not up. |
| 7674 | */ |
| 7675 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7676 | case CMD_GEN_REQUEST64_CR: |
| 7677 | case CMD_GEN_REQUEST64_CX: |
| 7678 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 7679 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7680 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7681 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 7682 | MENLO_TRANSPORT_TYPE)) |
| 7683 | |
| 7684 | goto iocb_busy; |
| 7685 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7686 | case CMD_QUE_RING_BUF_CN: |
| 7687 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7688 | /* |
| 7689 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 7690 | * completion, iocb_cmpl MUST be 0. |
| 7691 | */ |
| 7692 | if (piocb->iocb_cmpl) |
| 7693 | piocb->iocb_cmpl = NULL; |
| 7694 | /*FALLTHROUGH*/ |
| 7695 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7696 | case CMD_CLOSE_XRI_CN: |
| 7697 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7698 | break; |
| 7699 | default: |
| 7700 | goto iocb_busy; |
| 7701 | } |
| 7702 | |
| 7703 | /* |
| 7704 | * For FCP commands, we must be in a state where we can process link |
| 7705 | * attention events. |
| 7706 | */ |
| 7707 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7708 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7709 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7710 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7711 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7712 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 7713 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 7714 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 7715 | |
| 7716 | if (iocb) |
| 7717 | lpfc_sli_update_ring(phba, pring); |
| 7718 | else |
| 7719 | lpfc_sli_update_full_ring(phba, pring); |
| 7720 | |
| 7721 | if (!piocb) |
| 7722 | return IOCB_SUCCESS; |
| 7723 | |
| 7724 | goto out_busy; |
| 7725 | |
| 7726 | iocb_busy: |
| 7727 | pring->stats.iocb_cmd_delay++; |
| 7728 | |
| 7729 | out_busy: |
| 7730 | |
| 7731 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7732 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7733 | return IOCB_SUCCESS; |
| 7734 | } |
| 7735 | |
| 7736 | return IOCB_BUSY; |
| 7737 | } |
| 7738 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7739 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7740 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 7741 | * @phba: Pointer to HBA context object. |
| 7742 | * @piocb: Pointer to command iocb. |
| 7743 | * @sglq: Pointer to the scatter gather queue object. |
| 7744 | * |
| 7745 | * This routine converts the bpl or bde that is in the IOCB |
| 7746 | * to a sgl list for the sli4 hardware. The physical address |
| 7747 | * of the bpl/bde is converted back to a virtual address. |
| 7748 | * If the IOCB contains a BPL then the list of BDE's is |
| 7749 | * converted to sli4_sge's. If the IOCB contains a single |
| 7750 | * BDE then it is converted to a single sli_sge. |
| 7751 | * The IOCB is still in cpu endianess so the contents of |
| 7752 | * the bpl can be used without byte swapping. |
| 7753 | * |
| 7754 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 7755 | **/ |
| 7756 | static uint16_t |
| 7757 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 7758 | struct lpfc_sglq *sglq) |
| 7759 | { |
| 7760 | uint16_t xritag = NO_XRI; |
| 7761 | struct ulp_bde64 *bpl = NULL; |
| 7762 | struct ulp_bde64 bde; |
| 7763 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7764 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7765 | IOCB_t *icmd; |
| 7766 | int numBdes = 0; |
| 7767 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7768 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 7769 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7770 | |
| 7771 | if (!piocbq || !sglq) |
| 7772 | return xritag; |
| 7773 | |
| 7774 | sgl = (struct sli4_sge *)sglq->sgl; |
| 7775 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7776 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 7777 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7778 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 7779 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 7780 | sizeof(struct ulp_bde64); |
| 7781 | /* The addrHigh and addrLow fields within the IOCB |
| 7782 | * have not been byteswapped yet so there is no |
| 7783 | * need to swap them back. |
| 7784 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7785 | if (piocbq->context3) |
| 7786 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 7787 | else |
| 7788 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7789 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7790 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7791 | if (!bpl) |
| 7792 | return xritag; |
| 7793 | |
| 7794 | for (i = 0; i < numBdes; i++) { |
| 7795 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7796 | sgl->addr_hi = bpl->addrHigh; |
| 7797 | sgl->addr_lo = bpl->addrLow; |
| 7798 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7799 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7800 | if ((i+1) == numBdes) |
| 7801 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7802 | else |
| 7803 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7804 | /* swap the size field back to the cpu so we |
| 7805 | * can assign it to the sgl. |
| 7806 | */ |
| 7807 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 7808 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7809 | /* The offsets in the sgl need to be accumulated |
| 7810 | * separately for the request and reply lists. |
| 7811 | * The request is always first, the reply follows. |
| 7812 | */ |
| 7813 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 7814 | /* add up the reply sg entries */ |
| 7815 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 7816 | inbound++; |
| 7817 | /* first inbound? reset the offset */ |
| 7818 | if (inbound == 1) |
| 7819 | offset = 0; |
| 7820 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 7821 | bf_set(lpfc_sli4_sge_type, sgl, |
| 7822 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7823 | offset += bde.tus.f.bdeSize; |
| 7824 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7825 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7826 | bpl++; |
| 7827 | sgl++; |
| 7828 | } |
| 7829 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 7830 | /* The addrHigh and addrLow fields of the BDE have not |
| 7831 | * been byteswapped yet so they need to be swapped |
| 7832 | * before putting them in the sgl. |
| 7833 | */ |
| 7834 | sgl->addr_hi = |
| 7835 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 7836 | sgl->addr_lo = |
| 7837 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7838 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7839 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7840 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7841 | sgl->sge_len = |
| 7842 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7843 | } |
| 7844 | return sglq->sli4_xritag; |
| 7845 | } |
| 7846 | |
| 7847 | /** |
| 7848 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 7849 | * @phba: Pointer to HBA context object. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7850 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 7851 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7852 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 7853 | * held. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7854 | * |
| 7855 | * Return: index into SLI4 fast-path FCP queue index. |
| 7856 | **/ |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7857 | static inline uint32_t |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7858 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7859 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7860 | int i; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7861 | |
James Smart | 49aa143 | 2012-08-03 12:36:42 -0400 | [diff] [blame] | 7862 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU) |
| 7863 | i = smp_processor_id(); |
| 7864 | else |
| 7865 | i = atomic_add_return(1, &phba->fcp_qidx); |
| 7866 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7867 | i = (i % phba->cfg_fcp_io_channel); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7868 | return i; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7869 | } |
| 7870 | |
| 7871 | /** |
| 7872 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 7873 | * @phba: Pointer to HBA context object. |
| 7874 | * @piocb: Pointer to command iocb. |
| 7875 | * @wqe: Pointer to the work queue entry. |
| 7876 | * |
| 7877 | * This routine converts the iocb command to its Work Queue Entry |
| 7878 | * equivalent. The wqe pointer should not have any fields set when |
| 7879 | * this routine is called because it will memcpy over them. |
| 7880 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 7881 | * wqe. |
| 7882 | * |
| 7883 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 7884 | **/ |
| 7885 | static int |
| 7886 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 7887 | union lpfc_wqe *wqe) |
| 7888 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7889 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7890 | uint8_t ct = 0; |
| 7891 | uint32_t fip; |
| 7892 | uint32_t abort_tag; |
| 7893 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 7894 | uint8_t cmnd; |
| 7895 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 7896 | uint16_t abrt_iotag; |
| 7897 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7898 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7899 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7900 | int numBdes, i; |
| 7901 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7902 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7903 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7904 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7905 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7906 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7907 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7908 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7909 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7910 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7911 | command_type = ELS_COMMAND_FIP; |
| 7912 | else |
| 7913 | command_type = ELS_COMMAND_NON_FIP; |
| 7914 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7915 | /* Some of the fields are in the right position already */ |
| 7916 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
| 7917 | abort_tag = (uint32_t) iocbq->iotag; |
| 7918 | xritag = iocbq->sli4_xritag; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7919 | 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] | 7920 | /* words0-2 bpl convert bde */ |
| 7921 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7922 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 7923 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7924 | bpl = (struct ulp_bde64 *) |
| 7925 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 7926 | if (!bpl) |
| 7927 | return IOCB_ERROR; |
| 7928 | |
| 7929 | /* Should already be byte swapped. */ |
| 7930 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 7931 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 7932 | /* swap the size field back to the cpu so we |
| 7933 | * can assign it to the sgl. |
| 7934 | */ |
| 7935 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7936 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 7937 | total_len = 0; |
| 7938 | for (i = 0; i < numBdes; i++) { |
| 7939 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 7940 | total_len += bde.tus.f.bdeSize; |
| 7941 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7942 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7943 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7944 | |
| 7945 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 7946 | cmnd = iocbq->iocb.ulpCommand; |
| 7947 | |
| 7948 | switch (iocbq->iocb.ulpCommand) { |
| 7949 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 7950 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 7951 | ndlp = iocbq->context_un.ndlp; |
| 7952 | else |
| 7953 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7954 | if (!iocbq->iocb.ulpLe) { |
| 7955 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7956 | "2007 Only Limited Edition cmd Format" |
| 7957 | " supported 0x%x\n", |
| 7958 | iocbq->iocb.ulpCommand); |
| 7959 | return IOCB_ERROR; |
| 7960 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7961 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7962 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7963 | /* Els_reguest64 has a TMO */ |
| 7964 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 7965 | iocbq->iocb.ulpTimeout); |
| 7966 | /* Need a VF for word 4 set the vf bit*/ |
| 7967 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 7968 | /* And a VFID for word 12 */ |
| 7969 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7970 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7971 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7972 | iocbq->iocb.ulpContext); |
| 7973 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 7974 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7975 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7976 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7977 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 7978 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7979 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7980 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7981 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7982 | &phba->sli4_hba.sli_intf); |
| 7983 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7984 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 7985 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7986 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 7987 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7988 | *pcmd == ELS_CMD_PLOGI)) { |
| 7989 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 7990 | bf_set(els_req64_sid, &wqe->els_req, |
| 7991 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7992 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 7993 | !(phba->fc_topology == |
| 7994 | LPFC_TOPOLOGY_LOOP)) |
| 7995 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7996 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 7997 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 7998 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 7999 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8000 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8001 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8002 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8003 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8004 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8005 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8006 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8007 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8008 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8009 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8010 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8011 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8012 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8013 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8014 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8015 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8016 | iocbq->iocb.un.ulpWord[3]); |
| 8017 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8018 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8019 | /* The entire sequence is transmitted for this IOCB */ |
| 8020 | xmit_len = total_len; |
| 8021 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8022 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8023 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8024 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8025 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8026 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8027 | /* word4 relative_offset memcpy */ |
| 8028 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8029 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8030 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8031 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8032 | LPFC_WQE_IOD_WRITE); |
| 8033 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8034 | LPFC_WQE_LENLOC_WORD12); |
| 8035 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8036 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8037 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8038 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8039 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8040 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8041 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8042 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8043 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8044 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8045 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8046 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8047 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8048 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8049 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8050 | LPFC_WQE_LENLOC_WORD3); |
| 8051 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8052 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8053 | case CMD_FCP_IWRITE64_CR: |
| 8054 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8055 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8056 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8057 | wqe->fcp_iwrite.payload_offset_len = |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8058 | xmit_len + sizeof(struct fcp_rsp); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8059 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8060 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8061 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8062 | iocbq->iocb.ulpFCP2Rcvy); |
| 8063 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8064 | /* Always open the exchange */ |
| 8065 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8066 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8067 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8068 | LPFC_WQE_LENLOC_WORD4); |
| 8069 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); |
| 8070 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8071 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8072 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8073 | case CMD_FCP_IREAD64_CR: |
| 8074 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8075 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8076 | wqe->fcp_iread.payload_offset_len = |
| 8077 | xmit_len + sizeof(struct fcp_rsp); |
| 8078 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8079 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8080 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8081 | iocbq->iocb.ulpFCP2Rcvy); |
| 8082 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8083 | /* Always open the exchange */ |
| 8084 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8085 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8086 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8087 | LPFC_WQE_LENLOC_WORD4); |
| 8088 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); |
| 8089 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8090 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8091 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8092 | case CMD_FCP_ICMND64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8093 | /* word3 iocb=IO_TAG wqe=reserved */ |
| 8094 | wqe->fcp_icmd.rsrvd3 = 0; |
| 8095 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8096 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8097 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
| 8098 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8099 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8100 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8101 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8102 | LPFC_WQE_LENLOC_NONE); |
| 8103 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8104 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8105 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8106 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8107 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8108 | /* For this command calculate the xmit length of the |
| 8109 | * request bde. |
| 8110 | */ |
| 8111 | xmit_len = 0; |
| 8112 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8113 | sizeof(struct ulp_bde64); |
| 8114 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8115 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8116 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8117 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8118 | xmit_len += bde.tus.f.bdeSize; |
| 8119 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8120 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8121 | wqe->gen_req.request_payload_len = xmit_len; |
| 8122 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8123 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8124 | /* word6 context tag copied in memcpy */ |
| 8125 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8126 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8127 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8128 | "2015 Invalid CT %x command 0x%x\n", |
| 8129 | ct, iocbq->iocb.ulpCommand); |
| 8130 | return IOCB_ERROR; |
| 8131 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8132 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8133 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8134 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8135 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8136 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8137 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8138 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8139 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8140 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8141 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8142 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8143 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8144 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8145 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8146 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8147 | /* word4 */ |
| 8148 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8149 | /* word5 iocb=rsvd wge=did */ |
| 8150 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8151 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8152 | |
| 8153 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8154 | &phba->sli4_hba.sli_intf); |
| 8155 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8156 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8157 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8158 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8159 | iocbq->vport->fc_myDID); |
| 8160 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8161 | bf_set(wqe_els_did, |
| 8162 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8163 | } |
| 8164 | } |
| 8165 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8166 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8167 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8168 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8169 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8170 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8171 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8172 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8173 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8174 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8175 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8176 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8177 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8178 | LPFC_WQE_LENLOC_WORD3); |
| 8179 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8180 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8181 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8182 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8183 | iocbq->context2)->virt); |
| 8184 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8185 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8186 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8187 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8188 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8189 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8190 | phba->vpi_ids[phba->pport->vpi]); |
| 8191 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8192 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8193 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8194 | case CMD_CLOSE_XRI_CN: |
| 8195 | case CMD_ABORT_XRI_CN: |
| 8196 | case CMD_ABORT_XRI_CX: |
| 8197 | /* words 0-2 memcpy should be 0 rserved */ |
| 8198 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8199 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8200 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8201 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8202 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8203 | } else |
| 8204 | fip = 0; |
| 8205 | |
| 8206 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8207 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8208 | * The link is down, or the command was ELS_FIP |
| 8209 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8210 | * on the wire. |
| 8211 | */ |
| 8212 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8213 | else |
| 8214 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8215 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8216 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8217 | wqe->abort_cmd.rsrvd5 = 0; |
| 8218 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8219 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8220 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8221 | /* |
| 8222 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8223 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8224 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8225 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8226 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8227 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8228 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8229 | cmnd = CMD_ABORT_XRI_CX; |
| 8230 | command_type = OTHER_COMMAND; |
| 8231 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8232 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8233 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8234 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8235 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8236 | * we re-construct this WQE here based on information in |
| 8237 | * iocbq from scratch. |
| 8238 | */ |
| 8239 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8240 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8241 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8242 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8243 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8244 | LPFC_ABTS_UNSOL_INT) { |
| 8245 | /* ABTS sent by initiator to CT exchange, the |
| 8246 | * RX_ID field will be filled with the newly |
| 8247 | * allocated responder XRI. |
| 8248 | */ |
| 8249 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8250 | iocbq->sli4_xritag); |
| 8251 | } else { |
| 8252 | /* ABTS sent by responder to CT exchange, the |
| 8253 | * RX_ID field will be filled with the responder |
| 8254 | * RX_ID from ABTS. |
| 8255 | */ |
| 8256 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8257 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8258 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8259 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8260 | 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] | 8261 | |
| 8262 | /* Use CT=VPI */ |
| 8263 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8264 | ndlp->nlp_DID); |
| 8265 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8266 | iocbq->iocb.ulpContext); |
| 8267 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8268 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8269 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8270 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8271 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8272 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8273 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8274 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8275 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8276 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8277 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8278 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8279 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8280 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8281 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8282 | } |
| 8283 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8284 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8285 | case CMD_XRI_ABORTED_CX: |
| 8286 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8287 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8288 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8289 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8290 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8291 | default: |
| 8292 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8293 | "2014 Invalid command 0x%x\n", |
| 8294 | iocbq->iocb.ulpCommand); |
| 8295 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8296 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8297 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8298 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 8299 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 8300 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 8301 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 8302 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 8303 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 8304 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 8305 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 8306 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8307 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8308 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8309 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8310 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8311 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8312 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8313 | 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] | 8314 | return 0; |
| 8315 | } |
| 8316 | |
| 8317 | /** |
| 8318 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8319 | * @phba: Pointer to HBA context object. |
| 8320 | * @ring_number: SLI ring number to issue iocb on. |
| 8321 | * @piocb: Pointer to command iocb. |
| 8322 | * @flag: Flag indicating if this command can be put into txq. |
| 8323 | * |
| 8324 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8325 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8326 | * |
| 8327 | * This function is called with hbalock held. The function will return success |
| 8328 | * after it successfully submit the iocb to firmware or after adding to the |
| 8329 | * txq. |
| 8330 | **/ |
| 8331 | static int |
| 8332 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8333 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8334 | { |
| 8335 | struct lpfc_sglq *sglq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8336 | union lpfc_wqe wqe; |
| 8337 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8338 | |
| 8339 | if (piocb->sli4_xritag == NO_XRI) { |
| 8340 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8341 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8342 | sglq = NULL; |
| 8343 | else { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8344 | if (pring->txq_cnt) { |
| 8345 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8346 | __lpfc_sli_ringtx_put(phba, |
| 8347 | pring, piocb); |
| 8348 | return IOCB_SUCCESS; |
| 8349 | } else { |
| 8350 | return IOCB_BUSY; |
| 8351 | } |
| 8352 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8353 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8354 | if (!sglq) { |
| 8355 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8356 | __lpfc_sli_ringtx_put(phba, |
| 8357 | pring, |
| 8358 | piocb); |
| 8359 | return IOCB_SUCCESS; |
| 8360 | } else |
| 8361 | return IOCB_BUSY; |
| 8362 | } |
| 8363 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8364 | } |
| 8365 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8366 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8367 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8368 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8369 | /* |
| 8370 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8371 | * sglq is on the active list |
| 8372 | */ |
| 8373 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); |
| 8374 | if (!sglq) |
| 8375 | return IOCB_ERROR; |
| 8376 | } |
| 8377 | |
| 8378 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8379 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8380 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8381 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8382 | return IOCB_ERROR; |
| 8383 | } |
| 8384 | |
| 8385 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
| 8386 | return IOCB_ERROR; |
| 8387 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8388 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 8389 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8390 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
| 8391 | &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8392 | return IOCB_ERROR; |
| 8393 | } else { |
| 8394 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 8395 | return IOCB_ERROR; |
| 8396 | } |
| 8397 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8398 | |
| 8399 | return 0; |
| 8400 | } |
| 8401 | |
| 8402 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8403 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8404 | * |
| 8405 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8406 | * pointer from the lpfc_hba struct. |
| 8407 | * |
| 8408 | * Return codes: |
| 8409 | * IOCB_ERROR - Error |
| 8410 | * IOCB_SUCCESS - Success |
| 8411 | * IOCB_BUSY - Busy |
| 8412 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8413 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8414 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8415 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8416 | { |
| 8417 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8418 | } |
| 8419 | |
| 8420 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8421 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8422 | * @phba: The hba struct for which this call is being executed. |
| 8423 | * @dev_grp: The HBA PCI-Device group number. |
| 8424 | * |
| 8425 | * This routine sets up the SLI interface API function jump table in @phba |
| 8426 | * struct. |
| 8427 | * Returns: 0 - success, -ENODEV - failure. |
| 8428 | **/ |
| 8429 | int |
| 8430 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8431 | { |
| 8432 | |
| 8433 | switch (dev_grp) { |
| 8434 | case LPFC_PCI_DEV_LP: |
| 8435 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8436 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8437 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8438 | case LPFC_PCI_DEV_OC: |
| 8439 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8440 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8441 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8442 | default: |
| 8443 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8444 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8445 | dev_grp); |
| 8446 | return -ENODEV; |
| 8447 | break; |
| 8448 | } |
| 8449 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8450 | return 0; |
| 8451 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8452 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8453 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8454 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8455 | * @phba: Pointer to HBA context object. |
| 8456 | * @pring: Pointer to driver SLI ring object. |
| 8457 | * @piocb: Pointer to command iocb. |
| 8458 | * @flag: Flag indicating if this command can be put into txq. |
| 8459 | * |
| 8460 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8461 | * function. This function gets the hbalock and calls |
| 8462 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8463 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8464 | * functions which do not hold hbalock. |
| 8465 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8466 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8467 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8468 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8469 | { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8470 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8471 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8472 | struct lpfc_queue *fpeq; |
| 8473 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8474 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8475 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8476 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8477 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8478 | if (piocb->iocb_flag & LPFC_IO_FCP) { |
| 8479 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8480 | return IOCB_ERROR; |
| 8481 | idx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
| 8482 | piocb->fcp_wqidx = idx; |
| 8483 | ring_number = MAX_SLI3_CONFIGURED_RINGS + idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8484 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8485 | pring = &phba->sli.ring[ring_number]; |
| 8486 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8487 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 8488 | flag); |
| 8489 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8490 | |
| 8491 | if (lpfc_fcp_look_ahead) { |
| 8492 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; |
| 8493 | |
| 8494 | if (atomic_dec_and_test(&fcp_eq_hdl-> |
| 8495 | fcp_eq_in_use)) { |
| 8496 | |
| 8497 | /* Get associated EQ with this index */ |
| 8498 | fpeq = phba->sli4_hba.hba_eq[idx]; |
| 8499 | |
| 8500 | /* Turn off interrupts from this EQ */ |
| 8501 | lpfc_sli4_eq_clr_intr(fpeq); |
| 8502 | |
| 8503 | /* |
| 8504 | * Process all the events on FCP EQ |
| 8505 | */ |
| 8506 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 8507 | lpfc_sli4_hba_handle_eqe(phba, |
| 8508 | eqe, idx); |
| 8509 | fpeq->EQ_processed++; |
| 8510 | } |
| 8511 | |
| 8512 | /* Always clear and re-arm the EQ */ |
| 8513 | lpfc_sli4_eq_release(fpeq, |
| 8514 | LPFC_QUEUE_REARM); |
| 8515 | } |
| 8516 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 8517 | } |
| 8518 | } else { |
| 8519 | pring = &phba->sli.ring[ring_number]; |
| 8520 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8521 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 8522 | flag); |
| 8523 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8524 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8525 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8526 | } else { |
| 8527 | /* For now, SLI2/3 will still use hbalock */ |
| 8528 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8529 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8530 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8531 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8532 | return rc; |
| 8533 | } |
| 8534 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8535 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8536 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8537 | * @phba: Pointer to HBA context object. |
| 8538 | * |
| 8539 | * This function is called while driver attaches with the |
| 8540 | * HBA to setup the extra ring. The extra ring is used |
| 8541 | * only when driver needs to support target mode functionality |
| 8542 | * or IP over FC functionalities. |
| 8543 | * |
| 8544 | * This function is called with no lock held. |
| 8545 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8546 | static int |
| 8547 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 8548 | { |
| 8549 | struct lpfc_sli *psli; |
| 8550 | struct lpfc_sli_ring *pring; |
| 8551 | |
| 8552 | psli = &phba->sli; |
| 8553 | |
| 8554 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8555 | |
| 8556 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8557 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8558 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8559 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8560 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8561 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8562 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8563 | /* and give them to the extra ring */ |
| 8564 | pring = &psli->ring[psli->extra_ring]; |
| 8565 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8566 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8567 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8568 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8569 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8570 | |
| 8571 | /* Setup default profile for this ring */ |
| 8572 | pring->iotag_max = 4096; |
| 8573 | pring->num_mask = 1; |
| 8574 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8575 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 8576 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8577 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 8578 | return 0; |
| 8579 | } |
| 8580 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8581 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 8582 | * @phba: Pointer to HBA context object. |
| 8583 | * @iocbq: Pointer to iocb object. |
| 8584 | * |
| 8585 | * The async_event handler calls this routine when it receives |
| 8586 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 8587 | * this event when an Abort Sequence request to an rport fails |
| 8588 | * twice in succession. The abort could be originated by the |
| 8589 | * driver or by the port. The ABTS could have been for an ELS |
| 8590 | * or FCP IO. The port only generates this event when an ABTS |
| 8591 | * fails to complete after one retry. |
| 8592 | */ |
| 8593 | static void |
| 8594 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 8595 | struct lpfc_iocbq *iocbq) |
| 8596 | { |
| 8597 | struct lpfc_nodelist *ndlp = NULL; |
| 8598 | uint16_t rpi = 0, vpi = 0; |
| 8599 | struct lpfc_vport *vport = NULL; |
| 8600 | |
| 8601 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 8602 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 8603 | rpi = iocbq->iocb.ulpContext; |
| 8604 | |
| 8605 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8606 | "3092 Port generated ABTS async event " |
| 8607 | "on vpi %d rpi %d status 0x%x\n", |
| 8608 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 8609 | |
| 8610 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 8611 | if (!vport) |
| 8612 | goto err_exit; |
| 8613 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 8614 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8615 | goto err_exit; |
| 8616 | |
| 8617 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 8618 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8619 | return; |
| 8620 | |
| 8621 | err_exit: |
| 8622 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8623 | "3095 Event Context not found, no " |
| 8624 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 8625 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 8626 | vpi, rpi); |
| 8627 | } |
| 8628 | |
| 8629 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 8630 | * @phba: pointer to HBA context object. |
| 8631 | * @ndlp: nodelist pointer for the impacted rport. |
| 8632 | * @axri: pointer to the wcqe containing the failed exchange. |
| 8633 | * |
| 8634 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 8635 | * port. The port generates this event when an abort exchange request to an |
| 8636 | * rport fails twice in succession with no reply. The abort could be originated |
| 8637 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 8638 | */ |
| 8639 | void |
| 8640 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 8641 | struct lpfc_nodelist *ndlp, |
| 8642 | struct sli4_wcqe_xri_aborted *axri) |
| 8643 | { |
| 8644 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8645 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8646 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8647 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8648 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8649 | "3115 Node Context not found, driver " |
| 8650 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8651 | return; |
| 8652 | } |
| 8653 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8654 | vport = ndlp->vport; |
| 8655 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8656 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8657 | "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] | 8658 | ndlp->vport->vpi, ndlp->nlp_rpi, |
| 8659 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8660 | bf_get(lpfc_wcqe_xa_status, axri), |
| 8661 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8662 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8663 | /* |
| 8664 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 8665 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 8666 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 8667 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 8668 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8669 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 8670 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8671 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8672 | } |
| 8673 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8674 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8675 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8676 | * @phba: Pointer to HBA context object. |
| 8677 | * @pring: Pointer to driver SLI ring object. |
| 8678 | * @iocbq: Pointer to iocb object. |
| 8679 | * |
| 8680 | * This function is called by the slow ring event handler |
| 8681 | * function when there is an ASYNC event iocb in the ring. |
| 8682 | * This function is called with no lock held. |
| 8683 | * Currently this function handles only temperature related |
| 8684 | * ASYNC events. The function decodes the temperature sensor |
| 8685 | * event message and posts events for the management applications. |
| 8686 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8687 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8688 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 8689 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 8690 | { |
| 8691 | IOCB_t *icmd; |
| 8692 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8693 | struct temp_event temp_event_data; |
| 8694 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8695 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8696 | |
| 8697 | icmd = &iocbq->iocb; |
| 8698 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8699 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8700 | switch (evt_code) { |
| 8701 | case ASYNC_TEMP_WARN: |
| 8702 | case ASYNC_TEMP_SAFE: |
| 8703 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 8704 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 8705 | if (evt_code == ASYNC_TEMP_WARN) { |
| 8706 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 8707 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8708 | "0347 Adapter is very hot, please take " |
| 8709 | "corrective action. temperature : %d Celsius\n", |
| 8710 | (uint32_t) icmd->ulpContext); |
| 8711 | } else { |
| 8712 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 8713 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8714 | "0340 Adapter temperature is OK now. " |
| 8715 | "temperature : %d Celsius\n", |
| 8716 | (uint32_t) icmd->ulpContext); |
| 8717 | } |
| 8718 | |
| 8719 | /* Send temperature change event to applications */ |
| 8720 | shost = lpfc_shost_from_vport(phba->pport); |
| 8721 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 8722 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 8723 | LPFC_NL_VENDOR_ID); |
| 8724 | break; |
| 8725 | case ASYNC_STATUS_CN: |
| 8726 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 8727 | break; |
| 8728 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8729 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8730 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8731 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 8732 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8733 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 8734 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 8735 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 8736 | "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] | 8737 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8738 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 8739 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 8740 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 8741 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 8742 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8743 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8744 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8745 | } |
| 8746 | |
| 8747 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8748 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8749 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8750 | * @phba: Pointer to HBA context object. |
| 8751 | * |
| 8752 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 8753 | * number of iocbs per ring and iotags. This function is |
| 8754 | * called while driver attach to the HBA and before the |
| 8755 | * interrupts are enabled. So there is no need for locking. |
| 8756 | * |
| 8757 | * This function always returns 0. |
| 8758 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8759 | int |
| 8760 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 8761 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8762 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8763 | struct lpfc_sli *psli = &phba->sli; |
| 8764 | struct lpfc_sli_ring *pring; |
| 8765 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8766 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| 8767 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8768 | psli->num_rings += phba->cfg_fcp_io_channel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8769 | psli->sli_flag = 0; |
| 8770 | psli->fcp_ring = LPFC_FCP_RING; |
| 8771 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8772 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8773 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8774 | psli->iocbq_lookup = NULL; |
| 8775 | psli->iocbq_lookup_len = 0; |
| 8776 | psli->last_iotag = 0; |
| 8777 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8778 | for (i = 0; i < psli->num_rings; i++) { |
| 8779 | pring = &psli->ring[i]; |
| 8780 | switch (i) { |
| 8781 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 8782 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8783 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 8784 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 8785 | pring->sli.sli3.numCiocb += |
| 8786 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8787 | pring->sli.sli3.numRiocb += |
| 8788 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8789 | pring->sli.sli3.numCiocb += |
| 8790 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8791 | pring->sli.sli3.numRiocb += |
| 8792 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8793 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8794 | SLI3_IOCB_CMD_SIZE : |
| 8795 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8796 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8797 | SLI3_IOCB_RSP_SIZE : |
| 8798 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8799 | pring->iotag_ctr = 0; |
| 8800 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8801 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8802 | pring->fast_iotag = pring->iotag_max; |
| 8803 | pring->num_mask = 0; |
| 8804 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8805 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8806 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8807 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 8808 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 8809 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8810 | SLI3_IOCB_CMD_SIZE : |
| 8811 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8812 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8813 | SLI3_IOCB_RSP_SIZE : |
| 8814 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8815 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8816 | pring->num_mask = 0; |
| 8817 | break; |
| 8818 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 8819 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8820 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 8821 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 8822 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8823 | SLI3_IOCB_CMD_SIZE : |
| 8824 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8825 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8826 | SLI3_IOCB_RSP_SIZE : |
| 8827 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8828 | pring->fast_iotag = 0; |
| 8829 | pring->iotag_ctr = 0; |
| 8830 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8831 | pring->lpfc_sli_rcv_async_status = |
| 8832 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8833 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8834 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8835 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 8836 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8837 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8838 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8839 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8840 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 8841 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8842 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8843 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8844 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 8845 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8846 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8847 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8848 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8849 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8850 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8851 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 8852 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8853 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8854 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8855 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8856 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8857 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8858 | break; |
| 8859 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8860 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 8861 | pring->sli.sli3.sizeCiocb) + |
| 8862 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8863 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8864 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8865 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8866 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 8867 | "SLI2 SLIM Data: x%x x%lx\n", |
| 8868 | phba->brd_no, totiocbsize, |
| 8869 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8870 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8871 | if (phba->cfg_multi_ring_support == 2) |
| 8872 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8873 | |
| 8874 | return 0; |
| 8875 | } |
| 8876 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8877 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8878 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8879 | * @phba: Pointer to HBA context object. |
| 8880 | * |
| 8881 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 8882 | * ring. This function also initializes ring indices of each ring. |
| 8883 | * This function is called during the initialization of the SLI |
| 8884 | * interface of an HBA. |
| 8885 | * This function is called with no lock held and always returns |
| 8886 | * 1. |
| 8887 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8888 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8889 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8890 | { |
| 8891 | struct lpfc_sli *psli; |
| 8892 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8893 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8894 | |
| 8895 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8896 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8897 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8898 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8899 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 8900 | for (i = 0; i < psli->num_rings; i++) { |
| 8901 | pring = &psli->ring[i]; |
| 8902 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8903 | pring->sli.sli3.next_cmdidx = 0; |
| 8904 | pring->sli.sli3.local_getidx = 0; |
| 8905 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8906 | INIT_LIST_HEAD(&pring->txq); |
| 8907 | INIT_LIST_HEAD(&pring->txcmplq); |
| 8908 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 8909 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8910 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8911 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8912 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8913 | spin_unlock_irq(&phba->hbalock); |
| 8914 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8915 | } |
| 8916 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8917 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8918 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 8919 | * @phba: Pointer to HBA context object. |
| 8920 | * |
| 8921 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 8922 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 8923 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 8924 | * command; and completed mailbox command queue. It is caller's responsibility |
| 8925 | * to make sure that the driver is in the proper state to flush the mailbox |
| 8926 | * command sub-system. Namely, the posting of mailbox commands into the |
| 8927 | * pending mailbox command queue from the various clients must be stopped; |
| 8928 | * either the HBA is in a state that it will never works on the outstanding |
| 8929 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 8930 | * mailbox command has been completed. |
| 8931 | **/ |
| 8932 | static void |
| 8933 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 8934 | { |
| 8935 | LIST_HEAD(completions); |
| 8936 | struct lpfc_sli *psli = &phba->sli; |
| 8937 | LPFC_MBOXQ_t *pmb; |
| 8938 | unsigned long iflag; |
| 8939 | |
| 8940 | /* Flush all the mailbox commands in the mbox system */ |
| 8941 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8942 | /* The pending mailbox command queue */ |
| 8943 | list_splice_init(&phba->sli.mboxq, &completions); |
| 8944 | /* The outstanding active mailbox command */ |
| 8945 | if (psli->mbox_active) { |
| 8946 | list_add_tail(&psli->mbox_active->list, &completions); |
| 8947 | psli->mbox_active = NULL; |
| 8948 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8949 | } |
| 8950 | /* The completed mailbox command queue */ |
| 8951 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 8952 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8953 | |
| 8954 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 8955 | while (!list_empty(&completions)) { |
| 8956 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 8957 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8958 | if (pmb->mbox_cmpl) |
| 8959 | pmb->mbox_cmpl(phba, pmb); |
| 8960 | } |
| 8961 | } |
| 8962 | |
| 8963 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8964 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8965 | * @vport: Pointer to virtual port object. |
| 8966 | * |
| 8967 | * lpfc_sli_host_down is called to clean up the resources |
| 8968 | * associated with a vport before destroying virtual |
| 8969 | * port data structures. |
| 8970 | * This function does following operations: |
| 8971 | * - Free discovery resources associated with this virtual |
| 8972 | * port. |
| 8973 | * - Free iocbs associated with this virtual port in |
| 8974 | * the txq. |
| 8975 | * - Send abort for all iocb commands associated with this |
| 8976 | * vport in txcmplq. |
| 8977 | * |
| 8978 | * This function is called with no lock held and always returns 1. |
| 8979 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8980 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8981 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 8982 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8983 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8984 | struct lpfc_hba *phba = vport->phba; |
| 8985 | struct lpfc_sli *psli = &phba->sli; |
| 8986 | struct lpfc_sli_ring *pring; |
| 8987 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8988 | int i; |
| 8989 | unsigned long flags = 0; |
| 8990 | uint16_t prev_pring_flag; |
| 8991 | |
| 8992 | lpfc_cleanup_discovery_resources(vport); |
| 8993 | |
| 8994 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8995 | for (i = 0; i < psli->num_rings; i++) { |
| 8996 | pring = &psli->ring[i]; |
| 8997 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8998 | /* Only slow rings */ |
| 8999 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9000 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9001 | /* Set the lpfc data pending flag */ |
| 9002 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9003 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9004 | /* |
| 9005 | * Error everything on the txq since these iocbs have not been |
| 9006 | * given to the FW yet. |
| 9007 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9008 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 9009 | if (iocb->vport != vport) |
| 9010 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9011 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9012 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9013 | } |
| 9014 | |
| 9015 | /* Next issue ABTS for everything on the txcmplq */ |
| 9016 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 9017 | list) { |
| 9018 | if (iocb->vport != vport) |
| 9019 | continue; |
| 9020 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 9021 | } |
| 9022 | |
| 9023 | pring->flag = prev_pring_flag; |
| 9024 | } |
| 9025 | |
| 9026 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9027 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9028 | /* Cancel all the IOCBs from the completions list */ |
| 9029 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9030 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9031 | return 1; |
| 9032 | } |
| 9033 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9034 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9035 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9036 | * @phba: Pointer to HBA context object. |
| 9037 | * |
| 9038 | * This function cleans up all iocb, buffers, mailbox commands |
| 9039 | * while shutting down the HBA. This function is called with no |
| 9040 | * lock held and always returns 1. |
| 9041 | * This function does the following to cleanup driver resources: |
| 9042 | * - Free discovery resources for each virtual port |
| 9043 | * - Cleanup any pending fabric iocbs |
| 9044 | * - Iterate through the iocb txq and free each entry |
| 9045 | * in the list. |
| 9046 | * - Free up any buffer posted to the HBA |
| 9047 | * - Free mailbox commands in the mailbox queue. |
| 9048 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9049 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9050 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9051 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9052 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9053 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9054 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9055 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9056 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9057 | int i; |
| 9058 | |
| 9059 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9060 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9062 | lpfc_hba_down_prep(phba); |
| 9063 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9064 | lpfc_fabric_abort_hba(phba); |
| 9065 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9066 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9067 | for (i = 0; i < psli->num_rings; i++) { |
| 9068 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9069 | /* Only slow rings */ |
| 9070 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9071 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9072 | /* Set the lpfc data pending flag */ |
| 9073 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9074 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9075 | |
| 9076 | /* |
| 9077 | * Error everything on the txq since these iocbs have not been |
| 9078 | * given to the FW yet. |
| 9079 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9080 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9081 | pring->txq_cnt = 0; |
| 9082 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9083 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9084 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9085 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9086 | /* Cancel all the IOCBs from the completions list */ |
| 9087 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9088 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9089 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9090 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9091 | list_splice_init(&phba->elsbuf, &completions); |
| 9092 | phba->elsbuf_cnt = 0; |
| 9093 | phba->elsbuf_prev_cnt = 0; |
| 9094 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9095 | |
| 9096 | while (!list_empty(&completions)) { |
| 9097 | list_remove_head(&completions, buf_ptr, |
| 9098 | struct lpfc_dmabuf, list); |
| 9099 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9100 | kfree(buf_ptr); |
| 9101 | } |
| 9102 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9103 | /* Return any active mbox cmds */ |
| 9104 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9105 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9106 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9107 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9108 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9109 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9110 | return 1; |
| 9111 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9112 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9113 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9114 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9115 | * @srcp: Source memory pointer. |
| 9116 | * @destp: Destination memory pointer. |
| 9117 | * @cnt: Number of words required to be copied. |
| 9118 | * |
| 9119 | * This function is used for copying data between driver memory |
| 9120 | * and the SLI memory. This function also changes the endianness |
| 9121 | * of each word if native endianness is different from SLI |
| 9122 | * endianness. This function can be called with or without |
| 9123 | * lock. |
| 9124 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9125 | void |
| 9126 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9127 | { |
| 9128 | uint32_t *src = srcp; |
| 9129 | uint32_t *dest = destp; |
| 9130 | uint32_t ldata; |
| 9131 | int i; |
| 9132 | |
| 9133 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9134 | ldata = *src; |
| 9135 | ldata = le32_to_cpu(ldata); |
| 9136 | *dest = ldata; |
| 9137 | src++; |
| 9138 | dest++; |
| 9139 | } |
| 9140 | } |
| 9141 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9142 | |
| 9143 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9144 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9145 | * @srcp: Source memory pointer. |
| 9146 | * @destp: Destination memory pointer. |
| 9147 | * @cnt: Number of words required to be copied. |
| 9148 | * |
| 9149 | * This function is used for copying data between a data structure |
| 9150 | * with big endian representation to local endianness. |
| 9151 | * This function can be called with or without lock. |
| 9152 | **/ |
| 9153 | void |
| 9154 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9155 | { |
| 9156 | uint32_t *src = srcp; |
| 9157 | uint32_t *dest = destp; |
| 9158 | uint32_t ldata; |
| 9159 | int i; |
| 9160 | |
| 9161 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9162 | ldata = *src; |
| 9163 | ldata = be32_to_cpu(ldata); |
| 9164 | *dest = ldata; |
| 9165 | src++; |
| 9166 | dest++; |
| 9167 | } |
| 9168 | } |
| 9169 | |
| 9170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9171 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9172 | * @phba: Pointer to HBA context object. |
| 9173 | * @pring: Pointer to driver SLI ring object. |
| 9174 | * @mp: Pointer to driver buffer object. |
| 9175 | * |
| 9176 | * This function is called with no lock held. |
| 9177 | * It always return zero after adding the buffer to the postbufq |
| 9178 | * buffer list. |
| 9179 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9180 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9181 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9182 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9183 | { |
| 9184 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9185 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9186 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9187 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9188 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9189 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9190 | return 0; |
| 9191 | } |
| 9192 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9193 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9194 | * 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] | 9195 | * @phba: Pointer to HBA context object. |
| 9196 | * |
| 9197 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9198 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9199 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9200 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9201 | * The function returns the allocated tag. The function is called with |
| 9202 | * no locks held. |
| 9203 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9204 | uint32_t |
| 9205 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9206 | { |
| 9207 | spin_lock_irq(&phba->hbalock); |
| 9208 | phba->buffer_tag_count++; |
| 9209 | /* |
| 9210 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9211 | * a tag assigned by HBQ. |
| 9212 | */ |
| 9213 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9214 | spin_unlock_irq(&phba->hbalock); |
| 9215 | return phba->buffer_tag_count; |
| 9216 | } |
| 9217 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9218 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9219 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9220 | * @phba: Pointer to HBA context object. |
| 9221 | * @pring: Pointer to driver SLI ring object. |
| 9222 | * @tag: Buffer tag. |
| 9223 | * |
| 9224 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9225 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9226 | * iocb is posted to the response ring with the tag of the buffer. |
| 9227 | * This function searches the pring->postbufq list using the tag |
| 9228 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9229 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9230 | * buffer is returned to the caller else NULL is returned. |
| 9231 | * This function is called with no lock held. |
| 9232 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9233 | struct lpfc_dmabuf * |
| 9234 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9235 | uint32_t tag) |
| 9236 | { |
| 9237 | struct lpfc_dmabuf *mp, *next_mp; |
| 9238 | struct list_head *slp = &pring->postbufq; |
| 9239 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9240 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9241 | spin_lock_irq(&phba->hbalock); |
| 9242 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9243 | if (mp->buffer_tag == tag) { |
| 9244 | list_del_init(&mp->list); |
| 9245 | pring->postbufq_cnt--; |
| 9246 | spin_unlock_irq(&phba->hbalock); |
| 9247 | return mp; |
| 9248 | } |
| 9249 | } |
| 9250 | |
| 9251 | spin_unlock_irq(&phba->hbalock); |
| 9252 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9253 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9254 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9255 | pring->ringno, (unsigned long) tag, |
| 9256 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9257 | |
| 9258 | return NULL; |
| 9259 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9261 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9262 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9263 | * @phba: Pointer to HBA context object. |
| 9264 | * @pring: Pointer to driver SLI ring object. |
| 9265 | * @phys: DMA address of the buffer. |
| 9266 | * |
| 9267 | * This function searches the buffer list using the dma_address |
| 9268 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9269 | * corresponding to the dma_address. The function returns the |
| 9270 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9271 | * This function is called by the ct and els unsolicited event |
| 9272 | * handlers to get the buffer associated with the unsolicited |
| 9273 | * event. |
| 9274 | * |
| 9275 | * This function is called with no lock held. |
| 9276 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9277 | struct lpfc_dmabuf * |
| 9278 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9279 | dma_addr_t phys) |
| 9280 | { |
| 9281 | struct lpfc_dmabuf *mp, *next_mp; |
| 9282 | struct list_head *slp = &pring->postbufq; |
| 9283 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9284 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9285 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9286 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9287 | if (mp->phys == phys) { |
| 9288 | list_del_init(&mp->list); |
| 9289 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9290 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9291 | return mp; |
| 9292 | } |
| 9293 | } |
| 9294 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9295 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9296 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9297 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9298 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9299 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9300 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9301 | return NULL; |
| 9302 | } |
| 9303 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9304 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9305 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9306 | * @phba: Pointer to HBA context object. |
| 9307 | * @cmdiocb: Pointer to driver command iocb object. |
| 9308 | * @rspiocb: Pointer to driver response iocb object. |
| 9309 | * |
| 9310 | * This function is the completion handler for the abort iocbs for |
| 9311 | * ELS commands. This function is called from the ELS ring event |
| 9312 | * handler with no lock held. This function frees memory resources |
| 9313 | * associated with the abort iocb. |
| 9314 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9315 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9316 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9317 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9318 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9319 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9320 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9321 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9322 | |
| 9323 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9324 | |
| 9325 | /* |
| 9326 | * Assume that the port already completed and returned, or |
| 9327 | * will return the iocb. Just Log the message. |
| 9328 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9329 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9330 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9331 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9332 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9333 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9334 | if (abort_iotag != 0 && |
| 9335 | abort_iotag <= phba->sli.last_iotag) |
| 9336 | abort_iocb = |
| 9337 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9338 | } else |
| 9339 | /* For sli4 the abort_tag is the XRI, |
| 9340 | * so the abort routine puts the iotag of the iocb |
| 9341 | * being aborted in the context field of the abort |
| 9342 | * IOCB. |
| 9343 | */ |
| 9344 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9345 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9346 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9347 | "0327 Cannot abort els iocb %p " |
| 9348 | "with tag %x context %x, abort status %x, " |
| 9349 | "abort code %x\n", |
| 9350 | abort_iocb, abort_iotag, abort_context, |
| 9351 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9352 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9353 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9354 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9355 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9356 | return; |
| 9357 | } |
| 9358 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9359 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9360 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9361 | * @phba: Pointer to HBA context object. |
| 9362 | * @cmdiocb: Pointer to driver command iocb object. |
| 9363 | * @rspiocb: Pointer to driver response iocb object. |
| 9364 | * |
| 9365 | * The function is called from SLI ring event handler with no |
| 9366 | * lock held. This function is the completion handler for ELS commands |
| 9367 | * which are aborted. The function frees memory resources used for |
| 9368 | * the aborted ELS commands. |
| 9369 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9370 | static void |
| 9371 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9372 | struct lpfc_iocbq *rspiocb) |
| 9373 | { |
| 9374 | IOCB_t *irsp = &rspiocb->iocb; |
| 9375 | |
| 9376 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9377 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9378 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9379 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9380 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9381 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9382 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9383 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9384 | else |
| 9385 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9386 | return; |
| 9387 | } |
| 9388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9389 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9390 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9391 | * @phba: Pointer to HBA context object. |
| 9392 | * @pring: Pointer to driver SLI ring object. |
| 9393 | * @cmdiocb: Pointer to driver command iocb object. |
| 9394 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9395 | * This function issues an abort iocb for the provided command iocb down to |
| 9396 | * the port. Other than the case the outstanding command iocb is an abort |
| 9397 | * request, this function issues abort out unconditionally. This function is |
| 9398 | * called with hbalock held. The function returns 0 when it fails due to |
| 9399 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9400 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9401 | static int |
| 9402 | 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] | 9403 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9404 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9405 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9406 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9407 | IOCB_t *icmd = NULL; |
| 9408 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9409 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9410 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9411 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9412 | /* |
| 9413 | * There are certain command types we don't want to abort. And we |
| 9414 | * don't want to abort commands that are already in the process of |
| 9415 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9416 | */ |
| 9417 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9418 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9419 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9420 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9421 | return 0; |
| 9422 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9423 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9424 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9425 | if (abtsiocbp == NULL) |
| 9426 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9427 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9428 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9429 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9430 | */ |
| 9431 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9432 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9433 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9434 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9435 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9436 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9437 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9438 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9439 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9440 | else |
| 9441 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9442 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9443 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9444 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9445 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9446 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9447 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9448 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9449 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9450 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9451 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9452 | else |
| 9453 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9454 | |
| 9455 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9456 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9457 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9458 | "0339 Abort xri x%x, original iotag x%x, " |
| 9459 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9460 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9461 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9462 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9463 | |
| 9464 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9465 | /* Note: both hbalock and ring_lock need to be set here */ |
| 9466 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9467 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9468 | abtsiocbp, 0); |
| 9469 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 9470 | } else { |
| 9471 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9472 | abtsiocbp, 0); |
| 9473 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9474 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9475 | if (retval) |
| 9476 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9477 | |
| 9478 | /* |
| 9479 | * Caller to this routine should check for IOCB_ERROR |
| 9480 | * and handle it properly. This routine no longer removes |
| 9481 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9482 | */ |
| 9483 | return retval; |
| 9484 | } |
| 9485 | |
| 9486 | /** |
| 9487 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9488 | * @phba: Pointer to HBA context object. |
| 9489 | * @pring: Pointer to driver SLI ring object. |
| 9490 | * @cmdiocb: Pointer to driver command iocb object. |
| 9491 | * |
| 9492 | * This function issues an abort iocb for the provided command iocb. In case |
| 9493 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9494 | * ring. Instead, the callback function shall be changed to those commands |
| 9495 | * so that nothing happens when them finishes. This function is called with |
| 9496 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9497 | * request. |
| 9498 | **/ |
| 9499 | int |
| 9500 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9501 | struct lpfc_iocbq *cmdiocb) |
| 9502 | { |
| 9503 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9504 | int retval = IOCB_ERROR; |
| 9505 | IOCB_t *icmd = NULL; |
| 9506 | |
| 9507 | /* |
| 9508 | * There are certain command types we don't want to abort. And we |
| 9509 | * don't want to abort commands that are already in the process of |
| 9510 | * being aborted. |
| 9511 | */ |
| 9512 | icmd = &cmdiocb->iocb; |
| 9513 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 9514 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9515 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 9516 | return 0; |
| 9517 | |
| 9518 | /* |
| 9519 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 9520 | * the callback so that nothing happens when it finishes. |
| 9521 | */ |
| 9522 | if ((vport->load_flag & FC_UNLOADING) && |
| 9523 | (pring->ringno == LPFC_ELS_RING)) { |
| 9524 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 9525 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9526 | else |
| 9527 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9528 | goto abort_iotag_exit; |
| 9529 | } |
| 9530 | |
| 9531 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 9532 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 9533 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9534 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9535 | /* |
| 9536 | * Caller to this routine should check for IOCB_ERROR |
| 9537 | * and handle it properly. This routine no longer removes |
| 9538 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9539 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9540 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9541 | } |
| 9542 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9543 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9544 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring |
| 9545 | * @phba: Pointer to HBA context object. |
| 9546 | * @pring: Pointer to driver SLI ring object. |
| 9547 | * |
| 9548 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 9549 | * objects in txq. This function issues abort iocbs unconditionally for all |
| 9550 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed |
| 9551 | * to complete before the return of this function. The caller is not required |
| 9552 | * to hold any locks. |
| 9553 | **/ |
| 9554 | static void |
| 9555 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 9556 | { |
| 9557 | LIST_HEAD(completions); |
| 9558 | struct lpfc_iocbq *iocb, *next_iocb; |
| 9559 | |
| 9560 | if (pring->ringno == LPFC_ELS_RING) |
| 9561 | lpfc_fabric_abort_hba(phba); |
| 9562 | |
| 9563 | spin_lock_irq(&phba->hbalock); |
| 9564 | |
| 9565 | /* Take off all the iocbs on txq for cancelling */ |
| 9566 | list_splice_init(&pring->txq, &completions); |
| 9567 | pring->txq_cnt = 0; |
| 9568 | |
| 9569 | /* Next issue ABTS for everything on the txcmplq */ |
| 9570 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 9571 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); |
| 9572 | |
| 9573 | spin_unlock_irq(&phba->hbalock); |
| 9574 | |
| 9575 | /* Cancel all the IOCBs from the completions list */ |
| 9576 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9577 | IOERR_SLI_ABORTED); |
| 9578 | } |
| 9579 | |
| 9580 | /** |
| 9581 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 9582 | * @phba: pointer to lpfc HBA data structure. |
| 9583 | * |
| 9584 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 9585 | **/ |
| 9586 | void |
| 9587 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 9588 | { |
| 9589 | struct lpfc_sli *psli = &phba->sli; |
| 9590 | struct lpfc_sli_ring *pring; |
| 9591 | int i; |
| 9592 | |
| 9593 | for (i = 0; i < psli->num_rings; i++) { |
| 9594 | pring = &psli->ring[i]; |
| 9595 | lpfc_sli_iocb_ring_abort(phba, pring); |
| 9596 | } |
| 9597 | } |
| 9598 | |
| 9599 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9600 | * 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] | 9601 | * @iocbq: Pointer to driver iocb object. |
| 9602 | * @vport: Pointer to driver virtual port object. |
| 9603 | * @tgt_id: SCSI ID of the target. |
| 9604 | * @lun_id: LUN ID of the scsi device. |
| 9605 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 9606 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9607 | * 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] | 9608 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 9609 | * 0 if the filtering criteria is met for the given iocb and will return |
| 9610 | * 1 if the filtering criteria is not met. |
| 9611 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 9612 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 9613 | * lun_id parameter. |
| 9614 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 9615 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 9616 | * parameters. |
| 9617 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 9618 | * given iocb is for the SCSI host associated with the given vport. |
| 9619 | * This function is called with no locks held. |
| 9620 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9621 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9622 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 9623 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9624 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9625 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9626 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9627 | int rc = 1; |
| 9628 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9629 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 9630 | return rc; |
| 9631 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9632 | if (iocbq->vport != vport) |
| 9633 | return rc; |
| 9634 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9635 | 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] | 9636 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9637 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9638 | return rc; |
| 9639 | |
| 9640 | switch (ctx_cmd) { |
| 9641 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9642 | if ((lpfc_cmd->rdata->pnode) && |
| 9643 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 9644 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9645 | rc = 0; |
| 9646 | break; |
| 9647 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9648 | if ((lpfc_cmd->rdata->pnode) && |
| 9649 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9650 | rc = 0; |
| 9651 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9652 | case LPFC_CTX_HOST: |
| 9653 | rc = 0; |
| 9654 | break; |
| 9655 | default: |
| 9656 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 9657 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9658 | break; |
| 9659 | } |
| 9660 | |
| 9661 | return rc; |
| 9662 | } |
| 9663 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9664 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9665 | * 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] | 9666 | * @vport: Pointer to virtual port. |
| 9667 | * @tgt_id: SCSI ID of the target. |
| 9668 | * @lun_id: LUN ID of the scsi device. |
| 9669 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9670 | * |
| 9671 | * This function returns number of FCP commands pending for the vport. |
| 9672 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 9673 | * commands pending on the vport associated with SCSI device specified |
| 9674 | * by tgt_id and lun_id parameters. |
| 9675 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 9676 | * commands pending on the vport associated with SCSI target specified |
| 9677 | * by tgt_id parameter. |
| 9678 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 9679 | * commands pending on the vport. |
| 9680 | * This function returns the number of iocbs which satisfy the filter. |
| 9681 | * This function is called without any lock held. |
| 9682 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9683 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9684 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 9685 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9686 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9687 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9688 | struct lpfc_iocbq *iocbq; |
| 9689 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9690 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9691 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 9692 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9693 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9694 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 9695 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9696 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9697 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9698 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9699 | return sum; |
| 9700 | } |
| 9701 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9702 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9703 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9704 | * @phba: Pointer to HBA context object |
| 9705 | * @cmdiocb: Pointer to command iocb object. |
| 9706 | * @rspiocb: Pointer to response iocb object. |
| 9707 | * |
| 9708 | * This function is called when an aborted FCP iocb completes. This |
| 9709 | * function is called by the ring event handler with no lock held. |
| 9710 | * This function frees the iocb. |
| 9711 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9712 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9713 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9714 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9715 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9716 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9717 | "3096 ABORT_XRI_CN completing on xri x%x " |
| 9718 | "original iotag x%x, abort cmd iotag x%x " |
| 9719 | "status 0x%x, reason 0x%x\n", |
| 9720 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 9721 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 9722 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 9723 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9724 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9725 | return; |
| 9726 | } |
| 9727 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9728 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9729 | * 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] | 9730 | * @vport: Pointer to virtual port. |
| 9731 | * @pring: Pointer to driver SLI ring object. |
| 9732 | * @tgt_id: SCSI ID of the target. |
| 9733 | * @lun_id: LUN ID of the scsi device. |
| 9734 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9735 | * |
| 9736 | * This function sends an abort command for every SCSI command |
| 9737 | * associated with the given virtual port pending on the ring |
| 9738 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 9739 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 9740 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 9741 | * parameters |
| 9742 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 9743 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 9744 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 9745 | * FCP iocbs associated with virtual port. |
| 9746 | * This function returns number of iocbs it failed to abort. |
| 9747 | * This function is called with no locks held. |
| 9748 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9749 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9750 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 9751 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9752 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9753 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9754 | struct lpfc_iocbq *iocbq; |
| 9755 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9756 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9757 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9758 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9759 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9760 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 9761 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9762 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9763 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9764 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9765 | continue; |
| 9766 | |
| 9767 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9768 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9769 | if (abtsiocb == NULL) { |
| 9770 | errcnt++; |
| 9771 | continue; |
| 9772 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9773 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9774 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9775 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9776 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9777 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9778 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 9779 | else |
| 9780 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9781 | abtsiocb->iocb.ulpLe = 1; |
| 9782 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9783 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9784 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9785 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9786 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9787 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 9788 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9789 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9790 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9791 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 9792 | else |
| 9793 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 9794 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9795 | /* Setup callback routine and issue the command. */ |
| 9796 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9797 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9798 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9799 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9800 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9801 | errcnt++; |
| 9802 | continue; |
| 9803 | } |
| 9804 | } |
| 9805 | |
| 9806 | return errcnt; |
| 9807 | } |
| 9808 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9809 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9810 | * 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] | 9811 | * @phba: Pointer to HBA context object. |
| 9812 | * @cmdiocbq: Pointer to command iocb. |
| 9813 | * @rspiocbq: Pointer to response iocb. |
| 9814 | * |
| 9815 | * This function is the completion handler for iocbs issued using |
| 9816 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 9817 | * ring event handler function without any lock held. This function |
| 9818 | * can be called from both worker thread context and interrupt |
| 9819 | * context. This function also can be called from other thread which |
| 9820 | * cleans up the SLI layer objects. |
| 9821 | * This function copy the contents of the response iocb to the |
| 9822 | * response iocb memory object provided by the caller of |
| 9823 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 9824 | * sleeps for the iocb completion. |
| 9825 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9826 | static void |
| 9827 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 9828 | struct lpfc_iocbq *cmdiocbq, |
| 9829 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9830 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9831 | wait_queue_head_t *pdone_q; |
| 9832 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9833 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9835 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9836 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 9837 | if (cmdiocbq->context2 && rspiocbq) |
| 9838 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 9839 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 9840 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9841 | /* Set the exchange busy flag for task management commands */ |
| 9842 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 9843 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 9844 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 9845 | cur_iocbq); |
| 9846 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 9847 | } |
| 9848 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9849 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9850 | if (pdone_q) |
| 9851 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9852 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9853 | return; |
| 9854 | } |
| 9855 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9856 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9857 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 9858 | * @phba: Pointer to HBA context object.. |
| 9859 | * @piocbq: Pointer to command iocb. |
| 9860 | * @flag: Flag to test. |
| 9861 | * |
| 9862 | * This routine grabs the hbalock and then test the iocb_flag to |
| 9863 | * see if the passed in flag is set. |
| 9864 | * Returns: |
| 9865 | * 1 if flag is set. |
| 9866 | * 0 if flag is not set. |
| 9867 | **/ |
| 9868 | static int |
| 9869 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 9870 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 9871 | { |
| 9872 | unsigned long iflags; |
| 9873 | int ret; |
| 9874 | |
| 9875 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9876 | ret = piocbq->iocb_flag & flag; |
| 9877 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9878 | return ret; |
| 9879 | |
| 9880 | } |
| 9881 | |
| 9882 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9883 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9884 | * @phba: Pointer to HBA context object.. |
| 9885 | * @pring: Pointer to sli ring. |
| 9886 | * @piocb: Pointer to command iocb. |
| 9887 | * @prspiocbq: Pointer to response iocb. |
| 9888 | * @timeout: Timeout in number of seconds. |
| 9889 | * |
| 9890 | * This function issues the iocb to firmware and waits for the |
| 9891 | * iocb to complete. If the iocb command is not |
| 9892 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 9893 | * Caller should not free the iocb resources if this function |
| 9894 | * returns IOCB_TIMEDOUT. |
| 9895 | * The function waits for the iocb completion using an |
| 9896 | * non-interruptible wait. |
| 9897 | * This function will sleep while waiting for iocb completion. |
| 9898 | * So, this function should not be called from any context which |
| 9899 | * does not allow sleeping. Due to the same reason, this function |
| 9900 | * cannot be called with interrupt disabled. |
| 9901 | * This function assumes that the iocb completions occur while |
| 9902 | * this function sleep. So, this function cannot be called from |
| 9903 | * the thread which process iocb completion for this ring. |
| 9904 | * This function clears the iocb_flag of the iocb object before |
| 9905 | * issuing the iocb and the iocb completion handler sets this |
| 9906 | * flag and wakes this thread when the iocb completes. |
| 9907 | * The contents of the response iocb will be copied to prspiocbq |
| 9908 | * by the completion handler when the command completes. |
| 9909 | * This function returns IOCB_SUCCESS when success. |
| 9910 | * This function is called with no lock held. |
| 9911 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9912 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9913 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9914 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9915 | struct lpfc_iocbq *piocb, |
| 9916 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9917 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9918 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9919 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9920 | long timeleft, timeout_req = 0; |
| 9921 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9922 | uint32_t creg_val; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9923 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9924 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9925 | * If the caller has provided a response iocbq buffer, then context2 |
| 9926 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9927 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9928 | if (prspiocbq) { |
| 9929 | if (piocb->context2) |
| 9930 | return IOCB_ERROR; |
| 9931 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9932 | } |
| 9933 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9934 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 9935 | piocb->context_un.wait_queue = &done_q; |
| 9936 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9937 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9938 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9939 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9940 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9941 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 9942 | writel(creg_val, phba->HCregaddr); |
| 9943 | readl(phba->HCregaddr); /* flush */ |
| 9944 | } |
| 9945 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9946 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 9947 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9948 | if (retval == IOCB_SUCCESS) { |
| 9949 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9950 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9951 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9952 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9953 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9954 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 9955 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9956 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9957 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9958 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9959 | "0338 IOCB wait timeout error - no " |
| 9960 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9961 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9962 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9963 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9964 | "0330 IOCB wake NOT set, " |
| 9965 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9966 | timeout, (timeleft / jiffies)); |
| 9967 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9968 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9969 | } else if (retval == IOCB_BUSY) { |
| 9970 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9971 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 9972 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); |
| 9973 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9974 | } else { |
| 9975 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9976 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9977 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9978 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9979 | } |
| 9980 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9981 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9982 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9983 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9984 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 9985 | writel(creg_val, phba->HCregaddr); |
| 9986 | readl(phba->HCregaddr); /* flush */ |
| 9987 | } |
| 9988 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9989 | if (prspiocbq) |
| 9990 | piocb->context2 = NULL; |
| 9991 | |
| 9992 | piocb->context_un.wait_queue = NULL; |
| 9993 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9994 | return retval; |
| 9995 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9996 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9997 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9998 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9999 | * @phba: Pointer to HBA context object. |
| 10000 | * @pmboxq: Pointer to driver mailbox object. |
| 10001 | * @timeout: Timeout in number of seconds. |
| 10002 | * |
| 10003 | * This function issues the mailbox to firmware and waits for the |
| 10004 | * mailbox command to complete. If the mailbox command is not |
| 10005 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 10006 | * The function waits for the mailbox completion using an |
| 10007 | * interruptible wait. If the thread is woken up due to a |
| 10008 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 10009 | * should not free the mailbox resources, if this function returns |
| 10010 | * MBX_TIMEOUT. |
| 10011 | * This function will sleep while waiting for mailbox completion. |
| 10012 | * So, this function should not be called from any context which |
| 10013 | * does not allow sleeping. Due to the same reason, this function |
| 10014 | * cannot be called with interrupt disabled. |
| 10015 | * This function assumes that the mailbox completion occurs while |
| 10016 | * this function sleep. So, this function cannot be called from |
| 10017 | * the worker thread which processes mailbox completion. |
| 10018 | * This function is called in the context of HBA management |
| 10019 | * applications. |
| 10020 | * This function returns MBX_SUCCESS when successful. |
| 10021 | * This function is called with no lock held. |
| 10022 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10023 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10024 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10025 | uint32_t timeout) |
| 10026 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10027 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10028 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10029 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10030 | |
| 10031 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10032 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10033 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10034 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10035 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10036 | /* setup wake call as IOCB callback */ |
| 10037 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 10038 | /* setup context field to pass wait_queue pointer to wake function */ |
| 10039 | pmboxq->context1 = &done_q; |
| 10040 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10041 | /* now issue the command */ |
| 10042 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10043 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10044 | wait_event_interruptible_timeout(done_q, |
| 10045 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 10046 | timeout * HZ); |
| 10047 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10048 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10049 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10050 | /* |
| 10051 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10052 | * else do not free the resources. |
| 10053 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10054 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10055 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10056 | lpfc_sli4_swap_str(phba, pmboxq); |
| 10057 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10058 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10059 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10060 | } |
| 10061 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10062 | } |
| 10063 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10064 | return retval; |
| 10065 | } |
| 10066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10067 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10068 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10069 | * @phba: Pointer to HBA context. |
| 10070 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10071 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10072 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10073 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10074 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10075 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10076 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10077 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10078 | * as with offline or HBA function reset), this routine will wait for the |
| 10079 | * outstanding mailbox command to complete before invoking the mailbox |
| 10080 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10081 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10082 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10083 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10084 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10085 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10086 | unsigned long timeout; |
| 10087 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10088 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10089 | /* delay 100ms for port state */ |
| 10090 | msleep(100); |
| 10091 | lpfc_sli_mbox_sys_flush(phba); |
| 10092 | return; |
| 10093 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10094 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10095 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10096 | spin_lock_irq(&phba->hbalock); |
| 10097 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10098 | |
| 10099 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10100 | /* Determine how long we might wait for the active mailbox |
| 10101 | * command to be gracefully completed by firmware. |
| 10102 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10103 | if (phba->sli.mbox_active) |
| 10104 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10105 | phba->sli.mbox_active) * |
| 10106 | 1000) + jiffies; |
| 10107 | spin_unlock_irq(&phba->hbalock); |
| 10108 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10109 | while (phba->sli.mbox_active) { |
| 10110 | /* Check active mailbox complete status every 2ms */ |
| 10111 | msleep(2); |
| 10112 | if (time_after(jiffies, timeout)) |
| 10113 | /* Timeout, let the mailbox flush routine to |
| 10114 | * forcefully release active mailbox command |
| 10115 | */ |
| 10116 | break; |
| 10117 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10118 | } else |
| 10119 | spin_unlock_irq(&phba->hbalock); |
| 10120 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10121 | lpfc_sli_mbox_sys_flush(phba); |
| 10122 | } |
| 10123 | |
| 10124 | /** |
| 10125 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10126 | * @phba: Pointer to HBA context. |
| 10127 | * |
| 10128 | * This function is called to read the SLI3 device error attention registers |
| 10129 | * for possible error attention events. The caller must hold the hostlock |
| 10130 | * with spin_lock_irq(). |
| 10131 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10132 | * 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] | 10133 | * Register and returns 0 otherwise. |
| 10134 | **/ |
| 10135 | static int |
| 10136 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10137 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10138 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10139 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10140 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10141 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10142 | goto unplug_err; |
| 10143 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10144 | if (ha_copy & HA_ERATT) { |
| 10145 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10146 | if (lpfc_sli_read_hs(phba)) |
| 10147 | goto unplug_err; |
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 | /* Check if there is a deferred error condition is active */ |
| 10150 | if ((HS_FFER1 & phba->work_hs) && |
| 10151 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10152 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10153 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10154 | /* Clear all interrupt enable conditions */ |
| 10155 | writel(0, phba->HCregaddr); |
| 10156 | readl(phba->HCregaddr); |
| 10157 | } |
| 10158 | |
| 10159 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10160 | phba->work_ha |= HA_ERATT; |
| 10161 | /* Indicate polling handles this ERATT */ |
| 10162 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10163 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10164 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10165 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10166 | |
| 10167 | unplug_err: |
| 10168 | /* Set the driver HS work bitmap */ |
| 10169 | phba->work_hs |= UNPLUG_ERR; |
| 10170 | /* Set the driver HA work bitmap */ |
| 10171 | phba->work_ha |= HA_ERATT; |
| 10172 | /* Indicate polling handles this ERATT */ |
| 10173 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10174 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10175 | } |
| 10176 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10177 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10178 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10179 | * @phba: Pointer to HBA context. |
| 10180 | * |
| 10181 | * This function is called to read the SLI4 device error attention registers |
| 10182 | * for possible error attention events. The caller must hold the hostlock |
| 10183 | * with spin_lock_irq(). |
| 10184 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10185 | * 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] | 10186 | * Register and returns 0 otherwise. |
| 10187 | **/ |
| 10188 | static int |
| 10189 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10190 | { |
| 10191 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10192 | uint32_t if_type, portsmphr; |
| 10193 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10194 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10195 | /* |
| 10196 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10197 | * registers for error attention. This can be changed later. |
| 10198 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10199 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10200 | switch (if_type) { |
| 10201 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10202 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10203 | &uerr_sta_lo) || |
| 10204 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10205 | &uerr_sta_hi)) { |
| 10206 | phba->work_hs |= UNPLUG_ERR; |
| 10207 | phba->work_ha |= HA_ERATT; |
| 10208 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10209 | return 1; |
| 10210 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10211 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10212 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10213 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10214 | "1423 HBA Unrecoverable error: " |
| 10215 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10216 | "ue_mask_lo_reg=0x%x, " |
| 10217 | "ue_mask_hi_reg=0x%x\n", |
| 10218 | uerr_sta_lo, uerr_sta_hi, |
| 10219 | phba->sli4_hba.ue_mask_lo, |
| 10220 | phba->sli4_hba.ue_mask_hi); |
| 10221 | phba->work_status[0] = uerr_sta_lo; |
| 10222 | phba->work_status[1] = uerr_sta_hi; |
| 10223 | phba->work_ha |= HA_ERATT; |
| 10224 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10225 | return 1; |
| 10226 | } |
| 10227 | break; |
| 10228 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10229 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10230 | &portstat_reg.word0) || |
| 10231 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10232 | &portsmphr)){ |
| 10233 | phba->work_hs |= UNPLUG_ERR; |
| 10234 | phba->work_ha |= HA_ERATT; |
| 10235 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10236 | return 1; |
| 10237 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10238 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10239 | phba->work_status[0] = |
| 10240 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10241 | phba->work_status[1] = |
| 10242 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10243 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10244 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10245 | "port status reg 0x%x, " |
| 10246 | "port smphr reg 0x%x, " |
| 10247 | "error 1=0x%x, error 2=0x%x\n", |
| 10248 | portstat_reg.word0, |
| 10249 | portsmphr, |
| 10250 | phba->work_status[0], |
| 10251 | phba->work_status[1]); |
| 10252 | phba->work_ha |= HA_ERATT; |
| 10253 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10254 | return 1; |
| 10255 | } |
| 10256 | break; |
| 10257 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10258 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10259 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10260 | "2886 HBA Error Attention on unsupported " |
| 10261 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10262 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10263 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10264 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10265 | return 0; |
| 10266 | } |
| 10267 | |
| 10268 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10269 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10270 | * @phba: Pointer to HBA context. |
| 10271 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10272 | * 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] | 10273 | * error attention register bit for error attention events. |
| 10274 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10275 | * 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] | 10276 | * Register and returns 0 otherwise. |
| 10277 | **/ |
| 10278 | int |
| 10279 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10280 | { |
| 10281 | uint32_t ha_copy; |
| 10282 | |
| 10283 | /* If somebody is waiting to handle an eratt, don't process it |
| 10284 | * here. The brdkill function will do this. |
| 10285 | */ |
| 10286 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10287 | return 0; |
| 10288 | |
| 10289 | /* Check if interrupt handler handles this ERATT */ |
| 10290 | spin_lock_irq(&phba->hbalock); |
| 10291 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10292 | /* Interrupt handler has handled ERATT */ |
| 10293 | spin_unlock_irq(&phba->hbalock); |
| 10294 | return 0; |
| 10295 | } |
| 10296 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10297 | /* |
| 10298 | * If there is deferred error attention, do not check for error |
| 10299 | * attention |
| 10300 | */ |
| 10301 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10302 | spin_unlock_irq(&phba->hbalock); |
| 10303 | return 0; |
| 10304 | } |
| 10305 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10306 | /* If PCI channel is offline, don't process it */ |
| 10307 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10308 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10309 | return 0; |
| 10310 | } |
| 10311 | |
| 10312 | switch (phba->sli_rev) { |
| 10313 | case LPFC_SLI_REV2: |
| 10314 | case LPFC_SLI_REV3: |
| 10315 | /* Read chip Host Attention (HA) register */ |
| 10316 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10317 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10318 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10319 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10320 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10321 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10322 | default: |
| 10323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10324 | "0299 Invalid SLI revision (%d)\n", |
| 10325 | phba->sli_rev); |
| 10326 | ha_copy = 0; |
| 10327 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10328 | } |
| 10329 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10330 | |
| 10331 | return ha_copy; |
| 10332 | } |
| 10333 | |
| 10334 | /** |
| 10335 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10336 | * @phba: Pointer to HBA context. |
| 10337 | * |
| 10338 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10339 | * that the interrupt should be handled. |
| 10340 | * |
| 10341 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10342 | * interrupt should be handled, otherwise -EIO. |
| 10343 | */ |
| 10344 | static inline int |
| 10345 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10346 | { |
| 10347 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10348 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10349 | return -EIO; |
| 10350 | |
| 10351 | /* Update device level interrupt statistics */ |
| 10352 | phba->sli.slistat.sli_intr++; |
| 10353 | |
| 10354 | /* Ignore all interrupts during initialization. */ |
| 10355 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 10356 | return -EIO; |
| 10357 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10358 | return 0; |
| 10359 | } |
| 10360 | |
| 10361 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10362 | * 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] | 10363 | * @irq: Interrupt number. |
| 10364 | * @dev_id: The device context pointer. |
| 10365 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10366 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10367 | * service routine when device with SLI-3 interface spec is enabled with |
| 10368 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 10369 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 10370 | * interrupt mode, this function is called as part of the device-level |
| 10371 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 10372 | * is undergoing initialization, the interrupt handler will not process |
| 10373 | * the interrupt. The link attention and ELS ring attention events are |
| 10374 | * handled by the worker thread. The interrupt handler signals the worker |
| 10375 | * thread and returns for these events. This function is called without |
| 10376 | * 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] | 10377 | * structures. |
| 10378 | * |
| 10379 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10380 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10381 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10382 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10383 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10384 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10385 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10386 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10387 | uint32_t work_ha_copy; |
| 10388 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10389 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10390 | uint32_t control; |
| 10391 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10392 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10393 | struct lpfc_vport *vport; |
| 10394 | struct lpfc_nodelist *ndlp; |
| 10395 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10396 | LPFC_MBOXQ_t *pmb; |
| 10397 | int rc; |
| 10398 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10399 | /* |
| 10400 | * Get the driver's phba structure from the dev_id and |
| 10401 | * assume the HBA is not interrupting. |
| 10402 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10403 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10404 | |
| 10405 | if (unlikely(!phba)) |
| 10406 | return IRQ_NONE; |
| 10407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10408 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10409 | * Stuff needs to be attented to when this function is invoked as an |
| 10410 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10411 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10412 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10413 | /* Check device state for handling interrupt */ |
| 10414 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10415 | return IRQ_NONE; |
| 10416 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10417 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10418 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10419 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10420 | /* If somebody is waiting to handle an eratt don't process it |
| 10421 | * here. The brdkill function will do this. |
| 10422 | */ |
| 10423 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10424 | ha_copy &= ~HA_ERATT; |
| 10425 | /* Check the need for handling ERATT in interrupt handler */ |
| 10426 | if (ha_copy & HA_ERATT) { |
| 10427 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10428 | /* ERATT polling has handled ERATT */ |
| 10429 | ha_copy &= ~HA_ERATT; |
| 10430 | else |
| 10431 | /* Indicate interrupt handler handles ERATT */ |
| 10432 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10433 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10434 | |
| 10435 | /* |
| 10436 | * If there is deferred error attention, do not check for any |
| 10437 | * interrupt. |
| 10438 | */ |
| 10439 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10440 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10441 | return IRQ_NONE; |
| 10442 | } |
| 10443 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10444 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10445 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 10446 | goto unplug_error; |
| 10447 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10448 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 10449 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10450 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10451 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 10452 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10453 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10454 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10455 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10456 | } else |
| 10457 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10458 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10459 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 10460 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10461 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10462 | if (work_ha_copy & HA_LATT) { |
| 10463 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 10464 | /* |
| 10465 | * Turn off Link Attention interrupts |
| 10466 | * until CLEAR_LA done |
| 10467 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10468 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10469 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10470 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10471 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10472 | control &= ~HC_LAINT_ENA; |
| 10473 | writel(control, phba->HCregaddr); |
| 10474 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10475 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10476 | } |
| 10477 | else |
| 10478 | work_ha_copy &= ~HA_LATT; |
| 10479 | } |
| 10480 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10481 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10482 | /* |
| 10483 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 10484 | * the only slow ring. |
| 10485 | */ |
| 10486 | status = (work_ha_copy & |
| 10487 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10488 | status >>= (4*LPFC_ELS_RING); |
| 10489 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10490 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10491 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10492 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10493 | |
| 10494 | lpfc_debugfs_slow_ring_trc(phba, |
| 10495 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 10496 | control, status, |
| 10497 | (uint32_t)phba->sli.slistat.sli_intr); |
| 10498 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10499 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10500 | lpfc_debugfs_slow_ring_trc(phba, |
| 10501 | "ISR Disable ring:" |
| 10502 | "pwork:x%x hawork:x%x wait:x%x", |
| 10503 | phba->work_ha, work_ha_copy, |
| 10504 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10505 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10506 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10507 | control &= |
| 10508 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10509 | writel(control, phba->HCregaddr); |
| 10510 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10511 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10512 | else { |
| 10513 | lpfc_debugfs_slow_ring_trc(phba, |
| 10514 | "ISR slow ring: pwork:" |
| 10515 | "x%x hawork:x%x wait:x%x", |
| 10516 | phba->work_ha, work_ha_copy, |
| 10517 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10518 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10519 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10520 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10521 | } |
| 10522 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10523 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10524 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10525 | if (lpfc_sli_read_hs(phba)) |
| 10526 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10527 | /* |
| 10528 | * Check if there is a deferred error condition |
| 10529 | * is active |
| 10530 | */ |
| 10531 | if ((HS_FFER1 & phba->work_hs) && |
| 10532 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10533 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 10534 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10535 | phba->hba_flag |= DEFER_ERATT; |
| 10536 | /* Clear all interrupt enable conditions */ |
| 10537 | writel(0, phba->HCregaddr); |
| 10538 | readl(phba->HCregaddr); |
| 10539 | } |
| 10540 | } |
| 10541 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10542 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10543 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10544 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10545 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10546 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10547 | |
| 10548 | /* First check out the status word */ |
| 10549 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 10550 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10551 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10552 | /* |
| 10553 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 10554 | * mbxStatus <status> |
| 10555 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10556 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10557 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10558 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10559 | "Interrupt mbxCommand x%x " |
| 10560 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10561 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10562 | pmbox->mbxCommand, |
| 10563 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10564 | /* clear mailbox attention bit */ |
| 10565 | work_ha_copy &= ~HA_MBATT; |
| 10566 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10567 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10568 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10569 | phba->last_completion_time = jiffies; |
| 10570 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10571 | if (pmb->mbox_cmpl) { |
| 10572 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 10573 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 10574 | if (pmb->out_ext_byte_len && |
| 10575 | pmb->context2) |
| 10576 | lpfc_sli_pcimem_bcopy( |
| 10577 | phba->mbox_ext, |
| 10578 | pmb->context2, |
| 10579 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10580 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10581 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10582 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10583 | |
| 10584 | lpfc_debugfs_disc_trc(vport, |
| 10585 | LPFC_DISC_TRC_MBOX_VPORT, |
| 10586 | "MBOX dflt rpi: : " |
| 10587 | "status:x%x rpi:x%x", |
| 10588 | (uint32_t)pmbox->mbxStatus, |
| 10589 | pmbox->un.varWords[0], 0); |
| 10590 | |
| 10591 | if (!pmbox->mbxStatus) { |
| 10592 | mp = (struct lpfc_dmabuf *) |
| 10593 | (pmb->context1); |
| 10594 | ndlp = (struct lpfc_nodelist *) |
| 10595 | pmb->context2; |
| 10596 | |
| 10597 | /* Reg_LOGIN of dflt RPI was |
| 10598 | * successful. new lets get |
| 10599 | * rid of the RPI using the |
| 10600 | * same mbox buffer. |
| 10601 | */ |
| 10602 | lpfc_unreg_login(phba, |
| 10603 | vport->vpi, |
| 10604 | pmbox->un.varWords[0], |
| 10605 | pmb); |
| 10606 | pmb->mbox_cmpl = |
| 10607 | lpfc_mbx_cmpl_dflt_rpi; |
| 10608 | pmb->context1 = mp; |
| 10609 | pmb->context2 = ndlp; |
| 10610 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10611 | rc = lpfc_sli_issue_mbox(phba, |
| 10612 | pmb, |
| 10613 | MBX_NOWAIT); |
| 10614 | if (rc != MBX_BUSY) |
| 10615 | lpfc_printf_log(phba, |
| 10616 | KERN_ERR, |
| 10617 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10618 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10619 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10620 | if (rc != MBX_NOT_FINISHED) |
| 10621 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10622 | } |
| 10623 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10624 | spin_lock_irqsave( |
| 10625 | &phba->pport->work_port_lock, |
| 10626 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10627 | phba->pport->work_port_events &= |
| 10628 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10629 | spin_unlock_irqrestore( |
| 10630 | &phba->pport->work_port_lock, |
| 10631 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10632 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10633 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10634 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10635 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10636 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10637 | if ((work_ha_copy & HA_MBATT) && |
| 10638 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10639 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10640 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10641 | do { |
| 10642 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 10643 | MBX_NOWAIT); |
| 10644 | } while (rc == MBX_NOT_FINISHED); |
| 10645 | if (rc != MBX_SUCCESS) |
| 10646 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10647 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10648 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10649 | } |
| 10650 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10651 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10652 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10653 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10654 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10655 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10656 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10657 | unplug_error: |
| 10658 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10659 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10660 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10661 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10662 | |
| 10663 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10664 | * 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] | 10665 | * @irq: Interrupt number. |
| 10666 | * @dev_id: The device context pointer. |
| 10667 | * |
| 10668 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10669 | * service routine when device with SLI-3 interface spec is enabled with |
| 10670 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 10671 | * ring event in the HBA. However, when the device is enabled with either |
| 10672 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 10673 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 10674 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 10675 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 10676 | * the intrrupt context. This function is called without any lock held. |
| 10677 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10678 | * |
| 10679 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10680 | * returns IRQ_NONE. |
| 10681 | **/ |
| 10682 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10683 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10684 | { |
| 10685 | struct lpfc_hba *phba; |
| 10686 | uint32_t ha_copy; |
| 10687 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10688 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10689 | |
| 10690 | /* Get the driver's phba structure from the dev_id and |
| 10691 | * assume the HBA is not interrupting. |
| 10692 | */ |
| 10693 | phba = (struct lpfc_hba *) dev_id; |
| 10694 | |
| 10695 | if (unlikely(!phba)) |
| 10696 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10697 | |
| 10698 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10699 | * Stuff needs to be attented to when this function is invoked as an |
| 10700 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10701 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10702 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10703 | /* Check device state for handling interrupt */ |
| 10704 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10705 | return IRQ_NONE; |
| 10706 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10707 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10708 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10709 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10710 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10711 | /* |
| 10712 | * If there is deferred error attention, do not check for |
| 10713 | * any interrupt. |
| 10714 | */ |
| 10715 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10716 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10717 | return IRQ_NONE; |
| 10718 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10719 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 10720 | phba->HAregaddr); |
| 10721 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10722 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10723 | } else |
| 10724 | ha_copy = phba->ha_copy; |
| 10725 | |
| 10726 | /* |
| 10727 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 10728 | */ |
| 10729 | ha_copy &= ~(phba->work_ha_mask); |
| 10730 | |
| 10731 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10732 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10733 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10734 | lpfc_sli_handle_fast_ring_event(phba, |
| 10735 | &phba->sli.ring[LPFC_FCP_RING], |
| 10736 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10737 | |
| 10738 | if (phba->cfg_multi_ring_support == 2) { |
| 10739 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10740 | * Process all events on extra ring. Take the optimized path |
| 10741 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10742 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10743 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10744 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10745 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10746 | lpfc_sli_handle_fast_ring_event(phba, |
| 10747 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 10748 | status); |
| 10749 | } |
| 10750 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10751 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10752 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10753 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10754 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10755 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10756 | * @irq: Interrupt number. |
| 10757 | * @dev_id: The device context pointer. |
| 10758 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10759 | * This function is the HBA device-level interrupt handler to device with |
| 10760 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 10761 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 10762 | * requires driver attention. This function invokes the slow-path interrupt |
| 10763 | * attention handling function and fast-path interrupt attention handling |
| 10764 | * function in turn to process the relevant HBA attention events. This |
| 10765 | * function is called without any lock held. It gets the hbalock to access |
| 10766 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10767 | * |
| 10768 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 10769 | * returns IRQ_NONE. |
| 10770 | **/ |
| 10771 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10772 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10773 | { |
| 10774 | struct lpfc_hba *phba; |
| 10775 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 10776 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10777 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10778 | |
| 10779 | /* |
| 10780 | * Get the driver's phba structure from the dev_id and |
| 10781 | * assume the HBA is not interrupting. |
| 10782 | */ |
| 10783 | phba = (struct lpfc_hba *) dev_id; |
| 10784 | |
| 10785 | if (unlikely(!phba)) |
| 10786 | return IRQ_NONE; |
| 10787 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10788 | /* Check device state for handling interrupt */ |
| 10789 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10790 | return IRQ_NONE; |
| 10791 | |
| 10792 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10793 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 10794 | spin_unlock(&phba->hbalock); |
| 10795 | return IRQ_HANDLED; |
| 10796 | } |
| 10797 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10798 | if (unlikely(!phba->ha_copy)) { |
| 10799 | spin_unlock(&phba->hbalock); |
| 10800 | return IRQ_NONE; |
| 10801 | } else if (phba->ha_copy & HA_ERATT) { |
| 10802 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10803 | /* ERATT polling has handled ERATT */ |
| 10804 | phba->ha_copy &= ~HA_ERATT; |
| 10805 | else |
| 10806 | /* Indicate interrupt handler handles ERATT */ |
| 10807 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10808 | } |
| 10809 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10810 | /* |
| 10811 | * If there is deferred error attention, do not check for any interrupt. |
| 10812 | */ |
| 10813 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 10814 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10815 | return IRQ_NONE; |
| 10816 | } |
| 10817 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10818 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10819 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 10820 | spin_unlock(&phba->hbalock); |
| 10821 | return IRQ_HANDLED; |
| 10822 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10823 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 10824 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10825 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10826 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10827 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10828 | readl(phba->HAregaddr); /* flush */ |
| 10829 | spin_unlock(&phba->hbalock); |
| 10830 | |
| 10831 | /* |
| 10832 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 10833 | */ |
| 10834 | |
| 10835 | /* status of events with mailbox and link attention */ |
| 10836 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 10837 | |
| 10838 | /* status of events with ELS ring */ |
| 10839 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10840 | status2 >>= (4*LPFC_ELS_RING); |
| 10841 | |
| 10842 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10843 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10844 | else |
| 10845 | sp_irq_rc = IRQ_NONE; |
| 10846 | |
| 10847 | /* |
| 10848 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 10849 | */ |
| 10850 | |
| 10851 | /* status of events with FCP ring */ |
| 10852 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 10853 | status1 >>= (4*LPFC_FCP_RING); |
| 10854 | |
| 10855 | /* status of events with extra ring */ |
| 10856 | if (phba->cfg_multi_ring_support == 2) { |
| 10857 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 10858 | status2 >>= (4*LPFC_EXTRA_RING); |
| 10859 | } else |
| 10860 | status2 = 0; |
| 10861 | |
| 10862 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10863 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10864 | else |
| 10865 | fp_irq_rc = IRQ_NONE; |
| 10866 | |
| 10867 | /* Return device-level interrupt handling status */ |
| 10868 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10869 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10870 | |
| 10871 | /** |
| 10872 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 10873 | * @phba: pointer to lpfc hba data structure. |
| 10874 | * |
| 10875 | * This routine is invoked by the worker thread to process all the pending |
| 10876 | * SLI4 FCP abort XRI events. |
| 10877 | **/ |
| 10878 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10879 | { |
| 10880 | struct lpfc_cq_event *cq_event; |
| 10881 | |
| 10882 | /* First, declare the fcp xri abort event has been handled */ |
| 10883 | spin_lock_irq(&phba->hbalock); |
| 10884 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 10885 | spin_unlock_irq(&phba->hbalock); |
| 10886 | /* Now, handle all the fcp xri abort events */ |
| 10887 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 10888 | /* Get the first event from the head of the event queue */ |
| 10889 | spin_lock_irq(&phba->hbalock); |
| 10890 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10891 | cq_event, struct lpfc_cq_event, list); |
| 10892 | spin_unlock_irq(&phba->hbalock); |
| 10893 | /* Notify aborted XRI for FCP work queue */ |
| 10894 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10895 | /* Free the event processed back to the free pool */ |
| 10896 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10897 | } |
| 10898 | } |
| 10899 | |
| 10900 | /** |
| 10901 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 10902 | * @phba: pointer to lpfc hba data structure. |
| 10903 | * |
| 10904 | * This routine is invoked by the worker thread to process all the pending |
| 10905 | * SLI4 els abort xri events. |
| 10906 | **/ |
| 10907 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10908 | { |
| 10909 | struct lpfc_cq_event *cq_event; |
| 10910 | |
| 10911 | /* First, declare the els xri abort event has been handled */ |
| 10912 | spin_lock_irq(&phba->hbalock); |
| 10913 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 10914 | spin_unlock_irq(&phba->hbalock); |
| 10915 | /* Now, handle all the els xri abort events */ |
| 10916 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 10917 | /* Get the first event from the head of the event queue */ |
| 10918 | spin_lock_irq(&phba->hbalock); |
| 10919 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10920 | cq_event, struct lpfc_cq_event, list); |
| 10921 | spin_unlock_irq(&phba->hbalock); |
| 10922 | /* Notify aborted XRI for ELS work queue */ |
| 10923 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10924 | /* Free the event processed back to the free pool */ |
| 10925 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10926 | } |
| 10927 | } |
| 10928 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10929 | /** |
| 10930 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 10931 | * @phba: pointer to lpfc hba data structure |
| 10932 | * @pIocbIn: pointer to the rspiocbq |
| 10933 | * @pIocbOut: pointer to the cmdiocbq |
| 10934 | * @wcqe: pointer to the complete wcqe |
| 10935 | * |
| 10936 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 10937 | * by copying all the IOCB fields from command iocbq and transferring the |
| 10938 | * completion status information from the complete wcqe. |
| 10939 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10940 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10941 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 10942 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10943 | struct lpfc_iocbq *pIocbOut, |
| 10944 | struct lpfc_wcqe_complete *wcqe) |
| 10945 | { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10946 | unsigned long iflags; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10947 | uint32_t status; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10948 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 10949 | |
| 10950 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 10951 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10952 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10953 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 10954 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10955 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 10956 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 10957 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 10958 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 10959 | wcqe->total_data_placed; |
| 10960 | else |
| 10961 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10962 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10963 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10964 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
| 10965 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10966 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10967 | /* Convert BG errors for completion status */ |
| 10968 | if (status == CQE_STATUS_DI_ERROR) { |
| 10969 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 10970 | |
| 10971 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 10972 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 10973 | else |
| 10974 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 10975 | |
| 10976 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 10977 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 10978 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10979 | BGS_GUARD_ERR_MASK; |
| 10980 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 10981 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10982 | BGS_APPTAG_ERR_MASK; |
| 10983 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 10984 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10985 | BGS_REFTAG_ERR_MASK; |
| 10986 | |
| 10987 | /* Check to see if there was any good data before the error */ |
| 10988 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 10989 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10990 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 10991 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 10992 | wcqe->total_data_placed; |
| 10993 | } |
| 10994 | |
| 10995 | /* |
| 10996 | * Set ALL the error bits to indicate we don't know what |
| 10997 | * type of error it is. |
| 10998 | */ |
| 10999 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 11000 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11001 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 11002 | BGS_GUARD_ERR_MASK); |
| 11003 | } |
| 11004 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11005 | /* Pick up HBA exchange busy condition */ |
| 11006 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 11007 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11008 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 11009 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11010 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11011 | } |
| 11012 | |
| 11013 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11014 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 11015 | * @phba: Pointer to HBA context object. |
| 11016 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11017 | * |
| 11018 | * This routine handles an ELS work-queue completion event and construct |
| 11019 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 11020 | * discovery engine to handle. |
| 11021 | * |
| 11022 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 11023 | **/ |
| 11024 | static struct lpfc_iocbq * |
| 11025 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 11026 | struct lpfc_iocbq *irspiocbq) |
| 11027 | { |
| 11028 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 11029 | struct lpfc_iocbq *cmdiocbq; |
| 11030 | struct lpfc_wcqe_complete *wcqe; |
| 11031 | unsigned long iflags; |
| 11032 | |
| 11033 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11034 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11035 | pring->stats.iocb_event++; |
| 11036 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 11037 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11038 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11039 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11040 | |
| 11041 | if (unlikely(!cmdiocbq)) { |
| 11042 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11043 | "0386 ELS complete with no corresponding " |
| 11044 | "cmdiocb: iotag (%d)\n", |
| 11045 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11046 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 11047 | return NULL; |
| 11048 | } |
| 11049 | |
| 11050 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11051 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11052 | |
| 11053 | return irspiocbq; |
| 11054 | } |
| 11055 | |
| 11056 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11057 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11058 | * @phba: Pointer to HBA context object. |
| 11059 | * @cqe: Pointer to mailbox completion queue entry. |
| 11060 | * |
| 11061 | * This routine process a mailbox completion queue entry with asynchrous |
| 11062 | * event. |
| 11063 | * |
| 11064 | * Return: true if work posted to worker thread, otherwise false. |
| 11065 | **/ |
| 11066 | static bool |
| 11067 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11068 | { |
| 11069 | struct lpfc_cq_event *cq_event; |
| 11070 | unsigned long iflags; |
| 11071 | |
| 11072 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11073 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11074 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11075 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11076 | |
| 11077 | /* Allocate a new internal CQ_EVENT entry */ |
| 11078 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11079 | if (!cq_event) { |
| 11080 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11081 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11082 | return false; |
| 11083 | } |
| 11084 | |
| 11085 | /* Move the CQE into an asynchronous event entry */ |
| 11086 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11087 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11088 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11089 | /* Set the async event flag */ |
| 11090 | phba->hba_flag |= ASYNC_EVENT; |
| 11091 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11092 | |
| 11093 | return true; |
| 11094 | } |
| 11095 | |
| 11096 | /** |
| 11097 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11098 | * @phba: Pointer to HBA context object. |
| 11099 | * @cqe: Pointer to mailbox completion queue entry. |
| 11100 | * |
| 11101 | * This routine process a mailbox completion queue entry with mailbox |
| 11102 | * completion event. |
| 11103 | * |
| 11104 | * Return: true if work posted to worker thread, otherwise false. |
| 11105 | **/ |
| 11106 | static bool |
| 11107 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11108 | { |
| 11109 | uint32_t mcqe_status; |
| 11110 | MAILBOX_t *mbox, *pmbox; |
| 11111 | struct lpfc_mqe *mqe; |
| 11112 | struct lpfc_vport *vport; |
| 11113 | struct lpfc_nodelist *ndlp; |
| 11114 | struct lpfc_dmabuf *mp; |
| 11115 | unsigned long iflags; |
| 11116 | LPFC_MBOXQ_t *pmb; |
| 11117 | bool workposted = false; |
| 11118 | int rc; |
| 11119 | |
| 11120 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11121 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11122 | goto out_no_mqe_complete; |
| 11123 | |
| 11124 | /* Get the reference to the active mbox command */ |
| 11125 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11126 | pmb = phba->sli.mbox_active; |
| 11127 | if (unlikely(!pmb)) { |
| 11128 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11129 | "1832 No pending MBOX command to handle\n"); |
| 11130 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11131 | goto out_no_mqe_complete; |
| 11132 | } |
| 11133 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11134 | mqe = &pmb->u.mqe; |
| 11135 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11136 | mbox = phba->mbox; |
| 11137 | vport = pmb->vport; |
| 11138 | |
| 11139 | /* Reset heartbeat timer */ |
| 11140 | phba->last_completion_time = jiffies; |
| 11141 | del_timer(&phba->sli.mbox_tmo); |
| 11142 | |
| 11143 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11144 | if (pmb->mbox_cmpl && mbox) |
| 11145 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11146 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11147 | /* |
| 11148 | * For mcqe errors, conditionally move a modified error code to |
| 11149 | * the mbox so that the error will not be missed. |
| 11150 | */ |
| 11151 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11152 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11153 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11154 | bf_set(lpfc_mqe_status, mqe, |
| 11155 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11156 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11157 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11158 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11159 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11160 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11161 | mcqe_status, |
| 11162 | pmbox->un.varWords[0], 0); |
| 11163 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11164 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11165 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11166 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11167 | * RID of the PPI using the same mbox buffer. |
| 11168 | */ |
| 11169 | lpfc_unreg_login(phba, vport->vpi, |
| 11170 | pmbox->un.varWords[0], pmb); |
| 11171 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11172 | pmb->context1 = mp; |
| 11173 | pmb->context2 = ndlp; |
| 11174 | pmb->vport = vport; |
| 11175 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11176 | if (rc != MBX_BUSY) |
| 11177 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11178 | LOG_SLI, "0385 rc should " |
| 11179 | "have been MBX_BUSY\n"); |
| 11180 | if (rc != MBX_NOT_FINISHED) |
| 11181 | goto send_current_mbox; |
| 11182 | } |
| 11183 | } |
| 11184 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11185 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11186 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11187 | |
| 11188 | /* There is mailbox completion work to do */ |
| 11189 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11190 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11191 | phba->work_ha |= HA_MBATT; |
| 11192 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11193 | workposted = true; |
| 11194 | |
| 11195 | send_current_mbox: |
| 11196 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11197 | /* Release the mailbox command posting token */ |
| 11198 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11199 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11200 | phba->sli.mbox_active = NULL; |
| 11201 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11202 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11203 | lpfc_worker_wake_up(phba); |
| 11204 | out_no_mqe_complete: |
| 11205 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11206 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11207 | return workposted; |
| 11208 | } |
| 11209 | |
| 11210 | /** |
| 11211 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11212 | * @phba: Pointer to HBA context object. |
| 11213 | * @cqe: Pointer to mailbox completion queue entry. |
| 11214 | * |
| 11215 | * This routine process a mailbox completion queue entry, it invokes the |
| 11216 | * proper mailbox complete handling or asynchrous event handling routine |
| 11217 | * according to the MCQE's async bit. |
| 11218 | * |
| 11219 | * Return: true if work posted to worker thread, otherwise false. |
| 11220 | **/ |
| 11221 | static bool |
| 11222 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11223 | { |
| 11224 | struct lpfc_mcqe mcqe; |
| 11225 | bool workposted; |
| 11226 | |
| 11227 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11228 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11229 | |
| 11230 | /* Invoke the proper event handling routine */ |
| 11231 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11232 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11233 | else |
| 11234 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11235 | return workposted; |
| 11236 | } |
| 11237 | |
| 11238 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11239 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11240 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11241 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11242 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11243 | * |
| 11244 | * This routine handles an ELS work-queue completion event. |
| 11245 | * |
| 11246 | * Return: true if work posted to worker thread, otherwise false. |
| 11247 | **/ |
| 11248 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11249 | 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] | 11250 | struct lpfc_wcqe_complete *wcqe) |
| 11251 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11252 | struct lpfc_iocbq *irspiocbq; |
| 11253 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11254 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11255 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11256 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11257 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 11258 | if (!irspiocbq) { |
| 11259 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11260 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 11261 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
| 11262 | pring->txq_cnt, phba->iocb_cnt, |
| 11263 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, |
| 11264 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11265 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11266 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11267 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11268 | /* Save off the slow-path queue event for work thread to process */ |
| 11269 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11270 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11271 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11272 | &phba->sli4_hba.sp_queue_event); |
| 11273 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11274 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11275 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11276 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11277 | } |
| 11278 | |
| 11279 | /** |
| 11280 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11281 | * @phba: Pointer to HBA context object. |
| 11282 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11283 | * |
| 11284 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11285 | * proper WQ release routine to the slow-path WQ. |
| 11286 | **/ |
| 11287 | static void |
| 11288 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11289 | struct lpfc_wcqe_release *wcqe) |
| 11290 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11291 | /* sanity check on queue memory */ |
| 11292 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11293 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11294 | /* Check for the slow-path ELS work queue */ |
| 11295 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11296 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11297 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11298 | else |
| 11299 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11300 | "2579 Slow-path wqe consume event carries " |
| 11301 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11302 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11303 | phba->sli4_hba.els_wq->queue_id); |
| 11304 | } |
| 11305 | |
| 11306 | /** |
| 11307 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11308 | * @phba: Pointer to HBA context object. |
| 11309 | * @cq: Pointer to a WQ completion queue. |
| 11310 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11311 | * |
| 11312 | * This routine handles an XRI abort event. |
| 11313 | * |
| 11314 | * Return: true if work posted to worker thread, otherwise false. |
| 11315 | **/ |
| 11316 | static bool |
| 11317 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 11318 | struct lpfc_queue *cq, |
| 11319 | struct sli4_wcqe_xri_aborted *wcqe) |
| 11320 | { |
| 11321 | bool workposted = false; |
| 11322 | struct lpfc_cq_event *cq_event; |
| 11323 | unsigned long iflags; |
| 11324 | |
| 11325 | /* Allocate a new internal CQ_EVENT entry */ |
| 11326 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11327 | if (!cq_event) { |
| 11328 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11329 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 11330 | return false; |
| 11331 | } |
| 11332 | |
| 11333 | /* Move the CQE into the proper xri abort event list */ |
| 11334 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 11335 | switch (cq->subtype) { |
| 11336 | case LPFC_FCP: |
| 11337 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11338 | list_add_tail(&cq_event->list, |
| 11339 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 11340 | /* Set the fcp xri abort event flag */ |
| 11341 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 11342 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11343 | workposted = true; |
| 11344 | break; |
| 11345 | case LPFC_ELS: |
| 11346 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11347 | list_add_tail(&cq_event->list, |
| 11348 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 11349 | /* Set the els xri abort event flag */ |
| 11350 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 11351 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11352 | workposted = true; |
| 11353 | break; |
| 11354 | default: |
| 11355 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11356 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 11357 | cq->subtype); |
| 11358 | workposted = false; |
| 11359 | break; |
| 11360 | } |
| 11361 | return workposted; |
| 11362 | } |
| 11363 | |
| 11364 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11365 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11366 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11367 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11368 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11369 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11370 | * |
| 11371 | * Return: true if work posted to worker thread, otherwise false. |
| 11372 | **/ |
| 11373 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11374 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 11375 | { |
| 11376 | bool workposted = false; |
| 11377 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 11378 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 11379 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11380 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11381 | unsigned long iflags; |
| 11382 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11383 | /* sanity check on queue memory */ |
| 11384 | if (unlikely(!hrq) || unlikely(!drq)) |
| 11385 | return workposted; |
| 11386 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11387 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 11388 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 11389 | else |
| 11390 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 11391 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11392 | goto out; |
| 11393 | |
| 11394 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 11395 | switch (status) { |
| 11396 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 11397 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11398 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11399 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11400 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11401 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11402 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11403 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 11404 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11405 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11406 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11407 | goto out; |
| 11408 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11409 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11410 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 11411 | /* save off the frame for the word thread to process */ |
| 11412 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11413 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11414 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11415 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11416 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11417 | workposted = true; |
| 11418 | break; |
| 11419 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 11420 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11421 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11422 | /* Post more buffers if possible */ |
| 11423 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11424 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 11425 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11426 | workposted = true; |
| 11427 | break; |
| 11428 | } |
| 11429 | out: |
| 11430 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11431 | } |
| 11432 | |
| 11433 | /** |
| 11434 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 11435 | * @phba: Pointer to HBA context object. |
| 11436 | * @cq: Pointer to the completion queue. |
| 11437 | * @wcqe: Pointer to a completion queue entry. |
| 11438 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11439 | * 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] | 11440 | * entry. |
| 11441 | * |
| 11442 | * Return: true if work posted to worker thread, otherwise false. |
| 11443 | **/ |
| 11444 | static bool |
| 11445 | 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] | 11446 | struct lpfc_cqe *cqe) |
| 11447 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11448 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11449 | bool workposted = false; |
| 11450 | |
| 11451 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11452 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11453 | |
| 11454 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11455 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11456 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11457 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11458 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11459 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11460 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11461 | break; |
| 11462 | case CQE_CODE_RELEASE_WQE: |
| 11463 | /* Process the WQ release event */ |
| 11464 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11465 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11466 | break; |
| 11467 | case CQE_CODE_XRI_ABORTED: |
| 11468 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11469 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11470 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11471 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11472 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11473 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11474 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11475 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11476 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11477 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11478 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11479 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11480 | default: |
| 11481 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11482 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11483 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11484 | break; |
| 11485 | } |
| 11486 | return workposted; |
| 11487 | } |
| 11488 | |
| 11489 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11490 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 11491 | * @phba: Pointer to HBA context object. |
| 11492 | * @eqe: Pointer to fast-path event queue entry. |
| 11493 | * |
| 11494 | * This routine process a event queue entry from the slow-path event queue. |
| 11495 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11496 | * completion event on a completion queue, if not, an error shall be logged |
| 11497 | * and just return. Otherwise, it will get to the corresponding completion |
| 11498 | * queue and process all the entries on that completion queue, rearm the |
| 11499 | * completion queue, and then return. |
| 11500 | * |
| 11501 | **/ |
| 11502 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11503 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11504 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11505 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11506 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11507 | struct lpfc_cqe *cqe; |
| 11508 | bool workposted = false; |
| 11509 | int ecount = 0; |
| 11510 | uint16_t cqid; |
| 11511 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11512 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11513 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11514 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11515 | list_for_each_entry(childq, &speq->child_list, list) { |
| 11516 | if (childq->queue_id == cqid) { |
| 11517 | cq = childq; |
| 11518 | break; |
| 11519 | } |
| 11520 | } |
| 11521 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11522 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11523 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11524 | "0365 Slow-path CQ identifier " |
| 11525 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11526 | return; |
| 11527 | } |
| 11528 | |
| 11529 | /* Process all the entries to the CQ */ |
| 11530 | switch (cq->type) { |
| 11531 | case LPFC_MCQ: |
| 11532 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11533 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11534 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11535 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11536 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11537 | } |
| 11538 | break; |
| 11539 | case LPFC_WCQ: |
| 11540 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11541 | if (cq->subtype == LPFC_FCP) |
| 11542 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 11543 | cqe); |
| 11544 | else |
| 11545 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 11546 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11547 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11548 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11549 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11550 | |
| 11551 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11552 | if (ecount > cq->CQ_max_cqe) |
| 11553 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11554 | break; |
| 11555 | default: |
| 11556 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11557 | "0370 Invalid completion queue type (%d)\n", |
| 11558 | cq->type); |
| 11559 | return; |
| 11560 | } |
| 11561 | |
| 11562 | /* Catch the no cq entry condition, log an error */ |
| 11563 | if (unlikely(ecount == 0)) |
| 11564 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11565 | "0371 No entry from the CQ: identifier " |
| 11566 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 11567 | |
| 11568 | /* In any case, flash and re-arm the RCQ */ |
| 11569 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11570 | |
| 11571 | /* wake up worker thread if there are works to be done */ |
| 11572 | if (workposted) |
| 11573 | lpfc_worker_wake_up(phba); |
| 11574 | } |
| 11575 | |
| 11576 | /** |
| 11577 | * 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] | 11578 | * @phba: Pointer to HBA context object. |
| 11579 | * @cq: Pointer to associated CQ |
| 11580 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11581 | * |
| 11582 | * This routine process a fast-path work queue completion entry from fast-path |
| 11583 | * event queue for FCP command response completion. |
| 11584 | **/ |
| 11585 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11586 | 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] | 11587 | struct lpfc_wcqe_complete *wcqe) |
| 11588 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11589 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11590 | struct lpfc_iocbq *cmdiocbq; |
| 11591 | struct lpfc_iocbq irspiocbq; |
| 11592 | unsigned long iflags; |
| 11593 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11594 | /* Check for response status */ |
| 11595 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 11596 | /* If resource errors reported from HBA, reduce queue |
| 11597 | * depth of the SCSI device. |
| 11598 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11599 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 11600 | IOSTAT_LOCAL_REJECT)) && |
| 11601 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 11602 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11603 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11604 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11605 | /* Log the error status */ |
| 11606 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11607 | "0373 FCP complete error: status=x%x, " |
| 11608 | "hw_status=x%x, total_data_specified=%d, " |
| 11609 | "parameter=x%x, word3=x%x\n", |
| 11610 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 11611 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 11612 | wcqe->total_data_placed, wcqe->parameter, |
| 11613 | wcqe->word3); |
| 11614 | } |
| 11615 | |
| 11616 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11617 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11618 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11619 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11620 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11621 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11622 | if (unlikely(!cmdiocbq)) { |
| 11623 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11624 | "0374 FCP complete with no corresponding " |
| 11625 | "cmdiocb: iotag (%d)\n", |
| 11626 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11627 | return; |
| 11628 | } |
| 11629 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 11630 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11631 | "0375 FCP cmdiocb not callback function " |
| 11632 | "iotag: (%d)\n", |
| 11633 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11634 | return; |
| 11635 | } |
| 11636 | |
| 11637 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11638 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11639 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11640 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 11641 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11642 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11643 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11644 | } |
| 11645 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11646 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 11647 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 11648 | } |
| 11649 | |
| 11650 | /** |
| 11651 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 11652 | * @phba: Pointer to HBA context object. |
| 11653 | * @cq: Pointer to completion queue. |
| 11654 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11655 | * |
| 11656 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 11657 | * proper WQ release routine to the slow-path WQ. |
| 11658 | **/ |
| 11659 | static void |
| 11660 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11661 | struct lpfc_wcqe_release *wcqe) |
| 11662 | { |
| 11663 | struct lpfc_queue *childwq; |
| 11664 | bool wqid_matched = false; |
| 11665 | uint16_t fcp_wqid; |
| 11666 | |
| 11667 | /* Check for fast-path FCP work queue release */ |
| 11668 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 11669 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 11670 | if (childwq->queue_id == fcp_wqid) { |
| 11671 | lpfc_sli4_wq_release(childwq, |
| 11672 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11673 | wqid_matched = true; |
| 11674 | break; |
| 11675 | } |
| 11676 | } |
| 11677 | /* Report warning log message if no match found */ |
| 11678 | if (wqid_matched != true) |
| 11679 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11680 | "2580 Fast-path wqe consume event carries " |
| 11681 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 11682 | } |
| 11683 | |
| 11684 | /** |
| 11685 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 11686 | * @cq: Pointer to the completion queue. |
| 11687 | * @eqe: Pointer to fast-path completion queue entry. |
| 11688 | * |
| 11689 | * This routine process a fast-path work queue completion entry from fast-path |
| 11690 | * event queue for FCP command response completion. |
| 11691 | **/ |
| 11692 | static int |
| 11693 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11694 | struct lpfc_cqe *cqe) |
| 11695 | { |
| 11696 | struct lpfc_wcqe_release wcqe; |
| 11697 | bool workposted = false; |
| 11698 | |
| 11699 | /* Copy the work queue CQE and convert endian order if needed */ |
| 11700 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 11701 | |
| 11702 | /* Check and process for different type of WCQE and dispatch */ |
| 11703 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 11704 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11705 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11706 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11707 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11708 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11709 | (struct lpfc_wcqe_complete *)&wcqe); |
| 11710 | break; |
| 11711 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11712 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11713 | /* Process the WQ release event */ |
| 11714 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 11715 | (struct lpfc_wcqe_release *)&wcqe); |
| 11716 | break; |
| 11717 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11718 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11719 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11720 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11721 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 11722 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 11723 | break; |
| 11724 | default: |
| 11725 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11726 | "0144 Not a valid WCQE code: x%x\n", |
| 11727 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 11728 | break; |
| 11729 | } |
| 11730 | return workposted; |
| 11731 | } |
| 11732 | |
| 11733 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11734 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11735 | * @phba: Pointer to HBA context object. |
| 11736 | * @eqe: Pointer to fast-path event queue entry. |
| 11737 | * |
| 11738 | * This routine process a event queue entry from the fast-path event queue. |
| 11739 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11740 | * completion event on a completion queue, if not, an error shall be logged |
| 11741 | * and just return. Otherwise, it will get to the corresponding completion |
| 11742 | * queue and process all the entries on the completion queue, rearm the |
| 11743 | * completion queue, and then return. |
| 11744 | **/ |
| 11745 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11746 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11747 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11748 | { |
| 11749 | struct lpfc_queue *cq; |
| 11750 | struct lpfc_cqe *cqe; |
| 11751 | bool workposted = false; |
| 11752 | uint16_t cqid; |
| 11753 | int ecount = 0; |
| 11754 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11755 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11756 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11757 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11758 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11759 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11760 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11761 | return; |
| 11762 | } |
| 11763 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11764 | /* Get the reference to the corresponding CQ */ |
| 11765 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 11766 | |
| 11767 | /* Check if this is a Slow path event */ |
| 11768 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { |
| 11769 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 11770 | phba->sli4_hba.hba_eq[qidx]); |
| 11771 | return; |
| 11772 | } |
| 11773 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11774 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 11775 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11776 | "3146 Fast-path completion queues " |
| 11777 | "does not exist\n"); |
| 11778 | return; |
| 11779 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11780 | cq = phba->sli4_hba.fcp_cq[qidx]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11781 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11782 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11783 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11784 | "0367 Fast-path completion queue " |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11785 | "(%d) does not exist\n", qidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11786 | return; |
| 11787 | } |
| 11788 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11789 | if (unlikely(cqid != cq->queue_id)) { |
| 11790 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11791 | "0368 Miss-matched fast-path completion " |
| 11792 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 11793 | cqid, cq->queue_id); |
| 11794 | return; |
| 11795 | } |
| 11796 | |
| 11797 | /* Process all the entries to the CQ */ |
| 11798 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11799 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11800 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11801 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11802 | } |
| 11803 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11804 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11805 | if (ecount > cq->CQ_max_cqe) |
| 11806 | cq->CQ_max_cqe = ecount; |
| 11807 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11808 | /* Catch the no cq entry condition */ |
| 11809 | if (unlikely(ecount == 0)) |
| 11810 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11811 | "0369 No entry from fast-path completion " |
| 11812 | "queue fcpcqid=%d\n", cq->queue_id); |
| 11813 | |
| 11814 | /* In any case, flash and re-arm the CQ */ |
| 11815 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11816 | |
| 11817 | /* wake up worker thread if there are works to be done */ |
| 11818 | if (workposted) |
| 11819 | lpfc_worker_wake_up(phba); |
| 11820 | } |
| 11821 | |
| 11822 | static void |
| 11823 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 11824 | { |
| 11825 | struct lpfc_eqe *eqe; |
| 11826 | |
| 11827 | /* walk all the EQ entries and drop on the floor */ |
| 11828 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 11829 | ; |
| 11830 | |
| 11831 | /* Clear and re-arm the EQ */ |
| 11832 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 11833 | } |
| 11834 | |
| 11835 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11836 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11837 | * @irq: Interrupt number. |
| 11838 | * @dev_id: The device context pointer. |
| 11839 | * |
| 11840 | * This function is directly called from the PCI layer as an interrupt |
| 11841 | * service routine when device with SLI-4 interface spec is enabled with |
| 11842 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11843 | * ring event in the HBA. However, when the device is enabled with either |
| 11844 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11845 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11846 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11847 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11848 | * the intrrupt context. This function is called without any lock held. |
| 11849 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 11850 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 11851 | * equal to that of FCP CQ index. |
| 11852 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11853 | * The link attention and ELS ring attention events are handled |
| 11854 | * by the worker thread. The interrupt handler signals the worker thread |
| 11855 | * and returns for these events. This function is called without any lock |
| 11856 | * held. It gets the hbalock to access and update SLI data structures. |
| 11857 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11858 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11859 | * returns IRQ_NONE. |
| 11860 | **/ |
| 11861 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11862 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11863 | { |
| 11864 | struct lpfc_hba *phba; |
| 11865 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 11866 | struct lpfc_queue *fpeq; |
| 11867 | struct lpfc_eqe *eqe; |
| 11868 | unsigned long iflag; |
| 11869 | int ecount = 0; |
| 11870 | uint32_t fcp_eqidx; |
| 11871 | |
| 11872 | /* Get the driver's phba structure from the dev_id */ |
| 11873 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 11874 | phba = fcp_eq_hdl->phba; |
| 11875 | fcp_eqidx = fcp_eq_hdl->idx; |
| 11876 | |
| 11877 | if (unlikely(!phba)) |
| 11878 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11879 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11880 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11881 | |
| 11882 | /* Get to the EQ struct associated with this vector */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11883 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11884 | if (unlikely(!fpeq)) |
| 11885 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11886 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 11887 | if (lpfc_fcp_look_ahead) { |
| 11888 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) |
| 11889 | lpfc_sli4_eq_clr_intr(fpeq); |
| 11890 | else { |
| 11891 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 11892 | return IRQ_NONE; |
| 11893 | } |
| 11894 | } |
| 11895 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11896 | /* Check device state for handling interrupt */ |
| 11897 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11898 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11899 | /* Check again for link_state with lock held */ |
| 11900 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11901 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11902 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11903 | lpfc_sli4_eq_flush(phba, fpeq); |
| 11904 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 11905 | if (lpfc_fcp_look_ahead) |
| 11906 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11907 | return IRQ_NONE; |
| 11908 | } |
| 11909 | |
| 11910 | /* |
| 11911 | * Process all the event on FCP fast-path EQ |
| 11912 | */ |
| 11913 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11914 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11915 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11916 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11917 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11918 | } |
| 11919 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11920 | /* Track the max number of EQEs processed in 1 intr */ |
| 11921 | if (ecount > fpeq->EQ_max_eqe) |
| 11922 | fpeq->EQ_max_eqe = ecount; |
| 11923 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11924 | /* Always clear and re-arm the fast-path EQ */ |
| 11925 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 11926 | |
| 11927 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11928 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 11929 | |
| 11930 | if (lpfc_fcp_look_ahead) { |
| 11931 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 11932 | return IRQ_NONE; |
| 11933 | } |
| 11934 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11935 | if (phba->intr_type == MSIX) |
| 11936 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11937 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11938 | "0358 MSI-X interrupt with no EQE\n"); |
| 11939 | else |
| 11940 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11941 | return IRQ_NONE; |
| 11942 | } |
| 11943 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 11944 | if (lpfc_fcp_look_ahead) |
| 11945 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11946 | return IRQ_HANDLED; |
| 11947 | } /* lpfc_sli4_fp_intr_handler */ |
| 11948 | |
| 11949 | /** |
| 11950 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 11951 | * @irq: Interrupt number. |
| 11952 | * @dev_id: The device context pointer. |
| 11953 | * |
| 11954 | * This function is the device-level interrupt handler to device with SLI-4 |
| 11955 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 11956 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 11957 | * driver attention. This function invokes the slow-path interrupt attention |
| 11958 | * handling function and fast-path interrupt attention handling function in |
| 11959 | * turn to process the relevant HBA attention events. This function is called |
| 11960 | * without any lock held. It gets the hbalock to access and update SLI data |
| 11961 | * structures. |
| 11962 | * |
| 11963 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11964 | * returns IRQ_NONE. |
| 11965 | **/ |
| 11966 | irqreturn_t |
| 11967 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 11968 | { |
| 11969 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11970 | irqreturn_t hba_irq_rc; |
| 11971 | bool hba_handled = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11972 | uint32_t fcp_eqidx; |
| 11973 | |
| 11974 | /* Get the driver's phba structure from the dev_id */ |
| 11975 | phba = (struct lpfc_hba *)dev_id; |
| 11976 | |
| 11977 | if (unlikely(!phba)) |
| 11978 | return IRQ_NONE; |
| 11979 | |
| 11980 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11981 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11982 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11983 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 11984 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11985 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11986 | if (hba_irq_rc == IRQ_HANDLED) |
| 11987 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11988 | } |
| 11989 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11990 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11991 | } /* lpfc_sli4_intr_handler */ |
| 11992 | |
| 11993 | /** |
| 11994 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 11995 | * @queue: The queue structure to free. |
| 11996 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 11997 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11998 | * the host resident queue. This function must be called after destroying the |
| 11999 | * queue on the HBA. |
| 12000 | **/ |
| 12001 | void |
| 12002 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12003 | { |
| 12004 | struct lpfc_dmabuf *dmabuf; |
| 12005 | |
| 12006 | if (!queue) |
| 12007 | return; |
| 12008 | |
| 12009 | while (!list_empty(&queue->page_list)) { |
| 12010 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12011 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12012 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12013 | dmabuf->virt, dmabuf->phys); |
| 12014 | kfree(dmabuf); |
| 12015 | } |
| 12016 | kfree(queue); |
| 12017 | return; |
| 12018 | } |
| 12019 | |
| 12020 | /** |
| 12021 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12022 | * @phba: The HBA that this queue is being created on. |
| 12023 | * @entry_size: The size of each queue entry for this queue. |
| 12024 | * @entry count: The number of entries that this queue will handle. |
| 12025 | * |
| 12026 | * This function allocates a queue structure and the DMAable memory used for |
| 12027 | * the host resident queue. This function must be called before creating the |
| 12028 | * queue on the HBA. |
| 12029 | **/ |
| 12030 | struct lpfc_queue * |
| 12031 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12032 | uint32_t entry_count) |
| 12033 | { |
| 12034 | struct lpfc_queue *queue; |
| 12035 | struct lpfc_dmabuf *dmabuf; |
| 12036 | int x, total_qe_count; |
| 12037 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12038 | 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] | 12039 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12040 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12041 | hw_page_size = SLI4_PAGE_SIZE; |
| 12042 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12043 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 12044 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 12045 | if (!queue) |
| 12046 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12047 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 12048 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12049 | INIT_LIST_HEAD(&queue->list); |
| 12050 | INIT_LIST_HEAD(&queue->page_list); |
| 12051 | INIT_LIST_HEAD(&queue->child_list); |
| 12052 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 12053 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 12054 | if (!dmabuf) |
| 12055 | goto out_fail; |
| 12056 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12057 | hw_page_size, &dmabuf->phys, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12058 | GFP_KERNEL); |
| 12059 | if (!dmabuf->virt) { |
| 12060 | kfree(dmabuf); |
| 12061 | goto out_fail; |
| 12062 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12063 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12064 | dmabuf->buffer_tag = x; |
| 12065 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 12066 | /* initialize queue's entry array */ |
| 12067 | dma_pointer = dmabuf->virt; |
| 12068 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12069 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12070 | total_qe_count++, dma_pointer += entry_size) { |
| 12071 | queue->qe[total_qe_count].address = dma_pointer; |
| 12072 | } |
| 12073 | } |
| 12074 | queue->entry_size = entry_size; |
| 12075 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12076 | |
| 12077 | /* |
| 12078 | * entry_repost is calculated based on the number of entries in the |
| 12079 | * queue. This works out except for RQs. If buffers are NOT initially |
| 12080 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 12081 | */ |
| 12082 | queue->entry_repost = (entry_count >> 3); |
| 12083 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 12084 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12085 | queue->phba = phba; |
| 12086 | |
| 12087 | return queue; |
| 12088 | out_fail: |
| 12089 | lpfc_sli4_queue_free(queue); |
| 12090 | return NULL; |
| 12091 | } |
| 12092 | |
| 12093 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12094 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 12095 | * @phba: HBA structure that indicates port to create a queue on. |
| 12096 | * @startq: The starting FCP EQ to modify |
| 12097 | * |
| 12098 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 12099 | * |
| 12100 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 12101 | * is used to get the starting FCP EQ to change. |
| 12102 | * This function is asynchronous and will wait for the mailbox |
| 12103 | * command to finish before continuing. |
| 12104 | * |
| 12105 | * On success this function will return a zero. If unable to allocate enough |
| 12106 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12107 | * fails this function will return -ENXIO. |
| 12108 | **/ |
| 12109 | uint32_t |
| 12110 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) |
| 12111 | { |
| 12112 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 12113 | LPFC_MBOXQ_t *mbox; |
| 12114 | struct lpfc_queue *eq; |
| 12115 | int cnt, rc, length, status = 0; |
| 12116 | uint32_t shdr_status, shdr_add_status; |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12117 | uint32_t result; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12118 | int fcp_eqidx; |
| 12119 | union lpfc_sli4_cfg_shdr *shdr; |
| 12120 | uint16_t dmult; |
| 12121 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12122 | if (startq >= phba->cfg_fcp_io_channel) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12123 | return 0; |
| 12124 | |
| 12125 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12126 | if (!mbox) |
| 12127 | return -ENOMEM; |
| 12128 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 12129 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12130 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12131 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 12132 | length, LPFC_SLI4_MBX_EMBED); |
| 12133 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 12134 | |
| 12135 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12136 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
| 12137 | if (result > LPFC_DMULT_CONST) |
| 12138 | dmult = 0; |
| 12139 | else |
| 12140 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12141 | |
| 12142 | cnt = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12143 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12144 | fcp_eqidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12145 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12146 | if (!eq) |
| 12147 | continue; |
| 12148 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 12149 | eq_delay->u.request.eq[cnt].phase = 0; |
| 12150 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 12151 | cnt++; |
| 12152 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 12153 | break; |
| 12154 | } |
| 12155 | eq_delay->u.request.num_eq = cnt; |
| 12156 | |
| 12157 | mbox->vport = phba->pport; |
| 12158 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12159 | mbox->context1 = NULL; |
| 12160 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12161 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 12162 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12163 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12164 | if (shdr_status || shdr_add_status || rc) { |
| 12165 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12166 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 12167 | "status x%x add_status x%x, mbx status x%x\n", |
| 12168 | shdr_status, shdr_add_status, rc); |
| 12169 | status = -ENXIO; |
| 12170 | } |
| 12171 | mempool_free(mbox, phba->mbox_mem_pool); |
| 12172 | return status; |
| 12173 | } |
| 12174 | |
| 12175 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12176 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 12177 | * @phba: HBA structure that indicates port to create a queue on. |
| 12178 | * @eq: The queue structure to use to create the event queue. |
| 12179 | * @imax: The maximum interrupt per second limit. |
| 12180 | * |
| 12181 | * This function creates an event queue, as detailed in @eq, on a port, |
| 12182 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 12183 | * |
| 12184 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 12185 | * is used to get the entry count and entry size that are necessary to |
| 12186 | * determine the number of pages to allocate and use for this queue. This |
| 12187 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 12188 | * event queue. This function is asynchronous and will wait for the mailbox |
| 12189 | * command to finish before continuing. |
| 12190 | * |
| 12191 | * 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] | 12192 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12193 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12194 | **/ |
| 12195 | uint32_t |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12196 | 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] | 12197 | { |
| 12198 | struct lpfc_mbx_eq_create *eq_create; |
| 12199 | LPFC_MBOXQ_t *mbox; |
| 12200 | int rc, length, status = 0; |
| 12201 | struct lpfc_dmabuf *dmabuf; |
| 12202 | uint32_t shdr_status, shdr_add_status; |
| 12203 | union lpfc_sli4_cfg_shdr *shdr; |
| 12204 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12205 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12206 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12207 | /* sanity check on queue memory */ |
| 12208 | if (!eq) |
| 12209 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12210 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12211 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12212 | |
| 12213 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12214 | if (!mbox) |
| 12215 | return -ENOMEM; |
| 12216 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 12217 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12218 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12219 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 12220 | length, LPFC_SLI4_MBX_EMBED); |
| 12221 | eq_create = &mbox->u.mqe.un.eq_create; |
| 12222 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 12223 | eq->page_count); |
| 12224 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 12225 | LPFC_EQE_SIZE); |
| 12226 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
| 12227 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12228 | if (imax > LPFC_DMULT_CONST) |
| 12229 | dmult = 0; |
| 12230 | else |
| 12231 | dmult = LPFC_DMULT_CONST/imax - 1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12232 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 12233 | dmult); |
| 12234 | switch (eq->entry_count) { |
| 12235 | default: |
| 12236 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12237 | "0360 Unsupported EQ count. (%d)\n", |
| 12238 | eq->entry_count); |
| 12239 | if (eq->entry_count < 256) |
| 12240 | return -EINVAL; |
| 12241 | /* otherwise default to smallest count (drop through) */ |
| 12242 | case 256: |
| 12243 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12244 | LPFC_EQ_CNT_256); |
| 12245 | break; |
| 12246 | case 512: |
| 12247 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12248 | LPFC_EQ_CNT_512); |
| 12249 | break; |
| 12250 | case 1024: |
| 12251 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12252 | LPFC_EQ_CNT_1024); |
| 12253 | break; |
| 12254 | case 2048: |
| 12255 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12256 | LPFC_EQ_CNT_2048); |
| 12257 | break; |
| 12258 | case 4096: |
| 12259 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12260 | LPFC_EQ_CNT_4096); |
| 12261 | break; |
| 12262 | } |
| 12263 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12264 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12265 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12266 | putPaddrLow(dmabuf->phys); |
| 12267 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12268 | putPaddrHigh(dmabuf->phys); |
| 12269 | } |
| 12270 | mbox->vport = phba->pport; |
| 12271 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12272 | mbox->context1 = NULL; |
| 12273 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12274 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 12275 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12276 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12277 | if (shdr_status || shdr_add_status || rc) { |
| 12278 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12279 | "2500 EQ_CREATE mailbox failed with " |
| 12280 | "status x%x add_status x%x, mbx status x%x\n", |
| 12281 | shdr_status, shdr_add_status, rc); |
| 12282 | status = -ENXIO; |
| 12283 | } |
| 12284 | eq->type = LPFC_EQ; |
| 12285 | eq->subtype = LPFC_NONE; |
| 12286 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 12287 | if (eq->queue_id == 0xFFFF) |
| 12288 | status = -ENXIO; |
| 12289 | eq->host_index = 0; |
| 12290 | eq->hba_index = 0; |
| 12291 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12292 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12293 | return status; |
| 12294 | } |
| 12295 | |
| 12296 | /** |
| 12297 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 12298 | * @phba: HBA structure that indicates port to create a queue on. |
| 12299 | * @cq: The queue structure to use to create the completion queue. |
| 12300 | * @eq: The event queue to bind this completion queue to. |
| 12301 | * |
| 12302 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 12303 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 12304 | * |
| 12305 | * The @phba struct is used to send mailbox command to HBA. The @cq 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. The @eq |
| 12308 | * is used to indicate which event queue to bind this completion queue to. This |
| 12309 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 12310 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 12311 | * command to finish before continuing. |
| 12312 | * |
| 12313 | * 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] | 12314 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12315 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12316 | **/ |
| 12317 | uint32_t |
| 12318 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12319 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 12320 | { |
| 12321 | struct lpfc_mbx_cq_create *cq_create; |
| 12322 | struct lpfc_dmabuf *dmabuf; |
| 12323 | LPFC_MBOXQ_t *mbox; |
| 12324 | int rc, length, status = 0; |
| 12325 | uint32_t shdr_status, shdr_add_status; |
| 12326 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12327 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12328 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12329 | /* sanity check on queue memory */ |
| 12330 | if (!cq || !eq) |
| 12331 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12332 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12333 | hw_page_size = SLI4_PAGE_SIZE; |
| 12334 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12335 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12336 | if (!mbox) |
| 12337 | return -ENOMEM; |
| 12338 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 12339 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12340 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12341 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 12342 | length, LPFC_SLI4_MBX_EMBED); |
| 12343 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12344 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12345 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 12346 | cq->page_count); |
| 12347 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 12348 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12349 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12350 | phba->sli4_hba.pc_sli4_params.cqv); |
| 12351 | 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] | 12352 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 12353 | 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] | 12354 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 12355 | eq->queue_id); |
| 12356 | } else { |
| 12357 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 12358 | eq->queue_id); |
| 12359 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12360 | switch (cq->entry_count) { |
| 12361 | default: |
| 12362 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12363 | "0361 Unsupported CQ count. (%d)\n", |
| 12364 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12365 | if (cq->entry_count < 256) { |
| 12366 | status = -EINVAL; |
| 12367 | goto out; |
| 12368 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12369 | /* otherwise default to smallest count (drop through) */ |
| 12370 | case 256: |
| 12371 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12372 | LPFC_CQ_CNT_256); |
| 12373 | break; |
| 12374 | case 512: |
| 12375 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12376 | LPFC_CQ_CNT_512); |
| 12377 | break; |
| 12378 | case 1024: |
| 12379 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12380 | LPFC_CQ_CNT_1024); |
| 12381 | break; |
| 12382 | } |
| 12383 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12384 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12385 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12386 | putPaddrLow(dmabuf->phys); |
| 12387 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12388 | putPaddrHigh(dmabuf->phys); |
| 12389 | } |
| 12390 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12391 | |
| 12392 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12393 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12394 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12395 | if (shdr_status || shdr_add_status || rc) { |
| 12396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12397 | "2501 CQ_CREATE mailbox failed with " |
| 12398 | "status x%x add_status x%x, mbx status x%x\n", |
| 12399 | shdr_status, shdr_add_status, rc); |
| 12400 | status = -ENXIO; |
| 12401 | goto out; |
| 12402 | } |
| 12403 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 12404 | if (cq->queue_id == 0xFFFF) { |
| 12405 | status = -ENXIO; |
| 12406 | goto out; |
| 12407 | } |
| 12408 | /* link the cq onto the parent eq child list */ |
| 12409 | list_add_tail(&cq->list, &eq->child_list); |
| 12410 | /* Set up completion queue's type and subtype */ |
| 12411 | cq->type = type; |
| 12412 | cq->subtype = subtype; |
| 12413 | 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] | 12414 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12415 | cq->host_index = 0; |
| 12416 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12417 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12418 | out: |
| 12419 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12420 | return status; |
| 12421 | } |
| 12422 | |
| 12423 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12424 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12425 | * @phba: HBA structure that indicates port to create a queue on. |
| 12426 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12427 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 12428 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12429 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12430 | * This function provides failback (fb) functionality when the |
| 12431 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 12432 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12433 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12434 | * This routine cannot fail as all attributes were previously accessed and |
| 12435 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12436 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12437 | static void |
| 12438 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12439 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12440 | { |
| 12441 | struct lpfc_mbx_mq_create *mq_create; |
| 12442 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12443 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12444 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12445 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 12446 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12447 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12448 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 12449 | length, LPFC_SLI4_MBX_EMBED); |
| 12450 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12451 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12452 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12453 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12454 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12455 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 12456 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12457 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12458 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12459 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12460 | break; |
| 12461 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12462 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12463 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12464 | break; |
| 12465 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12466 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12467 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12468 | break; |
| 12469 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12470 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12471 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12472 | break; |
| 12473 | } |
| 12474 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 12475 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12476 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12477 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12478 | putPaddrHigh(dmabuf->phys); |
| 12479 | } |
| 12480 | } |
| 12481 | |
| 12482 | /** |
| 12483 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 12484 | * @phba: HBA structure that indicates port to create a queue on. |
| 12485 | * @mq: The queue structure to use to create the mailbox queue. |
| 12486 | * @cq: The completion queue to associate with this cq. |
| 12487 | * @subtype: The queue's subtype. |
| 12488 | * |
| 12489 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 12490 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 12491 | * |
| 12492 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12493 | * is used to get the entry count and entry size that are necessary to |
| 12494 | * determine the number of pages to allocate and use for this queue. This |
| 12495 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 12496 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 12497 | * command to finish before continuing. |
| 12498 | * |
| 12499 | * 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] | 12500 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12501 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12502 | **/ |
| 12503 | int32_t |
| 12504 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12505 | struct lpfc_queue *cq, uint32_t subtype) |
| 12506 | { |
| 12507 | struct lpfc_mbx_mq_create *mq_create; |
| 12508 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 12509 | struct lpfc_dmabuf *dmabuf; |
| 12510 | LPFC_MBOXQ_t *mbox; |
| 12511 | int rc, length, status = 0; |
| 12512 | uint32_t shdr_status, shdr_add_status; |
| 12513 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12514 | 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] | 12515 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12516 | /* sanity check on queue memory */ |
| 12517 | if (!mq || !cq) |
| 12518 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12519 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12520 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12521 | |
| 12522 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12523 | if (!mbox) |
| 12524 | return -ENOMEM; |
| 12525 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 12526 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12527 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12528 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 12529 | length, LPFC_SLI4_MBX_EMBED); |
| 12530 | |
| 12531 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12532 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12533 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 12534 | &mq_create_ext->u.request, mq->page_count); |
| 12535 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 12536 | &mq_create_ext->u.request, 1); |
| 12537 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12538 | &mq_create_ext->u.request, 1); |
| 12539 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 12540 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12541 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 12542 | &mq_create_ext->u.request, 1); |
| 12543 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 12544 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12545 | 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] | 12546 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12547 | phba->sli4_hba.pc_sli4_params.mqv); |
| 12548 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 12549 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 12550 | cq->queue_id); |
| 12551 | else |
| 12552 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 12553 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12554 | switch (mq->entry_count) { |
| 12555 | default: |
| 12556 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12557 | "0362 Unsupported MQ count. (%d)\n", |
| 12558 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12559 | if (mq->entry_count < 16) { |
| 12560 | status = -EINVAL; |
| 12561 | goto out; |
| 12562 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12563 | /* otherwise default to smallest count (drop through) */ |
| 12564 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12565 | bf_set(lpfc_mq_context_ring_size, |
| 12566 | &mq_create_ext->u.request.context, |
| 12567 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12568 | break; |
| 12569 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12570 | bf_set(lpfc_mq_context_ring_size, |
| 12571 | &mq_create_ext->u.request.context, |
| 12572 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12573 | break; |
| 12574 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12575 | bf_set(lpfc_mq_context_ring_size, |
| 12576 | &mq_create_ext->u.request.context, |
| 12577 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12578 | break; |
| 12579 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12580 | bf_set(lpfc_mq_context_ring_size, |
| 12581 | &mq_create_ext->u.request.context, |
| 12582 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12583 | break; |
| 12584 | } |
| 12585 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12586 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12587 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12588 | putPaddrLow(dmabuf->phys); |
| 12589 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12590 | putPaddrHigh(dmabuf->phys); |
| 12591 | } |
| 12592 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12593 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12594 | &mq_create_ext->u.response); |
| 12595 | if (rc != MBX_SUCCESS) { |
| 12596 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12597 | "2795 MQ_CREATE_EXT failed with " |
| 12598 | "status x%x. Failback to MQ_CREATE.\n", |
| 12599 | rc); |
| 12600 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 12601 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12602 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12603 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 12604 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12605 | &mq_create->u.response); |
| 12606 | } |
| 12607 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12608 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12609 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12610 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12611 | if (shdr_status || shdr_add_status || rc) { |
| 12612 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12613 | "2502 MQ_CREATE mailbox failed with " |
| 12614 | "status x%x add_status x%x, mbx status x%x\n", |
| 12615 | shdr_status, shdr_add_status, rc); |
| 12616 | status = -ENXIO; |
| 12617 | goto out; |
| 12618 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12619 | if (mq->queue_id == 0xFFFF) { |
| 12620 | status = -ENXIO; |
| 12621 | goto out; |
| 12622 | } |
| 12623 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12624 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12625 | mq->subtype = subtype; |
| 12626 | mq->host_index = 0; |
| 12627 | mq->hba_index = 0; |
| 12628 | |
| 12629 | /* link the mq onto the parent cq child list */ |
| 12630 | list_add_tail(&mq->list, &cq->child_list); |
| 12631 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12632 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12633 | return status; |
| 12634 | } |
| 12635 | |
| 12636 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12637 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 12638 | * @phba: HBA structure that indicates port to create a queue on. |
| 12639 | * @wq: The queue structure to use to create the work queue. |
| 12640 | * @cq: The completion queue to bind this work queue to. |
| 12641 | * @subtype: The subtype of the work queue indicating its functionality. |
| 12642 | * |
| 12643 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 12644 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 12645 | * |
| 12646 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 12647 | * is used to get the entry count and entry size that are necessary to |
| 12648 | * determine the number of pages to allocate and use for this queue. The @cq |
| 12649 | * is used to indicate which completion queue to bind this work queue to. This |
| 12650 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 12651 | * work queue. This function is asynchronous and will wait for the mailbox |
| 12652 | * command to finish before continuing. |
| 12653 | * |
| 12654 | * 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] | 12655 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12656 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12657 | **/ |
| 12658 | uint32_t |
| 12659 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 12660 | struct lpfc_queue *cq, uint32_t subtype) |
| 12661 | { |
| 12662 | struct lpfc_mbx_wq_create *wq_create; |
| 12663 | struct lpfc_dmabuf *dmabuf; |
| 12664 | LPFC_MBOXQ_t *mbox; |
| 12665 | int rc, length, status = 0; |
| 12666 | uint32_t shdr_status, shdr_add_status; |
| 12667 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12668 | 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] | 12669 | struct dma_address *page; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12670 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12671 | /* sanity check on queue memory */ |
| 12672 | if (!wq || !cq) |
| 12673 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12674 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12675 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12676 | |
| 12677 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12678 | if (!mbox) |
| 12679 | return -ENOMEM; |
| 12680 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 12681 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12682 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12683 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 12684 | length, LPFC_SLI4_MBX_EMBED); |
| 12685 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12686 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12687 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 12688 | wq->page_count); |
| 12689 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 12690 | cq->queue_id); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12691 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12692 | phba->sli4_hba.pc_sli4_params.wqv); |
| 12693 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { |
| 12694 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 12695 | wq->entry_count); |
| 12696 | switch (wq->entry_size) { |
| 12697 | default: |
| 12698 | case 64: |
| 12699 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12700 | &wq_create->u.request_1, |
| 12701 | LPFC_WQ_WQE_SIZE_64); |
| 12702 | break; |
| 12703 | case 128: |
| 12704 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12705 | &wq_create->u.request_1, |
| 12706 | LPFC_WQ_WQE_SIZE_128); |
| 12707 | break; |
| 12708 | } |
| 12709 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 12710 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 12711 | page = wq_create->u.request_1.page; |
| 12712 | } else { |
| 12713 | page = wq_create->u.request.page; |
| 12714 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12715 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12716 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12717 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 12718 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12719 | } |
| 12720 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12721 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12722 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12723 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12724 | if (shdr_status || shdr_add_status || rc) { |
| 12725 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12726 | "2503 WQ_CREATE mailbox failed with " |
| 12727 | "status x%x add_status x%x, mbx status x%x\n", |
| 12728 | shdr_status, shdr_add_status, rc); |
| 12729 | status = -ENXIO; |
| 12730 | goto out; |
| 12731 | } |
| 12732 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 12733 | if (wq->queue_id == 0xFFFF) { |
| 12734 | status = -ENXIO; |
| 12735 | goto out; |
| 12736 | } |
| 12737 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12738 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12739 | wq->subtype = subtype; |
| 12740 | wq->host_index = 0; |
| 12741 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12742 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12743 | |
| 12744 | /* link the wq onto the parent cq child list */ |
| 12745 | list_add_tail(&wq->list, &cq->child_list); |
| 12746 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12747 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12748 | return status; |
| 12749 | } |
| 12750 | |
| 12751 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12752 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 12753 | * @phba: HBA structure that indicates port to create a queue on. |
| 12754 | * @rq: The queue structure to use for the receive queue. |
| 12755 | * @qno: The associated HBQ number |
| 12756 | * |
| 12757 | * |
| 12758 | * For SLI4 we need to adjust the RQ repost value based on |
| 12759 | * the number of buffers that are initially posted to the RQ. |
| 12760 | */ |
| 12761 | void |
| 12762 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 12763 | { |
| 12764 | uint32_t cnt; |
| 12765 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12766 | /* sanity check on queue memory */ |
| 12767 | if (!rq) |
| 12768 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12769 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 12770 | |
| 12771 | /* Recalc repost for RQs based on buffers initially posted */ |
| 12772 | cnt = (cnt >> 3); |
| 12773 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 12774 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 12775 | |
| 12776 | rq->entry_repost = cnt; |
| 12777 | } |
| 12778 | |
| 12779 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12780 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 12781 | * @phba: HBA structure that indicates port to create a queue on. |
| 12782 | * @hrq: The queue structure to use to create the header receive queue. |
| 12783 | * @drq: The queue structure to use to create the data receive queue. |
| 12784 | * @cq: The completion queue to bind this work queue to. |
| 12785 | * |
| 12786 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 12787 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 12788 | * to the HBA. |
| 12789 | * |
| 12790 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 12791 | * struct is used to get the entry count that is necessary to determine the |
| 12792 | * number of pages to use for this queue. The @cq is used to indicate which |
| 12793 | * completion queue to bind received buffers that are posted to these queues to. |
| 12794 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 12795 | * receive queue pair. This function is asynchronous and will wait for the |
| 12796 | * mailbox command to finish before continuing. |
| 12797 | * |
| 12798 | * 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] | 12799 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12800 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12801 | **/ |
| 12802 | uint32_t |
| 12803 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 12804 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 12805 | { |
| 12806 | struct lpfc_mbx_rq_create *rq_create; |
| 12807 | struct lpfc_dmabuf *dmabuf; |
| 12808 | LPFC_MBOXQ_t *mbox; |
| 12809 | int rc, length, status = 0; |
| 12810 | uint32_t shdr_status, shdr_add_status; |
| 12811 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12812 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12813 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12814 | /* sanity check on queue memory */ |
| 12815 | if (!hrq || !drq || !cq) |
| 12816 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12817 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12818 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12819 | |
| 12820 | if (hrq->entry_count != drq->entry_count) |
| 12821 | return -EINVAL; |
| 12822 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12823 | if (!mbox) |
| 12824 | return -ENOMEM; |
| 12825 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 12826 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12827 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12828 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12829 | length, LPFC_SLI4_MBX_EMBED); |
| 12830 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12831 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12832 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12833 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12834 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12835 | bf_set(lpfc_rq_context_rqe_count_1, |
| 12836 | &rq_create->u.request.context, |
| 12837 | hrq->entry_count); |
| 12838 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12839 | bf_set(lpfc_rq_context_rqe_size, |
| 12840 | &rq_create->u.request.context, |
| 12841 | LPFC_RQE_SIZE_8); |
| 12842 | bf_set(lpfc_rq_context_page_size, |
| 12843 | &rq_create->u.request.context, |
| 12844 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12845 | } else { |
| 12846 | switch (hrq->entry_count) { |
| 12847 | default: |
| 12848 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12849 | "2535 Unsupported RQ count. (%d)\n", |
| 12850 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12851 | if (hrq->entry_count < 512) { |
| 12852 | status = -EINVAL; |
| 12853 | goto out; |
| 12854 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12855 | /* otherwise default to smallest count (drop through) */ |
| 12856 | case 512: |
| 12857 | bf_set(lpfc_rq_context_rqe_count, |
| 12858 | &rq_create->u.request.context, |
| 12859 | LPFC_RQ_RING_SIZE_512); |
| 12860 | break; |
| 12861 | case 1024: |
| 12862 | bf_set(lpfc_rq_context_rqe_count, |
| 12863 | &rq_create->u.request.context, |
| 12864 | LPFC_RQ_RING_SIZE_1024); |
| 12865 | break; |
| 12866 | case 2048: |
| 12867 | bf_set(lpfc_rq_context_rqe_count, |
| 12868 | &rq_create->u.request.context, |
| 12869 | LPFC_RQ_RING_SIZE_2048); |
| 12870 | break; |
| 12871 | case 4096: |
| 12872 | bf_set(lpfc_rq_context_rqe_count, |
| 12873 | &rq_create->u.request.context, |
| 12874 | LPFC_RQ_RING_SIZE_4096); |
| 12875 | break; |
| 12876 | } |
| 12877 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12878 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12879 | } |
| 12880 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12881 | cq->queue_id); |
| 12882 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12883 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12884 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12885 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12886 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12887 | putPaddrLow(dmabuf->phys); |
| 12888 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12889 | putPaddrHigh(dmabuf->phys); |
| 12890 | } |
| 12891 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12892 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12893 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12894 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12895 | if (shdr_status || shdr_add_status || rc) { |
| 12896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12897 | "2504 RQ_CREATE mailbox failed with " |
| 12898 | "status x%x add_status x%x, mbx status x%x\n", |
| 12899 | shdr_status, shdr_add_status, rc); |
| 12900 | status = -ENXIO; |
| 12901 | goto out; |
| 12902 | } |
| 12903 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12904 | if (hrq->queue_id == 0xFFFF) { |
| 12905 | status = -ENXIO; |
| 12906 | goto out; |
| 12907 | } |
| 12908 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12909 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12910 | hrq->subtype = subtype; |
| 12911 | hrq->host_index = 0; |
| 12912 | hrq->hba_index = 0; |
| 12913 | |
| 12914 | /* now create the data queue */ |
| 12915 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12916 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12917 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12918 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12919 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12920 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12921 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12922 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12923 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12924 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 12925 | LPFC_RQE_SIZE_8); |
| 12926 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 12927 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12928 | } else { |
| 12929 | switch (drq->entry_count) { |
| 12930 | default: |
| 12931 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12932 | "2536 Unsupported RQ count. (%d)\n", |
| 12933 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12934 | if (drq->entry_count < 512) { |
| 12935 | status = -EINVAL; |
| 12936 | goto out; |
| 12937 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12938 | /* otherwise default to smallest count (drop through) */ |
| 12939 | case 512: |
| 12940 | bf_set(lpfc_rq_context_rqe_count, |
| 12941 | &rq_create->u.request.context, |
| 12942 | LPFC_RQ_RING_SIZE_512); |
| 12943 | break; |
| 12944 | case 1024: |
| 12945 | bf_set(lpfc_rq_context_rqe_count, |
| 12946 | &rq_create->u.request.context, |
| 12947 | LPFC_RQ_RING_SIZE_1024); |
| 12948 | break; |
| 12949 | case 2048: |
| 12950 | bf_set(lpfc_rq_context_rqe_count, |
| 12951 | &rq_create->u.request.context, |
| 12952 | LPFC_RQ_RING_SIZE_2048); |
| 12953 | break; |
| 12954 | case 4096: |
| 12955 | bf_set(lpfc_rq_context_rqe_count, |
| 12956 | &rq_create->u.request.context, |
| 12957 | LPFC_RQ_RING_SIZE_4096); |
| 12958 | break; |
| 12959 | } |
| 12960 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12961 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12962 | } |
| 12963 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12964 | cq->queue_id); |
| 12965 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12966 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12967 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 12968 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12969 | putPaddrLow(dmabuf->phys); |
| 12970 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12971 | putPaddrHigh(dmabuf->phys); |
| 12972 | } |
| 12973 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12974 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12975 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12976 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12977 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12978 | if (shdr_status || shdr_add_status || rc) { |
| 12979 | status = -ENXIO; |
| 12980 | goto out; |
| 12981 | } |
| 12982 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12983 | if (drq->queue_id == 0xFFFF) { |
| 12984 | status = -ENXIO; |
| 12985 | goto out; |
| 12986 | } |
| 12987 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12988 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12989 | drq->subtype = subtype; |
| 12990 | drq->host_index = 0; |
| 12991 | drq->hba_index = 0; |
| 12992 | |
| 12993 | /* link the header and data RQs onto the parent cq child list */ |
| 12994 | list_add_tail(&hrq->list, &cq->child_list); |
| 12995 | list_add_tail(&drq->list, &cq->child_list); |
| 12996 | |
| 12997 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12998 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12999 | return status; |
| 13000 | } |
| 13001 | |
| 13002 | /** |
| 13003 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 13004 | * @eq: The queue structure associated with the queue to destroy. |
| 13005 | * |
| 13006 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 13007 | * command, specific to the type of queue, to the HBA. |
| 13008 | * |
| 13009 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 13010 | * |
| 13011 | * 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] | 13012 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13013 | **/ |
| 13014 | uint32_t |
| 13015 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13016 | { |
| 13017 | LPFC_MBOXQ_t *mbox; |
| 13018 | int rc, length, status = 0; |
| 13019 | uint32_t shdr_status, shdr_add_status; |
| 13020 | union lpfc_sli4_cfg_shdr *shdr; |
| 13021 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13022 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13023 | if (!eq) |
| 13024 | return -ENODEV; |
| 13025 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13026 | if (!mbox) |
| 13027 | return -ENOMEM; |
| 13028 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 13029 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13030 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13031 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 13032 | length, LPFC_SLI4_MBX_EMBED); |
| 13033 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 13034 | eq->queue_id); |
| 13035 | mbox->vport = eq->phba->pport; |
| 13036 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13037 | |
| 13038 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 13039 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13040 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13041 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 13042 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13043 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13044 | if (shdr_status || shdr_add_status || rc) { |
| 13045 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13046 | "2505 EQ_DESTROY mailbox failed with " |
| 13047 | "status x%x add_status x%x, mbx status x%x\n", |
| 13048 | shdr_status, shdr_add_status, rc); |
| 13049 | status = -ENXIO; |
| 13050 | } |
| 13051 | |
| 13052 | /* Remove eq from any list */ |
| 13053 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13054 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13055 | return status; |
| 13056 | } |
| 13057 | |
| 13058 | /** |
| 13059 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 13060 | * @cq: The queue structure associated with the queue to destroy. |
| 13061 | * |
| 13062 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 13063 | * command, specific to the type of queue, to the HBA. |
| 13064 | * |
| 13065 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 13066 | * |
| 13067 | * 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] | 13068 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13069 | **/ |
| 13070 | uint32_t |
| 13071 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 13072 | { |
| 13073 | LPFC_MBOXQ_t *mbox; |
| 13074 | int rc, length, status = 0; |
| 13075 | uint32_t shdr_status, shdr_add_status; |
| 13076 | union lpfc_sli4_cfg_shdr *shdr; |
| 13077 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13078 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13079 | if (!cq) |
| 13080 | return -ENODEV; |
| 13081 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13082 | if (!mbox) |
| 13083 | return -ENOMEM; |
| 13084 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 13085 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13086 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13087 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 13088 | length, LPFC_SLI4_MBX_EMBED); |
| 13089 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 13090 | cq->queue_id); |
| 13091 | mbox->vport = cq->phba->pport; |
| 13092 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13093 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 13094 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13095 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13096 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 13097 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13098 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13099 | if (shdr_status || shdr_add_status || rc) { |
| 13100 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13101 | "2506 CQ_DESTROY mailbox failed with " |
| 13102 | "status x%x add_status x%x, mbx status x%x\n", |
| 13103 | shdr_status, shdr_add_status, rc); |
| 13104 | status = -ENXIO; |
| 13105 | } |
| 13106 | /* Remove cq from any list */ |
| 13107 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13108 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13109 | return status; |
| 13110 | } |
| 13111 | |
| 13112 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13113 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 13114 | * @qm: The queue structure associated with the queue to destroy. |
| 13115 | * |
| 13116 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 13117 | * command, specific to the type of queue, to the HBA. |
| 13118 | * |
| 13119 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 13120 | * |
| 13121 | * 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] | 13122 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13123 | **/ |
| 13124 | uint32_t |
| 13125 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 13126 | { |
| 13127 | LPFC_MBOXQ_t *mbox; |
| 13128 | int rc, length, status = 0; |
| 13129 | uint32_t shdr_status, shdr_add_status; |
| 13130 | union lpfc_sli4_cfg_shdr *shdr; |
| 13131 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13132 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13133 | if (!mq) |
| 13134 | return -ENODEV; |
| 13135 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13136 | if (!mbox) |
| 13137 | return -ENOMEM; |
| 13138 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 13139 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13140 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13141 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 13142 | length, LPFC_SLI4_MBX_EMBED); |
| 13143 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 13144 | mq->queue_id); |
| 13145 | mbox->vport = mq->phba->pport; |
| 13146 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13147 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 13148 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13149 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13150 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 13151 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13152 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13153 | if (shdr_status || shdr_add_status || rc) { |
| 13154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13155 | "2507 MQ_DESTROY mailbox failed with " |
| 13156 | "status x%x add_status x%x, mbx status x%x\n", |
| 13157 | shdr_status, shdr_add_status, rc); |
| 13158 | status = -ENXIO; |
| 13159 | } |
| 13160 | /* Remove mq from any list */ |
| 13161 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13162 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13163 | return status; |
| 13164 | } |
| 13165 | |
| 13166 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13167 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 13168 | * @wq: The queue structure associated with the queue to destroy. |
| 13169 | * |
| 13170 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 13171 | * command, specific to the type of queue, to the HBA. |
| 13172 | * |
| 13173 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 13174 | * |
| 13175 | * 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] | 13176 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13177 | **/ |
| 13178 | uint32_t |
| 13179 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 13180 | { |
| 13181 | LPFC_MBOXQ_t *mbox; |
| 13182 | int rc, length, status = 0; |
| 13183 | uint32_t shdr_status, shdr_add_status; |
| 13184 | union lpfc_sli4_cfg_shdr *shdr; |
| 13185 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13186 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13187 | if (!wq) |
| 13188 | return -ENODEV; |
| 13189 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13190 | if (!mbox) |
| 13191 | return -ENOMEM; |
| 13192 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 13193 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13194 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13195 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 13196 | length, LPFC_SLI4_MBX_EMBED); |
| 13197 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 13198 | wq->queue_id); |
| 13199 | mbox->vport = wq->phba->pport; |
| 13200 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13201 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 13202 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13203 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 13204 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13205 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13206 | if (shdr_status || shdr_add_status || rc) { |
| 13207 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13208 | "2508 WQ_DESTROY mailbox failed with " |
| 13209 | "status x%x add_status x%x, mbx status x%x\n", |
| 13210 | shdr_status, shdr_add_status, rc); |
| 13211 | status = -ENXIO; |
| 13212 | } |
| 13213 | /* Remove wq from any list */ |
| 13214 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13215 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13216 | return status; |
| 13217 | } |
| 13218 | |
| 13219 | /** |
| 13220 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 13221 | * @rq: The queue structure associated with the queue to destroy. |
| 13222 | * |
| 13223 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 13224 | * command, specific to the type of queue, to the HBA. |
| 13225 | * |
| 13226 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 13227 | * |
| 13228 | * 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] | 13229 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13230 | **/ |
| 13231 | uint32_t |
| 13232 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13233 | struct lpfc_queue *drq) |
| 13234 | { |
| 13235 | LPFC_MBOXQ_t *mbox; |
| 13236 | int rc, length, status = 0; |
| 13237 | uint32_t shdr_status, shdr_add_status; |
| 13238 | union lpfc_sli4_cfg_shdr *shdr; |
| 13239 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13240 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13241 | if (!hrq || !drq) |
| 13242 | return -ENODEV; |
| 13243 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13244 | if (!mbox) |
| 13245 | return -ENOMEM; |
| 13246 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13247 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13248 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13249 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 13250 | length, LPFC_SLI4_MBX_EMBED); |
| 13251 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13252 | hrq->queue_id); |
| 13253 | mbox->vport = hrq->phba->pport; |
| 13254 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13255 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 13256 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13257 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13258 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13259 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13260 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13261 | if (shdr_status || shdr_add_status || rc) { |
| 13262 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13263 | "2509 RQ_DESTROY mailbox failed with " |
| 13264 | "status x%x add_status x%x, mbx status x%x\n", |
| 13265 | shdr_status, shdr_add_status, rc); |
| 13266 | if (rc != MBX_TIMEOUT) |
| 13267 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 13268 | return -ENXIO; |
| 13269 | } |
| 13270 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13271 | drq->queue_id); |
| 13272 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 13273 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13274 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13275 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13276 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13277 | if (shdr_status || shdr_add_status || rc) { |
| 13278 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13279 | "2510 RQ_DESTROY mailbox failed with " |
| 13280 | "status x%x add_status x%x, mbx status x%x\n", |
| 13281 | shdr_status, shdr_add_status, rc); |
| 13282 | status = -ENXIO; |
| 13283 | } |
| 13284 | list_del_init(&hrq->list); |
| 13285 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13286 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13287 | return status; |
| 13288 | } |
| 13289 | |
| 13290 | /** |
| 13291 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 13292 | * @phba: The virtual port for which this call being executed. |
| 13293 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 13294 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 13295 | * @xritag: the xritag that ties this io to the SGL pages. |
| 13296 | * |
| 13297 | * This routine will post the sgl pages for the IO that has the xritag |
| 13298 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 13299 | * creation and persists for as long as the driver is loaded. |
| 13300 | * if the caller has fewer than 256 scatter gather segments to map then |
| 13301 | * pdma_phys_addr1 should be 0. |
| 13302 | * If the caller needs to map more than 256 scatter gather segment then |
| 13303 | * pdma_phys_addr1 should be a valid physical address. |
| 13304 | * physical address for SGLs must be 64 byte aligned. |
| 13305 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 13306 | * the second sgl can have between 1 and 256 entries. |
| 13307 | * |
| 13308 | * Return codes: |
| 13309 | * 0 - Success |
| 13310 | * -ENXIO, -ENOMEM - Failure |
| 13311 | **/ |
| 13312 | int |
| 13313 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 13314 | dma_addr_t pdma_phys_addr0, |
| 13315 | dma_addr_t pdma_phys_addr1, |
| 13316 | uint16_t xritag) |
| 13317 | { |
| 13318 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 13319 | LPFC_MBOXQ_t *mbox; |
| 13320 | int rc; |
| 13321 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13322 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13323 | union lpfc_sli4_cfg_shdr *shdr; |
| 13324 | |
| 13325 | if (xritag == NO_XRI) { |
| 13326 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13327 | "0364 Invalid param:\n"); |
| 13328 | return -EINVAL; |
| 13329 | } |
| 13330 | |
| 13331 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13332 | if (!mbox) |
| 13333 | return -ENOMEM; |
| 13334 | |
| 13335 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13336 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13337 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13338 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13339 | |
| 13340 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 13341 | &mbox->u.mqe.un.post_sgl_pages; |
| 13342 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 13343 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 13344 | |
| 13345 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 13346 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 13347 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 13348 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 13349 | |
| 13350 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 13351 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 13352 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 13353 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 13354 | if (!phba->sli4_hba.intr_enable) |
| 13355 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13356 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13357 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13358 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13359 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13360 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13361 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 13362 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13363 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13364 | if (rc != MBX_TIMEOUT) |
| 13365 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13366 | if (shdr_status || shdr_add_status || rc) { |
| 13367 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13368 | "2511 POST_SGL mailbox failed with " |
| 13369 | "status x%x add_status x%x, mbx status x%x\n", |
| 13370 | shdr_status, shdr_add_status, rc); |
| 13371 | rc = -ENXIO; |
| 13372 | } |
| 13373 | return 0; |
| 13374 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13375 | |
| 13376 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13377 | * 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] | 13378 | * @phba: pointer to lpfc hba data structure. |
| 13379 | * |
| 13380 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13381 | * HBA consistent with the SLI-4 interface spec. This routine |
| 13382 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 13383 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13384 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13385 | * Returns |
| 13386 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 13387 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 13388 | **/ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13389 | uint16_t |
| 13390 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 13391 | { |
| 13392 | unsigned long xri; |
| 13393 | |
| 13394 | /* |
| 13395 | * Fetch the next logical xri. Because this index is logical, |
| 13396 | * the driver starts at 0 each time. |
| 13397 | */ |
| 13398 | spin_lock_irq(&phba->hbalock); |
| 13399 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 13400 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 13401 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 13402 | spin_unlock_irq(&phba->hbalock); |
| 13403 | return NO_XRI; |
| 13404 | } else { |
| 13405 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 13406 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13407 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13408 | spin_unlock_irq(&phba->hbalock); |
| 13409 | return xri; |
| 13410 | } |
| 13411 | |
| 13412 | /** |
| 13413 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13414 | * @phba: pointer to lpfc hba data structure. |
| 13415 | * |
| 13416 | * This routine is invoked to release an xri to the pool of |
| 13417 | * available rpis maintained by the driver. |
| 13418 | **/ |
| 13419 | void |
| 13420 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13421 | { |
| 13422 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13423 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 13424 | } |
| 13425 | } |
| 13426 | |
| 13427 | /** |
| 13428 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13429 | * @phba: pointer to lpfc hba data structure. |
| 13430 | * |
| 13431 | * This routine is invoked to release an xri to the pool of |
| 13432 | * available rpis maintained by the driver. |
| 13433 | **/ |
| 13434 | void |
| 13435 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13436 | { |
| 13437 | spin_lock_irq(&phba->hbalock); |
| 13438 | __lpfc_sli4_free_xri(phba, xri); |
| 13439 | spin_unlock_irq(&phba->hbalock); |
| 13440 | } |
| 13441 | |
| 13442 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13443 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 13444 | * @phba: Pointer to HBA context object. |
| 13445 | * |
| 13446 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 13447 | * it will return 0xffff. |
| 13448 | * The function returns the allocated xritag if successful, else returns zero. |
| 13449 | * Zero is not a valid xritag. |
| 13450 | * The caller is not required to hold any lock. |
| 13451 | **/ |
| 13452 | uint16_t |
| 13453 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 13454 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13455 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13456 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13457 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 13458 | if (xri_index == NO_XRI) |
| 13459 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13460 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 13461 | " Max XRI is %d, Used XRI is %d\n", |
| 13462 | xri_index, |
| 13463 | phba->sli4_hba.max_cfg_param.max_xri, |
| 13464 | phba->sli4_hba.max_cfg_param.xri_used); |
| 13465 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13466 | } |
| 13467 | |
| 13468 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13469 | * 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] | 13470 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13471 | * @post_sgl_list: pointer to els sgl entry list. |
| 13472 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13473 | * |
| 13474 | * This routine is invoked to post a block of driver's sgl pages to the |
| 13475 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 13476 | * is only called when the driver is loading and after all IO has been |
| 13477 | * stopped. |
| 13478 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13479 | static int |
| 13480 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 13481 | struct list_head *post_sgl_list, |
| 13482 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13483 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13484 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13485 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13486 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13487 | void *viraddr; |
| 13488 | LPFC_MBOXQ_t *mbox; |
| 13489 | uint32_t reqlen, alloclen, pg_pairs; |
| 13490 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13491 | uint16_t xritag_start = 0; |
| 13492 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13493 | uint32_t shdr_status, shdr_add_status; |
| 13494 | union lpfc_sli4_cfg_shdr *shdr; |
| 13495 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13496 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13497 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13498 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13499 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13500 | "2559 Block sgl registration required DMA " |
| 13501 | "size (%d) great than a page\n", reqlen); |
| 13502 | return -ENOMEM; |
| 13503 | } |
| 13504 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13505 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13506 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13507 | |
| 13508 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13509 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13510 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13511 | LPFC_SLI4_MBX_NEMBED); |
| 13512 | |
| 13513 | if (alloclen < reqlen) { |
| 13514 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13515 | "0285 Allocated DMA memory size (%d) is " |
| 13516 | "less than the requested DMA memory " |
| 13517 | "size (%d)\n", alloclen, reqlen); |
| 13518 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13519 | return -ENOMEM; |
| 13520 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13521 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13522 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13523 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13524 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13525 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13526 | pg_pairs = 0; |
| 13527 | 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] | 13528 | /* Set up the sge entry */ |
| 13529 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13530 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 13531 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13532 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 13533 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13534 | cpu_to_le32(putPaddrLow(0)); |
| 13535 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13536 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13537 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13538 | /* Keep the first xritag on the list */ |
| 13539 | if (pg_pairs == 0) |
| 13540 | xritag_start = sglq_entry->sli4_xritag; |
| 13541 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13542 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13543 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13544 | |
| 13545 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13546 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13547 | 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] | 13548 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13549 | if (!phba->sli4_hba.intr_enable) |
| 13550 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13551 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13552 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13553 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13554 | } |
| 13555 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13556 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13557 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13558 | if (rc != MBX_TIMEOUT) |
| 13559 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13560 | if (shdr_status || shdr_add_status || rc) { |
| 13561 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13562 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 13563 | "status x%x add_status x%x mbx status x%x\n", |
| 13564 | shdr_status, shdr_add_status, rc); |
| 13565 | rc = -ENXIO; |
| 13566 | } |
| 13567 | return rc; |
| 13568 | } |
| 13569 | |
| 13570 | /** |
| 13571 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 13572 | * @phba: pointer to lpfc hba data structure. |
| 13573 | * @sblist: pointer to scsi buffer list. |
| 13574 | * @count: number of scsi buffers on the list. |
| 13575 | * |
| 13576 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 13577 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 13578 | * No Lock is held. |
| 13579 | * |
| 13580 | **/ |
| 13581 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13582 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 13583 | struct list_head *sblist, |
| 13584 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13585 | { |
| 13586 | struct lpfc_scsi_buf *psb; |
| 13587 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13588 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13589 | void *viraddr; |
| 13590 | LPFC_MBOXQ_t *mbox; |
| 13591 | uint32_t reqlen, alloclen, pg_pairs; |
| 13592 | uint32_t mbox_tmo; |
| 13593 | uint16_t xritag_start = 0; |
| 13594 | int rc = 0; |
| 13595 | uint32_t shdr_status, shdr_add_status; |
| 13596 | dma_addr_t pdma_phys_bpl1; |
| 13597 | union lpfc_sli4_cfg_shdr *shdr; |
| 13598 | |
| 13599 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13600 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13601 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13602 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13603 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13604 | "0217 Block sgl registration required DMA " |
| 13605 | "size (%d) great than a page\n", reqlen); |
| 13606 | return -ENOMEM; |
| 13607 | } |
| 13608 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13609 | if (!mbox) { |
| 13610 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13611 | "0283 Failed to allocate mbox cmd memory\n"); |
| 13612 | return -ENOMEM; |
| 13613 | } |
| 13614 | |
| 13615 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13616 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13617 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13618 | LPFC_SLI4_MBX_NEMBED); |
| 13619 | |
| 13620 | if (alloclen < reqlen) { |
| 13621 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13622 | "2561 Allocated DMA memory size (%d) is " |
| 13623 | "less than the requested DMA memory " |
| 13624 | "size (%d)\n", alloclen, reqlen); |
| 13625 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13626 | return -ENOMEM; |
| 13627 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13628 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13629 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13630 | viraddr = mbox->sge_array->addr[0]; |
| 13631 | |
| 13632 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 13633 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13634 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13635 | |
| 13636 | pg_pairs = 0; |
| 13637 | list_for_each_entry(psb, sblist, list) { |
| 13638 | /* Set up the sge entry */ |
| 13639 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13640 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 13641 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13642 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 13643 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 13644 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 13645 | else |
| 13646 | pdma_phys_bpl1 = 0; |
| 13647 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13648 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 13649 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13650 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 13651 | /* Keep the first xritag on the list */ |
| 13652 | if (pg_pairs == 0) |
| 13653 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 13654 | sgl_pg_pairs++; |
| 13655 | pg_pairs++; |
| 13656 | } |
| 13657 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 13658 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 13659 | /* Perform endian conversion if necessary */ |
| 13660 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 13661 | |
| 13662 | if (!phba->sli4_hba.intr_enable) |
| 13663 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13664 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13665 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13666 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13667 | } |
| 13668 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13669 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13670 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13671 | if (rc != MBX_TIMEOUT) |
| 13672 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13673 | if (shdr_status || shdr_add_status || rc) { |
| 13674 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13675 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 13676 | "status x%x add_status x%x mbx status x%x\n", |
| 13677 | shdr_status, shdr_add_status, rc); |
| 13678 | rc = -ENXIO; |
| 13679 | } |
| 13680 | return rc; |
| 13681 | } |
| 13682 | |
| 13683 | /** |
| 13684 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 13685 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 13686 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13687 | * |
| 13688 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 13689 | * valid type of frame that the LPFC driver will handle. This function will |
| 13690 | * return a zero if the frame is a valid frame or a non zero value when the |
| 13691 | * frame does not pass the check. |
| 13692 | **/ |
| 13693 | static int |
| 13694 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 13695 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 13696 | /* make rctl_names static to save stack space */ |
| 13697 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13698 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 13699 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13700 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13701 | |
| 13702 | switch (fc_hdr->fh_r_ctl) { |
| 13703 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 13704 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 13705 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 13706 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 13707 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 13708 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 13709 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 13710 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 13711 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 13712 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 13713 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 13714 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 13715 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 13716 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 13717 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 13718 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 13719 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 13720 | case FC_RCTL_BA_PRMT: |
| 13721 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 13722 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 13723 | case FC_RCTL_P_RJT: /* port reject */ |
| 13724 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 13725 | case FC_RCTL_P_BSY: /* port busy */ |
| 13726 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 13727 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 13728 | case FC_RCTL_LCR: /* link credit reset */ |
| 13729 | case FC_RCTL_END: /* end */ |
| 13730 | break; |
| 13731 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 13732 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13733 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 13734 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 13735 | default: |
| 13736 | goto drop; |
| 13737 | } |
| 13738 | switch (fc_hdr->fh_type) { |
| 13739 | case FC_TYPE_BLS: |
| 13740 | case FC_TYPE_ELS: |
| 13741 | case FC_TYPE_FCP: |
| 13742 | case FC_TYPE_CT: |
| 13743 | break; |
| 13744 | case FC_TYPE_IP: |
| 13745 | case FC_TYPE_ILS: |
| 13746 | default: |
| 13747 | goto drop; |
| 13748 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13749 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13750 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13751 | "2538 Received frame rctl:%s type:%s " |
| 13752 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13753 | rctl_names[fc_hdr->fh_r_ctl], |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13754 | type_names[fc_hdr->fh_type], |
| 13755 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 13756 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 13757 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13758 | return 0; |
| 13759 | drop: |
| 13760 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 13761 | "2539 Dropped frame rctl:%s type:%s\n", |
| 13762 | rctl_names[fc_hdr->fh_r_ctl], |
| 13763 | type_names[fc_hdr->fh_type]); |
| 13764 | return 1; |
| 13765 | } |
| 13766 | |
| 13767 | /** |
| 13768 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 13769 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13770 | * |
| 13771 | * This function processes the FC header to retrieve the VFI from the VF |
| 13772 | * header, if one exists. This function will return the VFI if one exists |
| 13773 | * or 0 if no VSAN Header exists. |
| 13774 | **/ |
| 13775 | static uint32_t |
| 13776 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 13777 | { |
| 13778 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13779 | |
| 13780 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 13781 | return 0; |
| 13782 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 13783 | } |
| 13784 | |
| 13785 | /** |
| 13786 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 13787 | * @phba: Pointer to the HBA structure to search for the vport on |
| 13788 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13789 | * @fcfi: The FC Fabric ID that the frame came from |
| 13790 | * |
| 13791 | * This function searches the @phba for a vport that matches the content of the |
| 13792 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 13793 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 13794 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 13795 | * vport. |
| 13796 | **/ |
| 13797 | static struct lpfc_vport * |
| 13798 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 13799 | uint16_t fcfi) |
| 13800 | { |
| 13801 | struct lpfc_vport **vports; |
| 13802 | struct lpfc_vport *vport = NULL; |
| 13803 | int i; |
| 13804 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 13805 | fc_hdr->fh_d_id[1] << 8 | |
| 13806 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 13807 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 13808 | if (did == Fabric_DID) |
| 13809 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 13810 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 13811 | !(phba->link_state == LPFC_HBA_READY)) |
| 13812 | return phba->pport; |
| 13813 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13814 | vports = lpfc_create_vport_work_array(phba); |
| 13815 | if (vports != NULL) |
| 13816 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 13817 | if (phba->fcf.fcfi == fcfi && |
| 13818 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 13819 | vports[i]->fc_myDID == did) { |
| 13820 | vport = vports[i]; |
| 13821 | break; |
| 13822 | } |
| 13823 | } |
| 13824 | lpfc_destroy_vport_work_array(phba, vports); |
| 13825 | return vport; |
| 13826 | } |
| 13827 | |
| 13828 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13829 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 13830 | * @vport: The vport to work on. |
| 13831 | * |
| 13832 | * This function updates the receive sequence time stamp for this vport. The |
| 13833 | * receive sequence time stamp indicates the time that the last frame of the |
| 13834 | * the sequence that has been idle for the longest amount of time was received. |
| 13835 | * the driver uses this time stamp to indicate if any received sequences have |
| 13836 | * timed out. |
| 13837 | **/ |
| 13838 | void |
| 13839 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 13840 | { |
| 13841 | struct lpfc_dmabuf *h_buf; |
| 13842 | struct hbq_dmabuf *dmabuf = NULL; |
| 13843 | |
| 13844 | /* get the oldest sequence on the rcv list */ |
| 13845 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 13846 | struct lpfc_dmabuf, list); |
| 13847 | if (!h_buf) |
| 13848 | return; |
| 13849 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13850 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 13851 | } |
| 13852 | |
| 13853 | /** |
| 13854 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 13855 | * @vport: The vport that the received sequences were sent to. |
| 13856 | * |
| 13857 | * This function cleans up all outstanding received sequences. This is called |
| 13858 | * by the driver when a link event or user action invalidates all the received |
| 13859 | * sequences. |
| 13860 | **/ |
| 13861 | void |
| 13862 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 13863 | { |
| 13864 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13865 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13866 | struct hbq_dmabuf *dmabuf = NULL; |
| 13867 | |
| 13868 | /* start with the oldest sequence on the rcv list */ |
| 13869 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13870 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13871 | list_del_init(&dmabuf->hbuf.list); |
| 13872 | list_for_each_entry_safe(d_buf, dnext, |
| 13873 | &dmabuf->dbuf.list, list) { |
| 13874 | list_del_init(&d_buf->list); |
| 13875 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13876 | } |
| 13877 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13878 | } |
| 13879 | } |
| 13880 | |
| 13881 | /** |
| 13882 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 13883 | * @vport: The vport that the received sequences were sent to. |
| 13884 | * |
| 13885 | * This function determines whether any received sequences have timed out by |
| 13886 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 13887 | * indicates that there is at least one timed out sequence this routine will |
| 13888 | * go through the received sequences one at a time from most inactive to most |
| 13889 | * active to determine which ones need to be cleaned up. Once it has determined |
| 13890 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 13891 | * without sending an abort. |
| 13892 | **/ |
| 13893 | void |
| 13894 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 13895 | { |
| 13896 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13897 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13898 | struct hbq_dmabuf *dmabuf = NULL; |
| 13899 | unsigned long timeout; |
| 13900 | int abort_count = 0; |
| 13901 | |
| 13902 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13903 | vport->rcv_buffer_time_stamp); |
| 13904 | if (list_empty(&vport->rcv_buffer_list) || |
| 13905 | time_before(jiffies, timeout)) |
| 13906 | return; |
| 13907 | /* start with the oldest sequence on the rcv list */ |
| 13908 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13909 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13910 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13911 | dmabuf->time_stamp); |
| 13912 | if (time_before(jiffies, timeout)) |
| 13913 | break; |
| 13914 | abort_count++; |
| 13915 | list_del_init(&dmabuf->hbuf.list); |
| 13916 | list_for_each_entry_safe(d_buf, dnext, |
| 13917 | &dmabuf->dbuf.list, list) { |
| 13918 | list_del_init(&d_buf->list); |
| 13919 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13920 | } |
| 13921 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13922 | } |
| 13923 | if (abort_count) |
| 13924 | lpfc_update_rcv_time_stamp(vport); |
| 13925 | } |
| 13926 | |
| 13927 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13928 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 13929 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 13930 | * |
| 13931 | * This function searches through the existing incomplete sequences that have |
| 13932 | * been sent to this @vport. If the frame matches one of the incomplete |
| 13933 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 13934 | * make up that sequence. If no sequence is found that matches this frame then |
| 13935 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 13936 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 13937 | * the frame was linked to. |
| 13938 | **/ |
| 13939 | static struct hbq_dmabuf * |
| 13940 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 13941 | { |
| 13942 | struct fc_frame_header *new_hdr; |
| 13943 | struct fc_frame_header *temp_hdr; |
| 13944 | struct lpfc_dmabuf *d_buf; |
| 13945 | struct lpfc_dmabuf *h_buf; |
| 13946 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 13947 | struct hbq_dmabuf *temp_dmabuf = NULL; |
| 13948 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13949 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13950 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13951 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 13952 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 13953 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 13954 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 13955 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 13956 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 13957 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 13958 | continue; |
| 13959 | /* found a pending sequence that matches this frame */ |
| 13960 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13961 | break; |
| 13962 | } |
| 13963 | if (!seq_dmabuf) { |
| 13964 | /* |
| 13965 | * This indicates first frame received for this sequence. |
| 13966 | * Queue the buffer on the vport's rcv_buffer_list. |
| 13967 | */ |
| 13968 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13969 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13970 | return dmabuf; |
| 13971 | } |
| 13972 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13973 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 13974 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13975 | list_del_init(&seq_dmabuf->hbuf.list); |
| 13976 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 13977 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13978 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13979 | return dmabuf; |
| 13980 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13981 | /* move this sequence to the tail to indicate a young sequence */ |
| 13982 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 13983 | seq_dmabuf->time_stamp = jiffies; |
| 13984 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13985 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 13986 | temp_hdr = dmabuf->hbuf.virt; |
| 13987 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 13988 | return seq_dmabuf; |
| 13989 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13990 | /* find the correct place in the sequence to insert this frame */ |
| 13991 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { |
| 13992 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 13993 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 13994 | /* |
| 13995 | * If the frame's sequence count is greater than the frame on |
| 13996 | * the list then insert the frame right after this frame |
| 13997 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13998 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 13999 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14000 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
| 14001 | return seq_dmabuf; |
| 14002 | } |
| 14003 | } |
| 14004 | return NULL; |
| 14005 | } |
| 14006 | |
| 14007 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14008 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 14009 | * @vport: pointer to a vitural port |
| 14010 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14011 | * |
| 14012 | * This function tries to abort from the partially assembed sequence, described |
| 14013 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 14014 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 14015 | * the frames from the partially assembled sequence. |
| 14016 | * |
| 14017 | * Return |
| 14018 | * true -- if there is matching partially assembled sequence present and all |
| 14019 | * the frames freed with the sequence; |
| 14020 | * false -- if there is no matching partially assembled sequence present so |
| 14021 | * nothing got aborted in the lower layer driver |
| 14022 | **/ |
| 14023 | static bool |
| 14024 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 14025 | struct hbq_dmabuf *dmabuf) |
| 14026 | { |
| 14027 | struct fc_frame_header *new_hdr; |
| 14028 | struct fc_frame_header *temp_hdr; |
| 14029 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 14030 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14031 | |
| 14032 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 14033 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 14034 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 14035 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14036 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14037 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14038 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14039 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14040 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14041 | continue; |
| 14042 | /* found a pending sequence that matches this frame */ |
| 14043 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14044 | break; |
| 14045 | } |
| 14046 | |
| 14047 | /* Free up all the frames from the partially assembled sequence */ |
| 14048 | if (seq_dmabuf) { |
| 14049 | list_for_each_entry_safe(d_buf, n_buf, |
| 14050 | &seq_dmabuf->dbuf.list, list) { |
| 14051 | list_del_init(&d_buf->list); |
| 14052 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14053 | } |
| 14054 | return true; |
| 14055 | } |
| 14056 | return false; |
| 14057 | } |
| 14058 | |
| 14059 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14060 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 14061 | * @vport: pointer to a vitural port |
| 14062 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14063 | * |
| 14064 | * This function tries to abort from the assembed sequence from upper level |
| 14065 | * protocol, described by the information from basic abbort @dmabuf. It |
| 14066 | * checks to see whether such pending context exists at upper level protocol. |
| 14067 | * If so, it shall clean up the pending context. |
| 14068 | * |
| 14069 | * Return |
| 14070 | * true -- if there is matching pending context of the sequence cleaned |
| 14071 | * at ulp; |
| 14072 | * false -- if there is no matching pending context of the sequence present |
| 14073 | * at ulp. |
| 14074 | **/ |
| 14075 | static bool |
| 14076 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 14077 | { |
| 14078 | struct lpfc_hba *phba = vport->phba; |
| 14079 | int handled; |
| 14080 | |
| 14081 | /* Accepting abort at ulp with SLI4 only */ |
| 14082 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 14083 | return false; |
| 14084 | |
| 14085 | /* Register all caring upper level protocols to attend abort */ |
| 14086 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 14087 | if (handled) |
| 14088 | return true; |
| 14089 | |
| 14090 | return false; |
| 14091 | } |
| 14092 | |
| 14093 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14094 | * 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] | 14095 | * @phba: Pointer to HBA context object. |
| 14096 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 14097 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 14098 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14099 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14100 | * event. It properly releases the memory allocated to the sequence abort |
| 14101 | * accept iocb. |
| 14102 | **/ |
| 14103 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14104 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14105 | struct lpfc_iocbq *cmd_iocbq, |
| 14106 | struct lpfc_iocbq *rsp_iocbq) |
| 14107 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14108 | struct lpfc_nodelist *ndlp; |
| 14109 | |
| 14110 | if (cmd_iocbq) { |
| 14111 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 14112 | lpfc_nlp_put(ndlp); |
| 14113 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14114 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14115 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14116 | |
| 14117 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 14118 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 14119 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14120 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 14121 | rsp_iocbq->iocb.ulpStatus, |
| 14122 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14123 | } |
| 14124 | |
| 14125 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14126 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 14127 | * @phba: Pointer to HBA context object. |
| 14128 | * @xri: xri id in transaction. |
| 14129 | * |
| 14130 | * This function validates the xri maps to the known range of XRIs allocated an |
| 14131 | * used by the driver. |
| 14132 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14133 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14134 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 14135 | uint16_t xri) |
| 14136 | { |
| 14137 | int i; |
| 14138 | |
| 14139 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 14140 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 14141 | return i; |
| 14142 | } |
| 14143 | return NO_XRI; |
| 14144 | } |
| 14145 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14146 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14147 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14148 | * @phba: Pointer to HBA context object. |
| 14149 | * @fc_hdr: pointer to a FC frame header. |
| 14150 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14151 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14152 | * event after aborting the sequence handling. |
| 14153 | **/ |
| 14154 | static void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14155 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 14156 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14157 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14158 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14159 | struct lpfc_iocbq *ctiocb = NULL; |
| 14160 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14161 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14162 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14163 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14164 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14165 | |
| 14166 | if (!lpfc_is_link_up(phba)) |
| 14167 | return; |
| 14168 | |
| 14169 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 14170 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14171 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14172 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14173 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14174 | if (!ndlp) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14175 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 14176 | if (!ndlp) { |
| 14177 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 14178 | "1268 Failed to allocate ndlp for " |
| 14179 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 14180 | return; |
| 14181 | } |
| 14182 | lpfc_nlp_init(vport, ndlp, sid); |
| 14183 | /* Put ndlp onto pport node list */ |
| 14184 | lpfc_enqueue_node(vport, ndlp); |
| 14185 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 14186 | /* re-setup ndlp without removing from node list */ |
| 14187 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 14188 | if (!ndlp) { |
| 14189 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 14190 | "3275 Failed to active ndlp found " |
| 14191 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 14192 | return; |
| 14193 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14194 | } |
| 14195 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14196 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14197 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 14198 | if (!ctiocb) |
| 14199 | return; |
| 14200 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14201 | /* Extract the F_CTL field from FC_HDR */ |
| 14202 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 14203 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14204 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14205 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14206 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14207 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 14208 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 14209 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 14210 | |
| 14211 | /* Fill in the rest of iocb fields */ |
| 14212 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 14213 | icmd->ulpBdeCount = 0; |
| 14214 | icmd->ulpLe = 1; |
| 14215 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14216 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14217 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14218 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14219 | ctiocb->iocb_cmpl = NULL; |
| 14220 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14221 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14222 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14223 | ctiocb->sli4_xritag = NO_XRI; |
| 14224 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14225 | if (fctl & FC_FC_EX_CTX) |
| 14226 | /* Exchange responder sent the abort so we |
| 14227 | * own the oxid. |
| 14228 | */ |
| 14229 | xri = oxid; |
| 14230 | else |
| 14231 | xri = rxid; |
| 14232 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 14233 | if (lxri != NO_XRI) |
| 14234 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 14235 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14236 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 14237 | * the oxid maps to the FCP XRI range, the port no longer has |
| 14238 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 14239 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14240 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14241 | if ((fctl & FC_FC_EX_CTX) && |
| 14242 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { |
| 14243 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14244 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14245 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14246 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14247 | } |
| 14248 | |
| 14249 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 14250 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 14251 | * the IOCB for a BA_RJT. |
| 14252 | */ |
| 14253 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14254 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14255 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14256 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14257 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14258 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14259 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14260 | if (fctl & FC_FC_EX_CTX) { |
| 14261 | /* ABTS sent by responder to CT exchange, construction |
| 14262 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 14263 | * field and RX_ID from ABTS for RX_ID field. |
| 14264 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14265 | 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] | 14266 | } else { |
| 14267 | /* ABTS sent by initiator to CT exchange, construction |
| 14268 | * 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] | 14269 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14270 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14271 | 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] | 14272 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14273 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14274 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14275 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14276 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14277 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 14278 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 14279 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14280 | |
| 14281 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 14282 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14283 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 14284 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 14285 | "xri x%x, Data x%x\n", |
| 14286 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 14287 | phba->link_state); |
| 14288 | lpfc_nlp_put(ndlp); |
| 14289 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14290 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 14291 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14292 | } |
| 14293 | |
| 14294 | /** |
| 14295 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 14296 | * @vport: Pointer to the vport on which this sequence was received |
| 14297 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14298 | * |
| 14299 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 14300 | * receive sequence is only partially assembed by the driver, it shall abort |
| 14301 | * the partially assembled frames for the sequence. Otherwise, if the |
| 14302 | * unsolicited receive sequence has been completely assembled and passed to |
| 14303 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 14304 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 14305 | * accept to accept the abort. |
| 14306 | **/ |
| 14307 | void |
| 14308 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 14309 | struct hbq_dmabuf *dmabuf) |
| 14310 | { |
| 14311 | struct lpfc_hba *phba = vport->phba; |
| 14312 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14313 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14314 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14315 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14316 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 14317 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14318 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14319 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14320 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14321 | /* ABTS by responder to exchange, no cleanup needed */ |
| 14322 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14323 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14324 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 14325 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 14326 | if (aborted == false) |
| 14327 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14328 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame^] | 14329 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14330 | |
| 14331 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 14332 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14333 | } |
| 14334 | |
| 14335 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14336 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 14337 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14338 | * |
| 14339 | * This function checks the sequence, starting with the frame described by |
| 14340 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 14341 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 14342 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 14343 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 14344 | * set. 3) That there are no holes in the sequence count. The function will |
| 14345 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 14346 | **/ |
| 14347 | static int |
| 14348 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 14349 | { |
| 14350 | struct fc_frame_header *hdr; |
| 14351 | struct lpfc_dmabuf *d_buf; |
| 14352 | struct hbq_dmabuf *seq_dmabuf; |
| 14353 | uint32_t fctl; |
| 14354 | int seq_count = 0; |
| 14355 | |
| 14356 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14357 | /* make sure first fame of sequence has a sequence count of zero */ |
| 14358 | if (hdr->fh_seq_cnt != seq_count) |
| 14359 | return 0; |
| 14360 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14361 | hdr->fh_f_ctl[1] << 8 | |
| 14362 | hdr->fh_f_ctl[2]); |
| 14363 | /* If last frame of sequence we can return success. */ |
| 14364 | if (fctl & FC_FC_END_SEQ) |
| 14365 | return 1; |
| 14366 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 14367 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14368 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14369 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14370 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14371 | return 0; |
| 14372 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14373 | hdr->fh_f_ctl[1] << 8 | |
| 14374 | hdr->fh_f_ctl[2]); |
| 14375 | /* If last frame of sequence we can return success. */ |
| 14376 | if (fctl & FC_FC_END_SEQ) |
| 14377 | return 1; |
| 14378 | } |
| 14379 | return 0; |
| 14380 | } |
| 14381 | |
| 14382 | /** |
| 14383 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 14384 | * @vport: Pointer to the vport on which this sequence was received |
| 14385 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14386 | * |
| 14387 | * This function takes a sequence, described by a list of frames, and creates |
| 14388 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 14389 | * used to issue to the generic unsolicited sequence handler. This routine |
| 14390 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 14391 | * to allocate an iocbq then it throw out the received frames that were not |
| 14392 | * able to be described and return a pointer to the first iocbq. If unable to |
| 14393 | * allocate any iocbqs (including the first) this function will return NULL. |
| 14394 | **/ |
| 14395 | static struct lpfc_iocbq * |
| 14396 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 14397 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14398 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14399 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 14400 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 14401 | struct fc_frame_header *fc_hdr; |
| 14402 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14403 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14404 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14405 | |
| 14406 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14407 | /* remove from receive buffer list */ |
| 14408 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14409 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14410 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14411 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14412 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14413 | /* Get an iocbq struct to fill in. */ |
| 14414 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14415 | if (first_iocbq) { |
| 14416 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14417 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14418 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14419 | |
| 14420 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 14421 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 14422 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 14423 | first_iocbq->iocb.un.rcvels.parmRo = |
| 14424 | sli4_did_from_fc_hdr(fc_hdr); |
| 14425 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 14426 | } else |
| 14427 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14428 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 14429 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 14430 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 14431 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 14432 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 14433 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14434 | /* put the first buffer into the first IOCBq */ |
| 14435 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 14436 | first_iocbq->context3 = NULL; |
| 14437 | first_iocbq->iocb.ulpBdeCount = 1; |
| 14438 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14439 | LPFC_DATA_BUF_SIZE; |
| 14440 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14441 | tot_len = bf_get(lpfc_rcqe_length, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14442 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14443 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14444 | } |
| 14445 | iocbq = first_iocbq; |
| 14446 | /* |
| 14447 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 14448 | * of buffers for this sequence and save two buffers in each IOCBq |
| 14449 | */ |
| 14450 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 14451 | if (!iocbq) { |
| 14452 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14453 | continue; |
| 14454 | } |
| 14455 | if (!iocbq->context3) { |
| 14456 | iocbq->context3 = d_buf; |
| 14457 | iocbq->iocb.ulpBdeCount++; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14458 | pbde = (struct ulp_bde64 *) |
| 14459 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 14460 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14461 | |
| 14462 | /* We need to get the size out of the right CQE */ |
| 14463 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14464 | len = bf_get(lpfc_rcqe_length, |
| 14465 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14466 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 14467 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14468 | } else { |
| 14469 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14470 | if (!iocbq) { |
| 14471 | if (first_iocbq) { |
| 14472 | first_iocbq->iocb.ulpStatus = |
| 14473 | IOSTAT_FCP_RSP_ERROR; |
| 14474 | first_iocbq->iocb.un.ulpWord[4] = |
| 14475 | IOERR_NO_RESOURCES; |
| 14476 | } |
| 14477 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14478 | continue; |
| 14479 | } |
| 14480 | iocbq->context2 = d_buf; |
| 14481 | iocbq->context3 = NULL; |
| 14482 | iocbq->iocb.ulpBdeCount = 1; |
| 14483 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14484 | LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14485 | |
| 14486 | /* We need to get the size out of the right CQE */ |
| 14487 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14488 | len = bf_get(lpfc_rcqe_length, |
| 14489 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14490 | tot_len += len; |
| 14491 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 14492 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14493 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 14494 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 14495 | } |
| 14496 | } |
| 14497 | return first_iocbq; |
| 14498 | } |
| 14499 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14500 | static void |
| 14501 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 14502 | struct hbq_dmabuf *seq_dmabuf) |
| 14503 | { |
| 14504 | struct fc_frame_header *fc_hdr; |
| 14505 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 14506 | struct lpfc_hba *phba = vport->phba; |
| 14507 | |
| 14508 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14509 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 14510 | if (!iocbq) { |
| 14511 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14512 | "2707 Ring %d handler: Failed to allocate " |
| 14513 | "iocb Rctl x%x Type x%x received\n", |
| 14514 | LPFC_ELS_RING, |
| 14515 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14516 | return; |
| 14517 | } |
| 14518 | if (!lpfc_complete_unsol_iocb(phba, |
| 14519 | &phba->sli.ring[LPFC_ELS_RING], |
| 14520 | iocbq, fc_hdr->fh_r_ctl, |
| 14521 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14522 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14523 | "2540 Ring %d handler: unexpected Rctl " |
| 14524 | "x%x Type x%x received\n", |
| 14525 | LPFC_ELS_RING, |
| 14526 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14527 | |
| 14528 | /* Free iocb created in lpfc_prep_seq */ |
| 14529 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 14530 | &iocbq->list, list) { |
| 14531 | list_del_init(&curr_iocb->list); |
| 14532 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 14533 | } |
| 14534 | lpfc_sli_release_iocbq(phba, iocbq); |
| 14535 | } |
| 14536 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14537 | /** |
| 14538 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 14539 | * @phba: Pointer to HBA context object. |
| 14540 | * |
| 14541 | * This function is called with no lock held. This function processes all |
| 14542 | * the received buffers and gives it to upper layers when a received buffer |
| 14543 | * indicates that it is the final frame in the sequence. The interrupt |
| 14544 | * service routine processes received buffers at interrupt contexts and adds |
| 14545 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 14546 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 14547 | * appropriate receive function when the final frame in a sequence is received. |
| 14548 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14549 | void |
| 14550 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 14551 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14552 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14553 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14554 | struct fc_frame_header *fc_hdr; |
| 14555 | struct lpfc_vport *vport; |
| 14556 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14557 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14558 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14559 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14560 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14561 | /* check to see if this a valid type of frame */ |
| 14562 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 14563 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14564 | return; |
| 14565 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14566 | if ((bf_get(lpfc_cqe_code, |
| 14567 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 14568 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 14569 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 14570 | else |
| 14571 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 14572 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14573 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14574 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14575 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14576 | /* throw out the frame */ |
| 14577 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14578 | return; |
| 14579 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14580 | |
| 14581 | /* d_id this frame is directed to */ |
| 14582 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 14583 | |
| 14584 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 14585 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 14586 | (did != Fabric_DID)) { |
| 14587 | /* |
| 14588 | * Throw out the frame if we are not pt2pt. |
| 14589 | * The pt2pt protocol allows for discovery frames |
| 14590 | * to be received without a registered VPI. |
| 14591 | */ |
| 14592 | if (!(vport->fc_flag & FC_PT2PT) || |
| 14593 | (phba->link_state == LPFC_HBA_READY)) { |
| 14594 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14595 | return; |
| 14596 | } |
| 14597 | } |
| 14598 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14599 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 14600 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 14601 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 14602 | return; |
| 14603 | } |
| 14604 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14605 | /* Link this frame */ |
| 14606 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 14607 | if (!seq_dmabuf) { |
| 14608 | /* unable to add frame to vport - throw it out */ |
| 14609 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14610 | return; |
| 14611 | } |
| 14612 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14613 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14614 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14615 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14616 | /* Send the complete sequence to the upper layer protocol */ |
| 14617 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14618 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14619 | |
| 14620 | /** |
| 14621 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 14622 | * @phba: pointer to lpfc hba data structure. |
| 14623 | * |
| 14624 | * This routine is invoked to post rpi header templates to the |
| 14625 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14626 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14627 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14628 | * |
| 14629 | * This routine does not require any locks. It's usage is expected |
| 14630 | * to be driver load or reset recovery when the driver is |
| 14631 | * sequential. |
| 14632 | * |
| 14633 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14634 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14635 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14636 | * When this error occurs, the driver is not guaranteed |
| 14637 | * to have any rpi regions posted to the device and |
| 14638 | * must either attempt to repost the regions or take a |
| 14639 | * fatal error. |
| 14640 | **/ |
| 14641 | int |
| 14642 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 14643 | { |
| 14644 | struct lpfc_rpi_hdr *rpi_page; |
| 14645 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14646 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14647 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14648 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14649 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14650 | goto exit; |
| 14651 | if (phba->sli4_hba.extents_in_use) |
| 14652 | return -EIO; |
| 14653 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14654 | 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] | 14655 | /* |
| 14656 | * Assign the rpi headers a physical rpi only if the driver |
| 14657 | * has not initialized those resources. A port reset only |
| 14658 | * needs the headers posted. |
| 14659 | */ |
| 14660 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 14661 | LPFC_RPI_RSRC_RDY) |
| 14662 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 14663 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14664 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 14665 | if (rc != MBX_SUCCESS) { |
| 14666 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14667 | "2008 Error %d posting all rpi " |
| 14668 | "headers\n", rc); |
| 14669 | rc = -EIO; |
| 14670 | break; |
| 14671 | } |
| 14672 | } |
| 14673 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14674 | exit: |
| 14675 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 14676 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14677 | return rc; |
| 14678 | } |
| 14679 | |
| 14680 | /** |
| 14681 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 14682 | * @phba: pointer to lpfc hba data structure. |
| 14683 | * @rpi_page: pointer to the rpi memory region. |
| 14684 | * |
| 14685 | * This routine is invoked to post a single rpi header to the |
| 14686 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 14687 | * maps up to 64 rpi context regions. |
| 14688 | * |
| 14689 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14690 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14691 | * -ENOMEM - No available memory |
| 14692 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14693 | **/ |
| 14694 | int |
| 14695 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 14696 | { |
| 14697 | LPFC_MBOXQ_t *mboxq; |
| 14698 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 14699 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14700 | uint32_t shdr_status, shdr_add_status; |
| 14701 | union lpfc_sli4_cfg_shdr *shdr; |
| 14702 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14703 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14704 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14705 | return rc; |
| 14706 | if (phba->sli4_hba.extents_in_use) |
| 14707 | return -EIO; |
| 14708 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14709 | /* The port is notified of the header region via a mailbox command. */ |
| 14710 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14711 | if (!mboxq) { |
| 14712 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14713 | "2001 Unable to allocate memory for issuing " |
| 14714 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 14715 | return -ENOMEM; |
| 14716 | } |
| 14717 | |
| 14718 | /* Post all rpi memory regions to the port. */ |
| 14719 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14720 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14721 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 14722 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14723 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 14724 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14725 | |
| 14726 | |
| 14727 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14728 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 14729 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14730 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 14731 | hdr_tmpl, rpi_page->page_count); |
| 14732 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14733 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 14734 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14735 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14736 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 14737 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14738 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14739 | if (rc != MBX_TIMEOUT) |
| 14740 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14741 | if (shdr_status || shdr_add_status || rc) { |
| 14742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14743 | "2514 POST_RPI_HDR mailbox failed with " |
| 14744 | "status x%x add_status x%x, mbx status x%x\n", |
| 14745 | shdr_status, shdr_add_status, rc); |
| 14746 | rc = -ENXIO; |
| 14747 | } |
| 14748 | return rc; |
| 14749 | } |
| 14750 | |
| 14751 | /** |
| 14752 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 14753 | * @phba: pointer to lpfc hba data structure. |
| 14754 | * |
| 14755 | * This routine is invoked to post rpi header templates to the |
| 14756 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14757 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14758 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14759 | * |
| 14760 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14761 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14762 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14763 | **/ |
| 14764 | int |
| 14765 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 14766 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14767 | unsigned long rpi; |
| 14768 | uint16_t max_rpi, rpi_limit; |
| 14769 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14770 | struct lpfc_rpi_hdr *rpi_hdr; |
| 14771 | |
| 14772 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14773 | rpi_limit = phba->sli4_hba.next_rpi; |
| 14774 | |
| 14775 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14776 | * Fetch the next logical rpi. Because this index is logical, |
| 14777 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14778 | */ |
| 14779 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14780 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 14781 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14782 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 14783 | else { |
| 14784 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 14785 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 14786 | phba->sli4_hba.rpi_count++; |
| 14787 | } |
| 14788 | |
| 14789 | /* |
| 14790 | * 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] | 14791 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14792 | */ |
| 14793 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 14794 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
| 14795 | spin_unlock_irq(&phba->hbalock); |
| 14796 | return rpi; |
| 14797 | } |
| 14798 | |
| 14799 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14800 | * RPI header postings are not required for SLI4 ports capable of |
| 14801 | * extents. |
| 14802 | */ |
| 14803 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
| 14804 | spin_unlock_irq(&phba->hbalock); |
| 14805 | return rpi; |
| 14806 | } |
| 14807 | |
| 14808 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14809 | * If the driver is running low on rpi resources, allocate another |
| 14810 | * page now. Note that the next_rpi value is used because |
| 14811 | * it represents how many are actually in use whereas max_rpi notes |
| 14812 | * how many are supported max by the device. |
| 14813 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14814 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14815 | spin_unlock_irq(&phba->hbalock); |
| 14816 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 14817 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 14818 | if (!rpi_hdr) { |
| 14819 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14820 | "2002 Error Could not grow rpi " |
| 14821 | "count\n"); |
| 14822 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14823 | lrpi = rpi_hdr->start_rpi; |
| 14824 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14825 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 14826 | } |
| 14827 | } |
| 14828 | |
| 14829 | return rpi; |
| 14830 | } |
| 14831 | |
| 14832 | /** |
| 14833 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14834 | * @phba: pointer to lpfc hba data structure. |
| 14835 | * |
| 14836 | * This routine is invoked to release an rpi to the pool of |
| 14837 | * available rpis maintained by the driver. |
| 14838 | **/ |
| 14839 | void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14840 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14841 | { |
| 14842 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 14843 | phba->sli4_hba.rpi_count--; |
| 14844 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 14845 | } |
| 14846 | } |
| 14847 | |
| 14848 | /** |
| 14849 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14850 | * @phba: pointer to lpfc hba data structure. |
| 14851 | * |
| 14852 | * This routine is invoked to release an rpi to the pool of |
| 14853 | * available rpis maintained by the driver. |
| 14854 | **/ |
| 14855 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14856 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14857 | { |
| 14858 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14859 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14860 | spin_unlock_irq(&phba->hbalock); |
| 14861 | } |
| 14862 | |
| 14863 | /** |
| 14864 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 14865 | * @phba: pointer to lpfc hba data structure. |
| 14866 | * |
| 14867 | * This routine is invoked to remove the memory region that |
| 14868 | * provided rpi via a bitmask. |
| 14869 | **/ |
| 14870 | void |
| 14871 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 14872 | { |
| 14873 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14874 | kfree(phba->sli4_hba.rpi_ids); |
| 14875 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14876 | } |
| 14877 | |
| 14878 | /** |
| 14879 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 14880 | * @phba: pointer to lpfc hba data structure. |
| 14881 | * |
| 14882 | * This routine is invoked to remove the memory region that |
| 14883 | * provided rpi via a bitmask. |
| 14884 | **/ |
| 14885 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14886 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 14887 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14888 | { |
| 14889 | LPFC_MBOXQ_t *mboxq; |
| 14890 | struct lpfc_hba *phba = ndlp->phba; |
| 14891 | int rc; |
| 14892 | |
| 14893 | /* The port is notified of the header region via a mailbox command. */ |
| 14894 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14895 | if (!mboxq) |
| 14896 | return -ENOMEM; |
| 14897 | |
| 14898 | /* Post all rpi memory regions to the port. */ |
| 14899 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14900 | if (cmpl) { |
| 14901 | mboxq->mbox_cmpl = cmpl; |
| 14902 | mboxq->context1 = arg; |
| 14903 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 14904 | } else |
| 14905 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14906 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14907 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 14908 | if (rc == MBX_NOT_FINISHED) { |
| 14909 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14910 | "2010 Resume RPI Mailbox failed " |
| 14911 | "status %d, mbxStatus x%x\n", rc, |
| 14912 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 14913 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14914 | return -EIO; |
| 14915 | } |
| 14916 | return 0; |
| 14917 | } |
| 14918 | |
| 14919 | /** |
| 14920 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14921 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14922 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14923 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14924 | * |
| 14925 | * Returns: |
| 14926 | * 0 success |
| 14927 | * -Evalue otherwise |
| 14928 | **/ |
| 14929 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14930 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14931 | { |
| 14932 | LPFC_MBOXQ_t *mboxq; |
| 14933 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14934 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14935 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14936 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14937 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14938 | if (!mboxq) |
| 14939 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14940 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14941 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14942 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14943 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14944 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14945 | "2022 INIT VPI Mailbox failed " |
| 14946 | "status %d, mbxStatus x%x\n", rc, |
| 14947 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14948 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14949 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14950 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14951 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14952 | |
| 14953 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14954 | } |
| 14955 | |
| 14956 | /** |
| 14957 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 14958 | * @phba: pointer to lpfc hba data structure. |
| 14959 | * @mboxq: Pointer to mailbox object. |
| 14960 | * |
| 14961 | * This routine is invoked to manually add a single FCF record. The caller |
| 14962 | * must pass a completely initialized FCF_Record. This routine takes |
| 14963 | * care of the nonembedded mailbox operations. |
| 14964 | **/ |
| 14965 | static void |
| 14966 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 14967 | { |
| 14968 | void *virt_addr; |
| 14969 | union lpfc_sli4_cfg_shdr *shdr; |
| 14970 | uint32_t shdr_status, shdr_add_status; |
| 14971 | |
| 14972 | virt_addr = mboxq->sge_array->addr[0]; |
| 14973 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14974 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 14975 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14976 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14977 | |
| 14978 | if ((shdr_status || shdr_add_status) && |
| 14979 | (shdr_status != STATUS_FCF_IN_USE)) |
| 14980 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14981 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 14982 | "status x%x add_status x%x\n", |
| 14983 | shdr_status, shdr_add_status); |
| 14984 | |
| 14985 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14986 | } |
| 14987 | |
| 14988 | /** |
| 14989 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 14990 | * @phba: pointer to lpfc hba data structure. |
| 14991 | * @fcf_record: pointer to the initialized fcf record to add. |
| 14992 | * |
| 14993 | * This routine is invoked to manually add a single FCF record. The caller |
| 14994 | * must pass a completely initialized FCF_Record. This routine takes |
| 14995 | * care of the nonembedded mailbox operations. |
| 14996 | **/ |
| 14997 | int |
| 14998 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 14999 | { |
| 15000 | int rc = 0; |
| 15001 | LPFC_MBOXQ_t *mboxq; |
| 15002 | uint8_t *bytep; |
| 15003 | void *virt_addr; |
| 15004 | dma_addr_t phys_addr; |
| 15005 | struct lpfc_mbx_sge sge; |
| 15006 | uint32_t alloc_len, req_len; |
| 15007 | uint32_t fcfindex; |
| 15008 | |
| 15009 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15010 | if (!mboxq) { |
| 15011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15012 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 15013 | return -ENOMEM; |
| 15014 | } |
| 15015 | |
| 15016 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 15017 | sizeof(uint32_t); |
| 15018 | |
| 15019 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 15020 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15021 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 15022 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 15023 | if (alloc_len < req_len) { |
| 15024 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15025 | "2523 Allocated DMA memory size (x%x) is " |
| 15026 | "less than the requested DMA memory " |
| 15027 | "size (x%x)\n", alloc_len, req_len); |
| 15028 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15029 | return -ENOMEM; |
| 15030 | } |
| 15031 | |
| 15032 | /* |
| 15033 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 15034 | * routine only uses a single SGE. |
| 15035 | */ |
| 15036 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 15037 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15038 | virt_addr = mboxq->sge_array->addr[0]; |
| 15039 | /* |
| 15040 | * Configure the FCF record for FCFI 0. This is the driver's |
| 15041 | * hardcoded default and gets used in nonFIP mode. |
| 15042 | */ |
| 15043 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 15044 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 15045 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 15046 | |
| 15047 | /* |
| 15048 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 15049 | * the FCoE header plus word10. The data copy needs to be endian |
| 15050 | * correct. |
| 15051 | */ |
| 15052 | bytep += sizeof(uint32_t); |
| 15053 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 15054 | mboxq->vport = phba->pport; |
| 15055 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 15056 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15057 | if (rc == MBX_NOT_FINISHED) { |
| 15058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15059 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 15060 | "status 0x%x\n", rc); |
| 15061 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15062 | rc = -EIO; |
| 15063 | } else |
| 15064 | rc = 0; |
| 15065 | |
| 15066 | return rc; |
| 15067 | } |
| 15068 | |
| 15069 | /** |
| 15070 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 15071 | * @phba: pointer to lpfc hba data structure. |
| 15072 | * @fcf_record: pointer to the fcf record to write the default data. |
| 15073 | * @fcf_index: FCF table entry index. |
| 15074 | * |
| 15075 | * This routine is invoked to build the driver's default FCF record. The |
| 15076 | * values used are hardcoded. This routine handles memory initialization. |
| 15077 | * |
| 15078 | **/ |
| 15079 | void |
| 15080 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 15081 | struct fcf_record *fcf_record, |
| 15082 | uint16_t fcf_index) |
| 15083 | { |
| 15084 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 15085 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 15086 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 15087 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 15088 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 15089 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 15090 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 15091 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 15092 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 15093 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 15094 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 15095 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 15096 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 15097 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 15098 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15099 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 15100 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 15101 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 15102 | /* Set the VLAN bit map */ |
| 15103 | if (phba->valid_vlan) { |
| 15104 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 15105 | = 1 << (phba->vlan_id % 8); |
| 15106 | } |
| 15107 | } |
| 15108 | |
| 15109 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15110 | * 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] | 15111 | * @phba: pointer to lpfc hba data structure. |
| 15112 | * @fcf_index: FCF table entry offset. |
| 15113 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15114 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 15115 | * record and processing it one at a time starting from the @fcf_index |
| 15116 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 15117 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15118 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15119 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15120 | **/ |
| 15121 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15122 | 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] | 15123 | { |
| 15124 | int rc = 0, error; |
| 15125 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15126 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15127 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 15128 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15129 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15130 | if (!mboxq) { |
| 15131 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15132 | "2000 Failed to allocate mbox for " |
| 15133 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15134 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15135 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15136 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15137 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15138 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15139 | if (rc) { |
| 15140 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15141 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15142 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15143 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15144 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15145 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15146 | |
| 15147 | spin_lock_irq(&phba->hbalock); |
| 15148 | phba->hba_flag |= FCF_TS_INPROG; |
| 15149 | spin_unlock_irq(&phba->hbalock); |
| 15150 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15151 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15152 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15153 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15154 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 15155 | /* Reset eligible FCF count for new scan */ |
| 15156 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 15157 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15158 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15159 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15160 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15161 | if (error) { |
| 15162 | if (mboxq) |
| 15163 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15164 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15165 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15166 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15167 | spin_unlock_irq(&phba->hbalock); |
| 15168 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15169 | return error; |
| 15170 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15171 | |
| 15172 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15173 | * 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] | 15174 | * @phba: pointer to lpfc hba data structure. |
| 15175 | * @fcf_index: FCF table entry offset. |
| 15176 | * |
| 15177 | * 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] | 15178 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15179 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15180 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15181 | * otherwise. |
| 15182 | **/ |
| 15183 | int |
| 15184 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15185 | { |
| 15186 | int rc = 0, error; |
| 15187 | LPFC_MBOXQ_t *mboxq; |
| 15188 | |
| 15189 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15190 | if (!mboxq) { |
| 15191 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15192 | "2763 Failed to allocate mbox for " |
| 15193 | "READ_FCF cmd\n"); |
| 15194 | error = -ENOMEM; |
| 15195 | goto fail_fcf_read; |
| 15196 | } |
| 15197 | /* Construct the read FCF record mailbox command */ |
| 15198 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15199 | if (rc) { |
| 15200 | error = -EINVAL; |
| 15201 | goto fail_fcf_read; |
| 15202 | } |
| 15203 | /* Issue the mailbox command asynchronously */ |
| 15204 | mboxq->vport = phba->pport; |
| 15205 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 15206 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15207 | if (rc == MBX_NOT_FINISHED) |
| 15208 | error = -EIO; |
| 15209 | else |
| 15210 | error = 0; |
| 15211 | |
| 15212 | fail_fcf_read: |
| 15213 | if (error && mboxq) |
| 15214 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15215 | return error; |
| 15216 | } |
| 15217 | |
| 15218 | /** |
| 15219 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 15220 | * @phba: pointer to lpfc hba data structure. |
| 15221 | * @fcf_index: FCF table entry offset. |
| 15222 | * |
| 15223 | * 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] | 15224 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15225 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15226 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15227 | * otherwise. |
| 15228 | **/ |
| 15229 | int |
| 15230 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15231 | { |
| 15232 | int rc = 0, error; |
| 15233 | LPFC_MBOXQ_t *mboxq; |
| 15234 | |
| 15235 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15236 | if (!mboxq) { |
| 15237 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15238 | "2758 Failed to allocate mbox for " |
| 15239 | "READ_FCF cmd\n"); |
| 15240 | error = -ENOMEM; |
| 15241 | goto fail_fcf_read; |
| 15242 | } |
| 15243 | /* Construct the read FCF record mailbox command */ |
| 15244 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15245 | if (rc) { |
| 15246 | error = -EINVAL; |
| 15247 | goto fail_fcf_read; |
| 15248 | } |
| 15249 | /* Issue the mailbox command asynchronously */ |
| 15250 | mboxq->vport = phba->pport; |
| 15251 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 15252 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15253 | if (rc == MBX_NOT_FINISHED) |
| 15254 | error = -EIO; |
| 15255 | else |
| 15256 | error = 0; |
| 15257 | |
| 15258 | fail_fcf_read: |
| 15259 | if (error && mboxq) |
| 15260 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15261 | return error; |
| 15262 | } |
| 15263 | |
| 15264 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15265 | * lpfc_check_next_fcf_pri |
| 15266 | * phba pointer to the lpfc_hba struct for this port. |
| 15267 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 15268 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 15269 | * rr_bmask based on their priority level. Starting from the highest priority |
| 15270 | * to the lowest. The most likely FCF candidate will be in the highest |
| 15271 | * priority group. When this routine is called it searches the fcf_pri list for |
| 15272 | * next lowest priority group and repopulates the rr_bmask with only those |
| 15273 | * fcf_indexes. |
| 15274 | * returns: |
| 15275 | * 1=success 0=failure |
| 15276 | **/ |
| 15277 | int |
| 15278 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 15279 | { |
| 15280 | uint16_t next_fcf_pri; |
| 15281 | uint16_t last_index; |
| 15282 | struct lpfc_fcf_pri *fcf_pri; |
| 15283 | int rc; |
| 15284 | int ret = 0; |
| 15285 | |
| 15286 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 15287 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15288 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 15289 | "3060 Last IDX %d\n", last_index); |
| 15290 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 15291 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 15292 | "3061 Last IDX %d\n", last_index); |
| 15293 | return 0; /* Empty rr list */ |
| 15294 | } |
| 15295 | next_fcf_pri = 0; |
| 15296 | /* |
| 15297 | * Clear the rr_bmask and set all of the bits that are at this |
| 15298 | * priority. |
| 15299 | */ |
| 15300 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 15301 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 15302 | spin_lock_irq(&phba->hbalock); |
| 15303 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15304 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 15305 | continue; |
| 15306 | /* |
| 15307 | * the 1st priority that has not FLOGI failed |
| 15308 | * will be the highest. |
| 15309 | */ |
| 15310 | if (!next_fcf_pri) |
| 15311 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15312 | spin_unlock_irq(&phba->hbalock); |
| 15313 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15314 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15315 | fcf_pri->fcf_rec.fcf_index); |
| 15316 | if (rc) |
| 15317 | return 0; |
| 15318 | } |
| 15319 | spin_lock_irq(&phba->hbalock); |
| 15320 | } |
| 15321 | /* |
| 15322 | * if next_fcf_pri was not set above and the list is not empty then |
| 15323 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 15324 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15325 | */ |
| 15326 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 15327 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15328 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 15329 | /* |
| 15330 | * the 1st priority that has not FLOGI failed |
| 15331 | * will be the highest. |
| 15332 | */ |
| 15333 | if (!next_fcf_pri) |
| 15334 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15335 | spin_unlock_irq(&phba->hbalock); |
| 15336 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15337 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15338 | fcf_pri->fcf_rec.fcf_index); |
| 15339 | if (rc) |
| 15340 | return 0; |
| 15341 | } |
| 15342 | spin_lock_irq(&phba->hbalock); |
| 15343 | } |
| 15344 | } else |
| 15345 | ret = 1; |
| 15346 | spin_unlock_irq(&phba->hbalock); |
| 15347 | |
| 15348 | return ret; |
| 15349 | } |
| 15350 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15351 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 15352 | * @phba: pointer to lpfc hba data structure. |
| 15353 | * |
| 15354 | * This routine is to get the next eligible FCF record index in a round |
| 15355 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15356 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15357 | * shall be returned, otherwise, the next eligible FCF record's index |
| 15358 | * shall be returned. |
| 15359 | **/ |
| 15360 | uint16_t |
| 15361 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 15362 | { |
| 15363 | uint16_t next_fcf_index; |
| 15364 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15365 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15366 | next_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15367 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % |
| 15368 | LPFC_SLI4_FCF_TBL_INDX_MAX; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15369 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15370 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15371 | next_fcf_index); |
| 15372 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15373 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15374 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15375 | /* |
| 15376 | * If we have wrapped then we need to clear the bits that |
| 15377 | * have been tested so that we can detect when we should |
| 15378 | * change the priority level. |
| 15379 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15380 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15381 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15382 | } |
| 15383 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15384 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15385 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15386 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 15387 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 15388 | /* |
| 15389 | * If next fcf index is not found check if there are lower |
| 15390 | * Priority level fcf's in the fcf_priority list. |
| 15391 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 15392 | * at that level and continue the selection process. |
| 15393 | */ |
| 15394 | if (lpfc_check_next_fcf_pri_level(phba)) |
| 15395 | goto next_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15396 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15397 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15398 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 15399 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 15400 | else { |
| 15401 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15402 | "3063 Only FCF available idx %d, flag %x\n", |
| 15403 | next_fcf_index, |
| 15404 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 15405 | return next_fcf_index; |
| 15406 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15407 | } |
| 15408 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15409 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 15410 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
| 15411 | LPFC_FCF_FLOGI_FAILED) |
| 15412 | goto next_priority; |
| 15413 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15414 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15415 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 15416 | next_fcf_index); |
| 15417 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15418 | return next_fcf_index; |
| 15419 | } |
| 15420 | |
| 15421 | /** |
| 15422 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 15423 | * @phba: pointer to lpfc hba data structure. |
| 15424 | * |
| 15425 | * 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] | 15426 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15427 | * does not go beyond the range of the driver allocated bmask dimension |
| 15428 | * before setting the bit. |
| 15429 | * |
| 15430 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 15431 | * -EINVAL. |
| 15432 | **/ |
| 15433 | int |
| 15434 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15435 | { |
| 15436 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15437 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15438 | "2610 FCF (x%x) reached driver's book " |
| 15439 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15440 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15441 | return -EINVAL; |
| 15442 | } |
| 15443 | /* Set the eligible FCF record index bmask */ |
| 15444 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 15445 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15446 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15447 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15448 | "bmask\n", fcf_index); |
| 15449 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15450 | return 0; |
| 15451 | } |
| 15452 | |
| 15453 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15454 | * 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] | 15455 | * @phba: pointer to lpfc hba data structure. |
| 15456 | * |
| 15457 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15458 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15459 | * does not go beyond the range of the driver allocated bmask dimension |
| 15460 | * before clearing the bit. |
| 15461 | **/ |
| 15462 | void |
| 15463 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15464 | { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15465 | struct lpfc_fcf_pri *fcf_pri; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15466 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15467 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15468 | "2762 FCF (x%x) reached driver's book " |
| 15469 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15470 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15471 | return; |
| 15472 | } |
| 15473 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15474 | spin_lock_irq(&phba->hbalock); |
| 15475 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15476 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 15477 | list_del_init(&fcf_pri->list); |
| 15478 | break; |
| 15479 | } |
| 15480 | } |
| 15481 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15482 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15483 | |
| 15484 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15485 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15486 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15487 | } |
| 15488 | |
| 15489 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15490 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 15491 | * @phba: pointer to lpfc hba data structure. |
| 15492 | * |
| 15493 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 15494 | * command. If the mailbox command returned failure, it will try to stop the |
| 15495 | * FCF rediscover wait timer. |
| 15496 | **/ |
| 15497 | void |
| 15498 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 15499 | { |
| 15500 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15501 | uint32_t shdr_status, shdr_add_status; |
| 15502 | |
| 15503 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15504 | |
| 15505 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 15506 | &redisc_fcf->header.cfg_shdr.response); |
| 15507 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 15508 | &redisc_fcf->header.cfg_shdr.response); |
| 15509 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15510 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15511 | "2746 Requesting for FCF rediscovery failed " |
| 15512 | "status x%x add_status x%x\n", |
| 15513 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15514 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15515 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15516 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15517 | spin_unlock_irq(&phba->hbalock); |
| 15518 | /* |
| 15519 | * CVL event triggered FCF rediscover request failed, |
| 15520 | * last resort to re-try current registered FCF entry. |
| 15521 | */ |
| 15522 | lpfc_retry_pport_discovery(phba); |
| 15523 | } else { |
| 15524 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15525 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15526 | spin_unlock_irq(&phba->hbalock); |
| 15527 | /* |
| 15528 | * DEAD FCF event triggered FCF rediscover request |
| 15529 | * failed, last resort to fail over as a link down |
| 15530 | * to FCF registration. |
| 15531 | */ |
| 15532 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 15533 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15534 | } else { |
| 15535 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15536 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15537 | /* |
| 15538 | * Start FCF rediscovery wait timer for pending FCF |
| 15539 | * before rescan FCF record table. |
| 15540 | */ |
| 15541 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15542 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15543 | |
| 15544 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15545 | } |
| 15546 | |
| 15547 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15548 | * 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] | 15549 | * @phba: pointer to lpfc hba data structure. |
| 15550 | * |
| 15551 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 15552 | * by the port. |
| 15553 | **/ |
| 15554 | int |
| 15555 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 15556 | { |
| 15557 | LPFC_MBOXQ_t *mbox; |
| 15558 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15559 | int rc, length; |
| 15560 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15561 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 15562 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 15563 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15564 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15565 | if (!mbox) { |
| 15566 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15567 | "2745 Failed to allocate mbox for " |
| 15568 | "requesting FCF rediscover.\n"); |
| 15569 | return -ENOMEM; |
| 15570 | } |
| 15571 | |
| 15572 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 15573 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15574 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15575 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 15576 | length, LPFC_SLI4_MBX_EMBED); |
| 15577 | |
| 15578 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15579 | /* Set count to 0 for invalidating the entire FCF database */ |
| 15580 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 15581 | |
| 15582 | /* Issue the mailbox command asynchronously */ |
| 15583 | mbox->vport = phba->pport; |
| 15584 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 15585 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 15586 | |
| 15587 | if (rc == MBX_NOT_FINISHED) { |
| 15588 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15589 | return -EIO; |
| 15590 | } |
| 15591 | return 0; |
| 15592 | } |
| 15593 | |
| 15594 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15595 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 15596 | * @phba: pointer to lpfc hba data structure. |
| 15597 | * |
| 15598 | * This function is the failover routine as a last resort to the FCF DEAD |
| 15599 | * event when driver failed to perform fast FCF failover. |
| 15600 | **/ |
| 15601 | void |
| 15602 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 15603 | { |
| 15604 | uint32_t link_state; |
| 15605 | |
| 15606 | /* |
| 15607 | * Last resort as FCF DEAD event failover will treat this as |
| 15608 | * a link down, but save the link state because we don't want |
| 15609 | * it to be changed to Link Down unless it is already down. |
| 15610 | */ |
| 15611 | link_state = phba->link_state; |
| 15612 | lpfc_linkdown(phba); |
| 15613 | phba->link_state = link_state; |
| 15614 | |
| 15615 | /* Unregister FCF if no devices connected to it */ |
| 15616 | lpfc_unregister_unused_fcf(phba); |
| 15617 | } |
| 15618 | |
| 15619 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15620 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15621 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15622 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15623 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15624 | * This function gets SLI3 port configure region 23 data through memory dump |
| 15625 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15626 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15627 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15628 | static uint32_t |
| 15629 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15630 | { |
| 15631 | LPFC_MBOXQ_t *pmb = NULL; |
| 15632 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15633 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15634 | int rc; |
| 15635 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15636 | if (!rgn23_data) |
| 15637 | return 0; |
| 15638 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15639 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15640 | if (!pmb) { |
| 15641 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15642 | "2600 failed to allocate mailbox memory\n"); |
| 15643 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15644 | } |
| 15645 | mb = &pmb->u.mb; |
| 15646 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15647 | do { |
| 15648 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 15649 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 15650 | |
| 15651 | if (rc != MBX_SUCCESS) { |
| 15652 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15653 | "2601 failed to read config " |
| 15654 | "region 23, rc 0x%x Status 0x%x\n", |
| 15655 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15656 | mb->un.varDmp.word_cnt = 0; |
| 15657 | } |
| 15658 | /* |
| 15659 | * dump mem may return a zero when finished or we got a |
| 15660 | * mailbox error, either way we are done. |
| 15661 | */ |
| 15662 | if (mb->un.varDmp.word_cnt == 0) |
| 15663 | break; |
| 15664 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 15665 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 15666 | |
| 15667 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15668 | rgn23_data + offset, |
| 15669 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15670 | offset += mb->un.varDmp.word_cnt; |
| 15671 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 15672 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15673 | mempool_free(pmb, phba->mbox_mem_pool); |
| 15674 | return offset; |
| 15675 | } |
| 15676 | |
| 15677 | /** |
| 15678 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 15679 | * @phba: pointer to lpfc hba data structure. |
| 15680 | * @rgn23_data: pointer to configure region 23 data. |
| 15681 | * |
| 15682 | * This function gets SLI4 port configure region 23 data through memory dump |
| 15683 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15684 | * will be returned, otherwise, 0 will be returned. |
| 15685 | **/ |
| 15686 | static uint32_t |
| 15687 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 15688 | { |
| 15689 | LPFC_MBOXQ_t *mboxq = NULL; |
| 15690 | struct lpfc_dmabuf *mp = NULL; |
| 15691 | struct lpfc_mqe *mqe; |
| 15692 | uint32_t data_length = 0; |
| 15693 | int rc; |
| 15694 | |
| 15695 | if (!rgn23_data) |
| 15696 | return 0; |
| 15697 | |
| 15698 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15699 | if (!mboxq) { |
| 15700 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15701 | "3105 failed to allocate mailbox memory\n"); |
| 15702 | return 0; |
| 15703 | } |
| 15704 | |
| 15705 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 15706 | goto out; |
| 15707 | mqe = &mboxq->u.mqe; |
| 15708 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 15709 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 15710 | if (rc) |
| 15711 | goto out; |
| 15712 | data_length = mqe->un.mb_words[5]; |
| 15713 | if (data_length == 0) |
| 15714 | goto out; |
| 15715 | if (data_length > DMP_RGN23_SIZE) { |
| 15716 | data_length = 0; |
| 15717 | goto out; |
| 15718 | } |
| 15719 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 15720 | out: |
| 15721 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15722 | if (mp) { |
| 15723 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15724 | kfree(mp); |
| 15725 | } |
| 15726 | return data_length; |
| 15727 | } |
| 15728 | |
| 15729 | /** |
| 15730 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 15731 | * @phba: pointer to lpfc hba data structure. |
| 15732 | * |
| 15733 | * This function read region 23 and parse TLV for port status to |
| 15734 | * decide if the user disaled the port. If the TLV indicates the |
| 15735 | * port is disabled, the hba_flag is set accordingly. |
| 15736 | **/ |
| 15737 | void |
| 15738 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 15739 | { |
| 15740 | uint8_t *rgn23_data = NULL; |
| 15741 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 15742 | uint32_t offset = 0; |
| 15743 | |
| 15744 | /* Get adapter Region 23 data */ |
| 15745 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 15746 | if (!rgn23_data) |
| 15747 | goto out; |
| 15748 | |
| 15749 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15750 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 15751 | else { |
| 15752 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 15753 | &phba->sli4_hba.sli_intf); |
| 15754 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 15755 | goto out; |
| 15756 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 15757 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15758 | |
| 15759 | if (!data_size) |
| 15760 | goto out; |
| 15761 | |
| 15762 | /* Check the region signature first */ |
| 15763 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 15764 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15765 | "2619 Config region 23 has bad signature\n"); |
| 15766 | goto out; |
| 15767 | } |
| 15768 | offset += 4; |
| 15769 | |
| 15770 | /* Check the data structure version */ |
| 15771 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 15772 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15773 | "2620 Config region 23 has bad version\n"); |
| 15774 | goto out; |
| 15775 | } |
| 15776 | offset += 4; |
| 15777 | |
| 15778 | /* Parse TLV entries in the region */ |
| 15779 | while (offset < data_size) { |
| 15780 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 15781 | break; |
| 15782 | /* |
| 15783 | * If the TLV is not driver specific TLV or driver id is |
| 15784 | * not linux driver id, skip the record. |
| 15785 | */ |
| 15786 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 15787 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 15788 | (rgn23_data[offset + 3] != 0)) { |
| 15789 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15790 | continue; |
| 15791 | } |
| 15792 | |
| 15793 | /* Driver found a driver specific TLV in the config region */ |
| 15794 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 15795 | offset += 4; |
| 15796 | tlv_offset = 0; |
| 15797 | |
| 15798 | /* |
| 15799 | * Search for configured port state sub-TLV. |
| 15800 | */ |
| 15801 | while ((offset < data_size) && |
| 15802 | (tlv_offset < sub_tlv_len)) { |
| 15803 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 15804 | offset += 4; |
| 15805 | tlv_offset += 4; |
| 15806 | break; |
| 15807 | } |
| 15808 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 15809 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15810 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 15811 | continue; |
| 15812 | } |
| 15813 | |
| 15814 | /* This HBA contains PORT_STE configured */ |
| 15815 | if (!rgn23_data[offset + 2]) |
| 15816 | phba->hba_flag |= LINK_DISABLED; |
| 15817 | |
| 15818 | goto out; |
| 15819 | } |
| 15820 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15821 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15822 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15823 | kfree(rgn23_data); |
| 15824 | return; |
| 15825 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15826 | |
| 15827 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15828 | * lpfc_wr_object - write an object to the firmware |
| 15829 | * @phba: HBA structure that indicates port to create a queue on. |
| 15830 | * @dmabuf_list: list of dmabufs to write to the port. |
| 15831 | * @size: the total byte value of the objects to write to the port. |
| 15832 | * @offset: the current offset to be used to start the transfer. |
| 15833 | * |
| 15834 | * This routine will create a wr_object mailbox command to send to the port. |
| 15835 | * the mailbox command will be constructed using the dma buffers described in |
| 15836 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 15837 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 15838 | * used to indicate the starting offset of the transfer and will also return |
| 15839 | * the offset after the write object mailbox has completed. @size is used to |
| 15840 | * determine the end of the object and whether the eof bit should be set. |
| 15841 | * |
| 15842 | * Return 0 is successful and offset will contain the the new offset to use |
| 15843 | * for the next write. |
| 15844 | * Return negative value for error cases. |
| 15845 | **/ |
| 15846 | int |
| 15847 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 15848 | uint32_t size, uint32_t *offset) |
| 15849 | { |
| 15850 | struct lpfc_mbx_wr_object *wr_object; |
| 15851 | LPFC_MBOXQ_t *mbox; |
| 15852 | int rc = 0, i = 0; |
| 15853 | uint32_t shdr_status, shdr_add_status; |
| 15854 | uint32_t mbox_tmo; |
| 15855 | union lpfc_sli4_cfg_shdr *shdr; |
| 15856 | struct lpfc_dmabuf *dmabuf; |
| 15857 | uint32_t written = 0; |
| 15858 | |
| 15859 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15860 | if (!mbox) |
| 15861 | return -ENOMEM; |
| 15862 | |
| 15863 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15864 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 15865 | sizeof(struct lpfc_mbx_wr_object) - |
| 15866 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 15867 | |
| 15868 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 15869 | wr_object->u.request.write_offset = *offset; |
| 15870 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 15871 | wr_object->u.request.object_name[0] = |
| 15872 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 15873 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 15874 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 15875 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 15876 | break; |
| 15877 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 15878 | wr_object->u.request.bde[i].addrHigh = |
| 15879 | putPaddrHigh(dmabuf->phys); |
| 15880 | if (written + SLI4_PAGE_SIZE >= size) { |
| 15881 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15882 | (size - written); |
| 15883 | written += (size - written); |
| 15884 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 15885 | } else { |
| 15886 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15887 | SLI4_PAGE_SIZE; |
| 15888 | written += SLI4_PAGE_SIZE; |
| 15889 | } |
| 15890 | i++; |
| 15891 | } |
| 15892 | wr_object->u.request.bde_count = i; |
| 15893 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 15894 | if (!phba->sli4_hba.intr_enable) |
| 15895 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15896 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15897 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15898 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 15899 | } |
| 15900 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15901 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 15902 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15903 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15904 | if (rc != MBX_TIMEOUT) |
| 15905 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15906 | if (shdr_status || shdr_add_status || rc) { |
| 15907 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15908 | "3025 Write Object mailbox failed with " |
| 15909 | "status x%x add_status x%x, mbx status x%x\n", |
| 15910 | shdr_status, shdr_add_status, rc); |
| 15911 | rc = -ENXIO; |
| 15912 | } else |
| 15913 | *offset += wr_object->u.response.actual_write_length; |
| 15914 | return rc; |
| 15915 | } |
| 15916 | |
| 15917 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15918 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 15919 | * @vport: pointer to vport data structure. |
| 15920 | * |
| 15921 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 15922 | * and REG_VPI mailbox commands associated with the vport. This function |
| 15923 | * is called when driver want to restart discovery of the vport due to |
| 15924 | * a Clear Virtual Link event. |
| 15925 | **/ |
| 15926 | void |
| 15927 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 15928 | { |
| 15929 | struct lpfc_hba *phba = vport->phba; |
| 15930 | LPFC_MBOXQ_t *mb, *nextmb; |
| 15931 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15932 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15933 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15934 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15935 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15936 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15937 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15938 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15939 | spin_lock_irq(&phba->hbalock); |
| 15940 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 15941 | if (mb->vport != vport) |
| 15942 | continue; |
| 15943 | |
| 15944 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15945 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15946 | continue; |
| 15947 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15948 | list_del(&mb->list); |
| 15949 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 15950 | } |
| 15951 | /* Clean up active mailbox command with the vport */ |
| 15952 | mb = phba->sli.mbox_active; |
| 15953 | if (mb && (mb->vport == vport)) { |
| 15954 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 15955 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 15956 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15957 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15958 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15959 | /* Put reference count for delayed processing */ |
| 15960 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 15961 | /* Unregister the RPI when mailbox complete */ |
| 15962 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15963 | } |
| 15964 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15965 | /* Cleanup any mailbox completions which are not yet processed */ |
| 15966 | do { |
| 15967 | restart_loop = 0; |
| 15968 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 15969 | /* |
| 15970 | * If this mailox is already processed or it is |
| 15971 | * for another vport ignore it. |
| 15972 | */ |
| 15973 | if ((mb->vport != vport) || |
| 15974 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 15975 | continue; |
| 15976 | |
| 15977 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15978 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15979 | continue; |
| 15980 | |
| 15981 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15982 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15983 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15984 | /* Unregister the RPI when mailbox complete */ |
| 15985 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15986 | restart_loop = 1; |
| 15987 | spin_unlock_irq(&phba->hbalock); |
| 15988 | spin_lock(shost->host_lock); |
| 15989 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15990 | spin_unlock(shost->host_lock); |
| 15991 | spin_lock_irq(&phba->hbalock); |
| 15992 | break; |
| 15993 | } |
| 15994 | } |
| 15995 | } while (restart_loop); |
| 15996 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15997 | spin_unlock_irq(&phba->hbalock); |
| 15998 | |
| 15999 | /* Release the cleaned-up mailbox commands */ |
| 16000 | while (!list_empty(&mbox_cmd_list)) { |
| 16001 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16002 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16003 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 16004 | if (mp) { |
| 16005 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16006 | kfree(mp); |
| 16007 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16008 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16009 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16010 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 16011 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 16012 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 16013 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16014 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16015 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16016 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16017 | mempool_free(mb, phba->mbox_mem_pool); |
| 16018 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16019 | |
| 16020 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 16021 | if (act_mbx_ndlp) { |
| 16022 | spin_lock(shost->host_lock); |
| 16023 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 16024 | spin_unlock(shost->host_lock); |
| 16025 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16026 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16027 | } |
| 16028 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16029 | /** |
| 16030 | * lpfc_drain_txq - Drain the txq |
| 16031 | * @phba: Pointer to HBA context object. |
| 16032 | * |
| 16033 | * This function attempt to submit IOCBs on the txq |
| 16034 | * to the adapter. For SLI4 adapters, the txq contains |
| 16035 | * ELS IOCBs that have been deferred because the there |
| 16036 | * are no SGLs. This congestion can occur with large |
| 16037 | * vport counts during node discovery. |
| 16038 | **/ |
| 16039 | |
| 16040 | uint32_t |
| 16041 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 16042 | { |
| 16043 | LIST_HEAD(completions); |
| 16044 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 16045 | struct lpfc_iocbq *piocbq = 0; |
| 16046 | unsigned long iflags = 0; |
| 16047 | char *fail_msg = NULL; |
| 16048 | struct lpfc_sglq *sglq; |
| 16049 | union lpfc_wqe wqe; |
| 16050 | |
| 16051 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 16052 | if (pring->txq_cnt > pring->txq_max) |
| 16053 | pring->txq_max = pring->txq_cnt; |
| 16054 | |
| 16055 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16056 | |
| 16057 | while (pring->txq_cnt) { |
| 16058 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 16059 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16060 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16061 | if (!piocbq) { |
| 16062 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16063 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16064 | "2823 txq empty and txq_cnt is %d\n ", |
| 16065 | pring->txq_cnt); |
| 16066 | break; |
| 16067 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16068 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16069 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16070 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16071 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16072 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16073 | } |
| 16074 | |
| 16075 | /* The xri and iocb resources secured, |
| 16076 | * attempt to issue request |
| 16077 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16078 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16079 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 16080 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 16081 | fail_msg = "to convert bpl to sgl"; |
| 16082 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 16083 | fail_msg = "to convert iocb to wqe"; |
| 16084 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 16085 | fail_msg = " - Wq is full"; |
| 16086 | else |
| 16087 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 16088 | |
| 16089 | if (fail_msg) { |
| 16090 | /* Failed means we can't issue and need to cancel */ |
| 16091 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16092 | "2822 IOCB failed %s iotag 0x%x " |
| 16093 | "xri 0x%x\n", |
| 16094 | fail_msg, |
| 16095 | piocbq->iotag, piocbq->sli4_xritag); |
| 16096 | list_add_tail(&piocbq->list, &completions); |
| 16097 | } |
| 16098 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16099 | } |
| 16100 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16101 | /* Cancel all the IOCBs that cannot be issued */ |
| 16102 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 16103 | IOERR_SLI_ABORTED); |
| 16104 | |
| 16105 | return pring->txq_cnt; |
| 16106 | } |