James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 1 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2 | /******************************************************************* |
| 3 | * 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] | 4 | * Fibre Channel Host Bus Adapters. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 5 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
| 6 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 7 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 8 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 9 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11 | * * |
| 12 | * 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] | 13 | * modify it under the terms of version 2 of the GNU General * |
| 14 | * Public License as published by the Free Software Foundation. * |
| 15 | * This program is distributed in the hope that it will be useful. * |
| 16 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 17 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 19 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 20 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 21 | * more details, a copy of which can be found in the file COPYING * |
| 22 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 23 | *******************************************************************/ |
| 24 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/blkdev.h> |
| 26 | #include <linux/pci.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 30 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 32 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_cmnd.h> |
| 34 | #include <scsi/scsi_device.h> |
| 35 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 36 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 37 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 38 | #include <linux/aer.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 40 | #include <linux/nvme-fc-driver.h> |
| 41 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 42 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include "lpfc_hw.h" |
| 44 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 45 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 46 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 49 | #include "lpfc_scsi.h" |
| 50 | #include "lpfc_nvme.h" |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 51 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 52 | #include "lpfc_crtn.h" |
| 53 | #include "lpfc_logmsg.h" |
| 54 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 55 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 56 | #include "lpfc_vport.h" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 57 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | |
| 59 | /* There are only four IOCB completion types. */ |
| 60 | typedef enum _lpfc_iocb_type { |
| 61 | LPFC_UNKNOWN_IOCB, |
| 62 | LPFC_UNSOL_IOCB, |
| 63 | LPFC_SOL_IOCB, |
| 64 | LPFC_ABORT_IOCB |
| 65 | } lpfc_iocb_type; |
| 66 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 67 | |
| 68 | /* Provide function prototypes local to this module. */ |
| 69 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 70 | uint32_t); |
| 71 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 72 | uint8_t *, uint32_t *); |
| 73 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 74 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 75 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 76 | struct hbq_dmabuf *); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 77 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 78 | struct hbq_dmabuf *dmabuf); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 79 | static int lpfc_sli4_fp_handle_cqe(struct lpfc_hba *, struct lpfc_queue *, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 80 | struct lpfc_cqe *); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 81 | static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 82 | int); |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 83 | static int lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
| 84 | struct lpfc_eqe *eqe, uint32_t qidx); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 85 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 86 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 87 | static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, |
| 88 | struct lpfc_sli_ring *pring, |
| 89 | struct lpfc_iocbq *cmdiocb); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 90 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 91 | static IOCB_t * |
| 92 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 93 | { |
| 94 | return &iocbq->iocb; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 99 | * @q: The Work Queue to operate on. |
| 100 | * @wqe: The work Queue Entry to put on the Work queue. |
| 101 | * |
| 102 | * This routine will copy the contents of @wqe to the next available entry on |
| 103 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 104 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 105 | * successful. If no entries are available on @q then this function will return |
| 106 | * -ENOMEM. |
| 107 | * The caller is expected to hold the hbalock when calling this routine. |
| 108 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 109 | static int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 110 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 111 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 112 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 113 | struct lpfc_register doorbell; |
| 114 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 115 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 116 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 117 | /* sanity check on queue memory */ |
| 118 | if (unlikely(!q)) |
| 119 | return -ENOMEM; |
| 120 | temp_wqe = q->qe[q->host_index].wqe; |
| 121 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 122 | /* 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] | 123 | idx = ((q->host_index + 1) % q->entry_count); |
| 124 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 125 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 126 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 127 | } |
| 128 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 129 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 130 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 131 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 48e835f | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 132 | else |
| 133 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 134 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 135 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 136 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 137 | /* ensure WQE bcopy flushed before doorbell write */ |
| 138 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 139 | |
| 140 | /* Update the host index before invoking device */ |
| 141 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 142 | |
| 143 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 144 | |
| 145 | /* Ring Doorbell */ |
| 146 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 147 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
| 148 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
| 149 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); |
| 150 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
| 151 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 152 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 153 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 154 | } else { |
| 155 | return -EINVAL; |
| 156 | } |
| 157 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 164 | * @q: The Work Queue to operate on. |
| 165 | * @index: The index to advance the hba index to. |
| 166 | * |
| 167 | * This routine will update the HBA index of a queue to reflect consumption of |
| 168 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 169 | * an entry the host calls this function to update the queue's internal |
| 170 | * pointers. This routine returns the number of entries that were consumed by |
| 171 | * the HBA. |
| 172 | **/ |
| 173 | static uint32_t |
| 174 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 175 | { |
| 176 | uint32_t released = 0; |
| 177 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 178 | /* sanity check on queue memory */ |
| 179 | if (unlikely(!q)) |
| 180 | return 0; |
| 181 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 182 | if (q->hba_index == index) |
| 183 | return 0; |
| 184 | do { |
| 185 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 186 | released++; |
| 187 | } while (q->hba_index != index); |
| 188 | return released; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 193 | * @q: The Mailbox Queue to operate on. |
| 194 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 195 | * |
| 196 | * This routine will copy the contents of @mqe to the next available entry on |
| 197 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 198 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 199 | * successful. If no entries are available on @q then this function will return |
| 200 | * -ENOMEM. |
| 201 | * The caller is expected to hold the hbalock when calling this routine. |
| 202 | **/ |
| 203 | static uint32_t |
| 204 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 205 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 206 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 207 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 208 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 209 | /* sanity check on queue memory */ |
| 210 | if (unlikely(!q)) |
| 211 | return -ENOMEM; |
| 212 | temp_mqe = q->qe[q->host_index].mqe; |
| 213 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 214 | /* If the host has not yet processed the next entry then we are done */ |
| 215 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 216 | return -ENOMEM; |
| 217 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 218 | /* Save off the mailbox pointer for completion */ |
| 219 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 220 | |
| 221 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 222 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 223 | |
| 224 | /* Ring Doorbell */ |
| 225 | doorbell.word0 = 0; |
| 226 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 227 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 228 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 234 | * @q: The Mailbox Queue to operate on. |
| 235 | * |
| 236 | * This routine will update the HBA index of a queue to reflect consumption of |
| 237 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 238 | * an entry the host calls this function to update the queue's internal |
| 239 | * pointers. This routine returns the number of entries that were consumed by |
| 240 | * the HBA. |
| 241 | **/ |
| 242 | static uint32_t |
| 243 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 244 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 245 | /* sanity check on queue memory */ |
| 246 | if (unlikely(!q)) |
| 247 | return 0; |
| 248 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 249 | /* Clear the mailbox pointer for completion */ |
| 250 | q->phba->mbox = NULL; |
| 251 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 252 | return 1; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 257 | * @q: The Event Queue to get the first valid EQE from |
| 258 | * |
| 259 | * This routine will get the first valid Event Queue Entry from @q, update |
| 260 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 261 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 262 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 263 | **/ |
| 264 | static struct lpfc_eqe * |
| 265 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 266 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 267 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 268 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 269 | |
| 270 | /* sanity check on queue memory */ |
| 271 | if (unlikely(!q)) |
| 272 | return NULL; |
| 273 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 274 | |
| 275 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 276 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 277 | return NULL; |
| 278 | /* 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] | 279 | idx = ((q->hba_index + 1) % q->entry_count); |
| 280 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 281 | return NULL; |
| 282 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 283 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * insert barrier for instruction interlock : data from the hardware |
| 287 | * must have the valid bit checked before it can be copied and acted |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 288 | * upon. Speculative instructions were allowing a bcopy at the start |
| 289 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 290 | * after our return, to copy data before the valid bit check above |
| 291 | * was done. As such, some of the copied data was stale. The barrier |
| 292 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 293 | */ |
| 294 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 295 | return eqe; |
| 296 | } |
| 297 | |
| 298 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 299 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 300 | * @q: The Event Queue to disable interrupts |
| 301 | * |
| 302 | **/ |
| 303 | static inline void |
| 304 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 305 | { |
| 306 | struct lpfc_register doorbell; |
| 307 | |
| 308 | doorbell.word0 = 0; |
| 309 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 310 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 311 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 312 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 313 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 314 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 315 | } |
| 316 | |
| 317 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 318 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 319 | * @q: The Event Queue that the host has completed processing for. |
| 320 | * @arm: Indicates whether the host wants to arms this CQ. |
| 321 | * |
| 322 | * This routine will mark all Event Queue Entries on @q, from the last |
| 323 | * known completed entry to the last entry that was processed, as completed |
| 324 | * by clearing the valid bit for each completion queue entry. Then it will |
| 325 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 326 | * The internal host index in the @q will be updated by this routine to indicate |
| 327 | * that the host has finished processing the entries. The @arm parameter |
| 328 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 329 | * |
| 330 | * This function will return the number of EQEs that were popped. |
| 331 | **/ |
| 332 | uint32_t |
| 333 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 334 | { |
| 335 | uint32_t released = 0; |
| 336 | struct lpfc_eqe *temp_eqe; |
| 337 | struct lpfc_register doorbell; |
| 338 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 339 | /* sanity check on queue memory */ |
| 340 | if (unlikely(!q)) |
| 341 | return 0; |
| 342 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 343 | /* while there are valid entries */ |
| 344 | while (q->hba_index != q->host_index) { |
| 345 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 346 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 347 | released++; |
| 348 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 349 | } |
| 350 | if (unlikely(released == 0 && !arm)) |
| 351 | return 0; |
| 352 | |
| 353 | /* ring doorbell for number popped */ |
| 354 | doorbell.word0 = 0; |
| 355 | if (arm) { |
| 356 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 357 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 358 | } |
| 359 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 360 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 361 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 362 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 363 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 364 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 365 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 366 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 367 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 368 | return released; |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 373 | * @q: The Completion Queue to get the first valid CQE from |
| 374 | * |
| 375 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 376 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 377 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 378 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 379 | **/ |
| 380 | static struct lpfc_cqe * |
| 381 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 382 | { |
| 383 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 384 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 385 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 386 | /* sanity check on queue memory */ |
| 387 | if (unlikely(!q)) |
| 388 | return NULL; |
| 389 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 390 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 391 | 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] | 392 | return NULL; |
| 393 | /* 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] | 394 | idx = ((q->hba_index + 1) % q->entry_count); |
| 395 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 396 | return NULL; |
| 397 | |
| 398 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 399 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 400 | |
| 401 | /* |
| 402 | * insert barrier for instruction interlock : data from the hardware |
| 403 | * must have the valid bit checked before it can be copied and acted |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 404 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 405 | * instructions allowing action on content before valid bit checked, |
| 406 | * add barrier here as well. May not be needed as "content" is a |
| 407 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 408 | */ |
| 409 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 410 | return cqe; |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 415 | * @q: The Completion Queue that the host has completed processing for. |
| 416 | * @arm: Indicates whether the host wants to arms this CQ. |
| 417 | * |
| 418 | * This routine will mark all Completion queue entries on @q, from the last |
| 419 | * known completed entry to the last entry that was processed, as completed |
| 420 | * by clearing the valid bit for each completion queue entry. Then it will |
| 421 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 422 | * The internal host index in the @q will be updated by this routine to indicate |
| 423 | * that the host has finished processing the entries. The @arm parameter |
| 424 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 425 | * |
| 426 | * This function will return the number of CQEs that were released. |
| 427 | **/ |
| 428 | uint32_t |
| 429 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 430 | { |
| 431 | uint32_t released = 0; |
| 432 | struct lpfc_cqe *temp_qe; |
| 433 | struct lpfc_register doorbell; |
| 434 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 435 | /* sanity check on queue memory */ |
| 436 | if (unlikely(!q)) |
| 437 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 438 | /* while there are valid entries */ |
| 439 | while (q->hba_index != q->host_index) { |
| 440 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 441 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 442 | released++; |
| 443 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 444 | } |
| 445 | if (unlikely(released == 0 && !arm)) |
| 446 | return 0; |
| 447 | |
| 448 | /* ring doorbell for number popped */ |
| 449 | doorbell.word0 = 0; |
| 450 | if (arm) |
| 451 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 452 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 453 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 454 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 455 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 456 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 457 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 458 | return released; |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 463 | * @q: The Header Receive Queue to operate on. |
| 464 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 465 | * |
| 466 | * This routine will copy the contents of @wqe to the next available entry on |
| 467 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 468 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 469 | * index that the rqe was copied to if successful. If no entries are available |
| 470 | * on @q then this function will return -ENOMEM. |
| 471 | * The caller is expected to hold the hbalock when calling this routine. |
| 472 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 473 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 474 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 475 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 476 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 477 | struct lpfc_rqe *temp_hrqe; |
| 478 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 479 | struct lpfc_register doorbell; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 480 | int put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 481 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 482 | /* sanity check on queue memory */ |
| 483 | if (unlikely(!hq) || unlikely(!dq)) |
| 484 | return -ENOMEM; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 485 | put_index = hq->host_index; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 486 | temp_hrqe = hq->qe[put_index].rqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 487 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 488 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 489 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 490 | return -EINVAL; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 491 | if (put_index != dq->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 492 | return -EINVAL; |
| 493 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 494 | if (((put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 495 | return -EBUSY; |
| 496 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 497 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 498 | |
| 499 | /* Update the host index to point to the next slot */ |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 500 | hq->host_index = ((put_index + 1) % hq->entry_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 501 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 502 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 503 | |
| 504 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 505 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 506 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 507 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 508 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 509 | hq->entry_repost); |
| 510 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 511 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 512 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 513 | hq->entry_repost); |
| 514 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 515 | hq->host_index); |
| 516 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 517 | } else { |
| 518 | return -EINVAL; |
| 519 | } |
| 520 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 521 | } |
| 522 | return put_index; |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 527 | * @q: The Header Receive Queue to operate on. |
| 528 | * |
| 529 | * This routine will update the HBA index of a queue to reflect consumption of |
| 530 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 531 | * consumed an entry the host calls this function to update the queue's |
| 532 | * internal pointers. This routine returns the number of entries that were |
| 533 | * consumed by the HBA. |
| 534 | **/ |
| 535 | static uint32_t |
| 536 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 537 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 538 | /* sanity check on queue memory */ |
| 539 | if (unlikely(!hq) || unlikely(!dq)) |
| 540 | return 0; |
| 541 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 542 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 543 | return 0; |
| 544 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 545 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 546 | return 1; |
| 547 | } |
| 548 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 550 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 551 | * @phba: Pointer to HBA context object. |
| 552 | * @pring: Pointer to driver SLI ring object. |
| 553 | * |
| 554 | * This function returns pointer to next command iocb entry |
| 555 | * in the command ring. The caller must hold hbalock to prevent |
| 556 | * other threads consume the next command iocb. |
| 557 | * SLI-2/SLI-3 provide different sized iocbs. |
| 558 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 559 | static inline IOCB_t * |
| 560 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 561 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 562 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 563 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 564 | } |
| 565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 567 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 568 | * @phba: Pointer to HBA context object. |
| 569 | * @pring: Pointer to driver SLI ring object. |
| 570 | * |
| 571 | * This function returns pointer to next response iocb entry |
| 572 | * in the response ring. The caller must hold hbalock to make sure |
| 573 | * that no other thread consume the next response iocb. |
| 574 | * SLI-2/SLI-3 provide different sized iocbs. |
| 575 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 576 | static inline IOCB_t * |
| 577 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 578 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 579 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 580 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 581 | } |
| 582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 583 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 584 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 585 | * @phba: Pointer to HBA context object. |
| 586 | * |
| 587 | * This function is called with hbalock held. This function |
| 588 | * allocates a new driver iocb object from the iocb pool. If the |
| 589 | * allocation is successful, it returns pointer to the newly |
| 590 | * allocated iocb object else it returns NULL. |
| 591 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 592 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 593 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 594 | { |
| 595 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 596 | struct lpfc_iocbq * iocbq = NULL; |
| 597 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 598 | lockdep_assert_held(&phba->hbalock); |
| 599 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 600 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 601 | if (iocbq) |
| 602 | phba->iocb_cnt++; |
| 603 | if (phba->iocb_cnt > phba->iocb_max) |
| 604 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 605 | return iocbq; |
| 606 | } |
| 607 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 608 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 609 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 610 | * @phba: Pointer to HBA context object. |
| 611 | * @xritag: XRI value. |
| 612 | * |
| 613 | * This function clears the sglq pointer from the array of acive |
| 614 | * sglq's. The xritag that is passed in is used to index into the |
| 615 | * array. Before the xritag can be used it needs to be adjusted |
| 616 | * by subtracting the xribase. |
| 617 | * |
| 618 | * Returns sglq ponter = success, NULL = Failure. |
| 619 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 620 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 621 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 622 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 623 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 624 | |
| 625 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 626 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 627 | return sglq; |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 632 | * @phba: Pointer to HBA context object. |
| 633 | * @xritag: XRI value. |
| 634 | * |
| 635 | * This function returns the sglq pointer from the array of acive |
| 636 | * sglq's. The xritag that is passed in is used to index into the |
| 637 | * array. Before the xritag can be used it needs to be adjusted |
| 638 | * by subtracting the xribase. |
| 639 | * |
| 640 | * Returns sglq ponter = success, NULL = Failure. |
| 641 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 642 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 643 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 644 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 645 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 646 | |
| 647 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 648 | return sglq; |
| 649 | } |
| 650 | |
| 651 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 652 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 653 | * @phba: Pointer to HBA context object. |
| 654 | * @xritag: xri used in this exchange. |
| 655 | * @rrq: The RRQ to be cleared. |
| 656 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 657 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 658 | void |
| 659 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 660 | uint16_t xritag, |
| 661 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 662 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 663 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 664 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 665 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 666 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 667 | |
| 668 | /* The target DID could have been swapped (cable swap) |
| 669 | * we should use the ndlp from the findnode if it is |
| 670 | * available. |
| 671 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 672 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 673 | ndlp = rrq->ndlp; |
| 674 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 675 | if (!ndlp) |
| 676 | goto out; |
| 677 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 678 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 679 | rrq->send_rrq = 0; |
| 680 | rrq->xritag = 0; |
| 681 | rrq->rrq_stop_time = 0; |
| 682 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 683 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 684 | mempool_free(rrq, phba->rrq_pool); |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 689 | * @phba: Pointer to HBA context object. |
| 690 | * |
| 691 | * This function is called with hbalock held. This function |
| 692 | * Checks if stop_time (ratov from setting rrq active) has |
| 693 | * been reached, if it has and the send_rrq flag is set then |
| 694 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 695 | * then it will just call the routine to clear the rrq and |
| 696 | * free the rrq resource. |
| 697 | * The timer is set to the next rrq that is going to expire before |
| 698 | * leaving the routine. |
| 699 | * |
| 700 | **/ |
| 701 | void |
| 702 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 703 | { |
| 704 | struct lpfc_node_rrq *rrq; |
| 705 | struct lpfc_node_rrq *nextrrq; |
| 706 | unsigned long next_time; |
| 707 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 708 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 709 | |
| 710 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 711 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 712 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 713 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 714 | &phba->active_rrq_list, list) { |
| 715 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 716 | list_move(&rrq->list, &send_rrq); |
| 717 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 718 | next_time = rrq->rrq_stop_time; |
| 719 | } |
| 720 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 721 | if ((!list_empty(&phba->active_rrq_list)) && |
| 722 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 723 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 724 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 725 | list_del(&rrq->list); |
| 726 | if (!rrq->send_rrq) |
| 727 | /* this call will free the rrq */ |
| 728 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 729 | else if (lpfc_send_rrq(phba, rrq)) { |
| 730 | /* if we send the rrq then the completion handler |
| 731 | * will clear the bit in the xribitmap. |
| 732 | */ |
| 733 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 734 | rrq); |
| 735 | } |
| 736 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | /** |
| 740 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 741 | * @vport: Pointer to vport context object. |
| 742 | * @xri: The xri used in the exchange. |
| 743 | * @did: The targets DID for this exchange. |
| 744 | * |
| 745 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 746 | * rrq = rrq for this xri and target. |
| 747 | **/ |
| 748 | struct lpfc_node_rrq * |
| 749 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 750 | { |
| 751 | struct lpfc_hba *phba = vport->phba; |
| 752 | struct lpfc_node_rrq *rrq; |
| 753 | struct lpfc_node_rrq *nextrrq; |
| 754 | unsigned long iflags; |
| 755 | |
| 756 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 757 | return NULL; |
| 758 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 759 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 760 | if (rrq->vport == vport && rrq->xritag == xri && |
| 761 | rrq->nlp_DID == did){ |
| 762 | list_del(&rrq->list); |
| 763 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 764 | return rrq; |
| 765 | } |
| 766 | } |
| 767 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 768 | return NULL; |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 773 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 774 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 775 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 776 | * phba->active_rrq_list and clear the rrq. |
| 777 | * 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] | 778 | **/ |
| 779 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 780 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 781 | |
| 782 | { |
| 783 | struct lpfc_hba *phba = vport->phba; |
| 784 | struct lpfc_node_rrq *rrq; |
| 785 | struct lpfc_node_rrq *nextrrq; |
| 786 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 787 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 788 | |
| 789 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 790 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 791 | if (!ndlp) { |
| 792 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 793 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 794 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 795 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 796 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 797 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 798 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 799 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 800 | |
| 801 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 802 | list_del(&rrq->list); |
| 803 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 804 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 808 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 809 | * @phba: Pointer to HBA context object. |
| 810 | * @ndlp: Targets nodelist pointer for this exchange. |
| 811 | * @xritag the xri in the bitmap to test. |
| 812 | * |
| 813 | * This function is called with hbalock held. This function |
| 814 | * returns 0 = rrq not active for this xri |
| 815 | * 1 = rrq is valid for this xri. |
| 816 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 817 | int |
| 818 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 819 | uint16_t xritag) |
| 820 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 821 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 822 | if (!ndlp) |
| 823 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 824 | if (!ndlp->active_rrqs_xri_bitmap) |
| 825 | return 0; |
| 826 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 827 | return 1; |
| 828 | else |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | /** |
| 833 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 834 | * @phba: Pointer to HBA context object. |
| 835 | * @ndlp: nodelist pointer for this target. |
| 836 | * @xritag: xri used in this exchange. |
| 837 | * @rxid: Remote Exchange ID. |
| 838 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 839 | * |
| 840 | * This function takes the hbalock. |
| 841 | * The active bit is always set in the active rrq xri_bitmap even |
| 842 | * if there is no slot avaiable for the other rrq information. |
| 843 | * |
| 844 | * returns 0 rrq actived for this xri |
| 845 | * < 0 No memory or invalid ndlp. |
| 846 | **/ |
| 847 | int |
| 848 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 849 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 850 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 851 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 852 | struct lpfc_node_rrq *rrq; |
| 853 | int empty; |
| 854 | |
| 855 | if (!ndlp) |
| 856 | return -EINVAL; |
| 857 | |
| 858 | if (!phba->cfg_enable_rrq) |
| 859 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 860 | |
| 861 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 862 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 863 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 864 | goto out; |
| 865 | } |
| 866 | |
| 867 | /* |
| 868 | * set the active bit even if there is no mem available. |
| 869 | */ |
| 870 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 871 | goto out; |
| 872 | |
| 873 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 874 | goto out; |
| 875 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 876 | if (!ndlp->active_rrqs_xri_bitmap) |
| 877 | goto out; |
| 878 | |
| 879 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 880 | goto out; |
| 881 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 882 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 883 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 884 | if (!rrq) { |
| 885 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 886 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 887 | " DID:0x%x Send:%d\n", |
| 888 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 889 | return -EINVAL; |
| 890 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 891 | if (phba->cfg_enable_rrq == 1) |
| 892 | rrq->send_rrq = send_rrq; |
| 893 | else |
| 894 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 895 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 896 | rrq->rrq_stop_time = jiffies + |
| 897 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 898 | rrq->ndlp = ndlp; |
| 899 | rrq->nlp_DID = ndlp->nlp_DID; |
| 900 | rrq->vport = ndlp->vport; |
| 901 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 902 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 903 | empty = list_empty(&phba->active_rrq_list); |
| 904 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 905 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 906 | if (empty) |
| 907 | lpfc_worker_wake_up(phba); |
| 908 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 909 | return 0; |
| 910 | out: |
| 911 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 912 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 913 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 914 | " DID:0x%x Send:%d\n", |
| 915 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 916 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 920 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 921 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 922 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 923 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 924 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 925 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 926 | * list is not empty then it is successful, it returns pointer to the newly |
| 927 | * allocated sglq object else it returns NULL. |
| 928 | **/ |
| 929 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 930 | __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 931 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 932 | struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 933 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 934 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 935 | struct lpfc_scsi_buf *lpfc_cmd; |
| 936 | struct lpfc_nodelist *ndlp; |
| 937 | int found = 0; |
| 938 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 939 | lockdep_assert_held(&phba->hbalock); |
| 940 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 941 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 942 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 943 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 944 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 945 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 946 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 947 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 948 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 949 | ndlp = NULL; |
| 950 | else |
| 951 | ndlp = piocbq->context_un.ndlp; |
| 952 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 953 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 954 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 955 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 956 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 957 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 958 | start_sglq = sglq; |
| 959 | while (!found) { |
| 960 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 961 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 962 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 963 | test_bit(sglq->sli4_lxritag, |
| 964 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 965 | /* This xri has an rrq outstanding for this DID. |
| 966 | * put it back in the list and get another xri. |
| 967 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 968 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 969 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 970 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 971 | struct lpfc_sglq, list); |
| 972 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 973 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 974 | sglq = NULL; |
| 975 | break; |
| 976 | } else |
| 977 | continue; |
| 978 | } |
| 979 | sglq->ndlp = ndlp; |
| 980 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 981 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 982 | sglq->state = SGL_ALLOCATED; |
| 983 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 984 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 985 | return sglq; |
| 986 | } |
| 987 | |
| 988 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 989 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 990 | * @phba: Pointer to HBA context object. |
| 991 | * @piocb: Pointer to the iocbq. |
| 992 | * |
| 993 | * This function is called with the sgl_list lock held. This function |
| 994 | * gets a new driver sglq object from the sglq list. If the |
| 995 | * list is not empty then it is successful, it returns pointer to the newly |
| 996 | * allocated sglq object else it returns NULL. |
| 997 | **/ |
| 998 | struct lpfc_sglq * |
| 999 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1000 | { |
| 1001 | struct list_head *lpfc_nvmet_sgl_list; |
| 1002 | struct lpfc_sglq *sglq = NULL; |
| 1003 | |
| 1004 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1005 | |
| 1006 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1007 | |
| 1008 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1009 | if (!sglq) |
| 1010 | return NULL; |
| 1011 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1012 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | return sglq; |
| 1014 | } |
| 1015 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1016 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1017 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1018 | * @phba: Pointer to HBA context object. |
| 1019 | * |
| 1020 | * This function is called with no lock held. This function |
| 1021 | * allocates a new driver iocb object from the iocb pool. If the |
| 1022 | * allocation is successful, it returns pointer to the newly |
| 1023 | * allocated iocb object else it returns NULL. |
| 1024 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1025 | struct lpfc_iocbq * |
| 1026 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1027 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1028 | struct lpfc_iocbq * iocbq = NULL; |
| 1029 | unsigned long iflags; |
| 1030 | |
| 1031 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1032 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1033 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1034 | return iocbq; |
| 1035 | } |
| 1036 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1037 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1038 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1039 | * @phba: Pointer to HBA context object. |
| 1040 | * @iocbq: Pointer to driver iocb object. |
| 1041 | * |
| 1042 | * This function is called with hbalock held to release driver |
| 1043 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1044 | * does not change for each use of the iocb object. This function |
| 1045 | * clears all other fields of the iocb object when it is freed. |
| 1046 | * The sqlq structure that holds the xritag and phys and virtual |
| 1047 | * mappings for the scatter gather list is retrieved from the |
| 1048 | * active array of sglq. The get of the sglq pointer also clears |
| 1049 | * the entry in the array. If the status of the IO indiactes that |
| 1050 | * this IO was aborted then the sglq entry it put on the |
| 1051 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1052 | * IO has good status or fails for any other reason then the sglq |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1053 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1054 | **/ |
| 1055 | static void |
| 1056 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1057 | { |
| 1058 | struct lpfc_sglq *sglq; |
| 1059 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1060 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1061 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1062 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1063 | lockdep_assert_held(&phba->hbalock); |
| 1064 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1065 | if (iocbq->sli4_xritag == NO_XRI) |
| 1066 | sglq = NULL; |
| 1067 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1068 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1069 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1070 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1071 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1072 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1073 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1074 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1075 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1076 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1077 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1078 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1079 | spin_unlock_irqrestore( |
| 1080 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1081 | goto out; |
| 1082 | } |
| 1083 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1084 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1085 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1086 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1087 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1088 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1089 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1090 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1091 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1092 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1093 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1094 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1095 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1096 | sglq->state = SGL_FREED; |
| 1097 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1098 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1099 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1100 | spin_unlock_irqrestore( |
| 1101 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1102 | |
| 1103 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1104 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1105 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1106 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1107 | } |
| 1108 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1109 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1110 | /* |
| 1111 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1112 | */ |
| 1113 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1114 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1115 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1116 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1117 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1118 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1119 | } |
| 1120 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1121 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1122 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1123 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1124 | * @phba: Pointer to HBA context object. |
| 1125 | * @iocbq: Pointer to driver iocb object. |
| 1126 | * |
| 1127 | * This function is called with hbalock held to release driver |
| 1128 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1129 | * does not change for each use of the iocb object. This function |
| 1130 | * clears all other fields of the iocb object when it is freed. |
| 1131 | **/ |
| 1132 | static void |
| 1133 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1134 | { |
| 1135 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1136 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1137 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1138 | |
| 1139 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1140 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1141 | */ |
| 1142 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1143 | iocbq->sli4_xritag = NO_XRI; |
| 1144 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1145 | } |
| 1146 | |
| 1147 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1148 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1149 | * @phba: Pointer to HBA context object. |
| 1150 | * @iocbq: Pointer to driver iocb object. |
| 1151 | * |
| 1152 | * This function is called with hbalock held to release driver |
| 1153 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1154 | * does not change for each use of the iocb object. This function |
| 1155 | * clears all other fields of the iocb object when it is freed. |
| 1156 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1157 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1158 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1159 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1160 | lockdep_assert_held(&phba->hbalock); |
| 1161 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1162 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1163 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1164 | } |
| 1165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1167 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1168 | * @phba: Pointer to HBA context object. |
| 1169 | * @iocbq: Pointer to driver iocb object. |
| 1170 | * |
| 1171 | * This function is called with no lock held to release the iocb to |
| 1172 | * iocb pool. |
| 1173 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1174 | void |
| 1175 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1176 | { |
| 1177 | unsigned long iflags; |
| 1178 | |
| 1179 | /* |
| 1180 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1181 | */ |
| 1182 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1183 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1184 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1185 | } |
| 1186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1187 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1188 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1189 | * @phba: Pointer to HBA context object. |
| 1190 | * @iocblist: List of IOCBs. |
| 1191 | * @ulpstatus: ULP status in IOCB command field. |
| 1192 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1193 | * |
| 1194 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1195 | * on the list by invoking the complete callback function associated with the |
| 1196 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1197 | * fields. |
| 1198 | **/ |
| 1199 | void |
| 1200 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1201 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1202 | { |
| 1203 | struct lpfc_iocbq *piocb; |
| 1204 | |
| 1205 | while (!list_empty(iocblist)) { |
| 1206 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1207 | if (!piocb->iocb_cmpl) |
| 1208 | lpfc_sli_release_iocbq(phba, piocb); |
| 1209 | else { |
| 1210 | piocb->iocb.ulpStatus = ulpstatus; |
| 1211 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1212 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1213 | } |
| 1214 | } |
| 1215 | return; |
| 1216 | } |
| 1217 | |
| 1218 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1219 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1220 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1221 | * |
| 1222 | * This function is called by ring event handler function to get the iocb type. |
| 1223 | * This function translates the iocb command to an iocb command type used to |
| 1224 | * decide the final disposition of each completed IOCB. |
| 1225 | * The function returns |
| 1226 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1227 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1228 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1229 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1230 | * |
| 1231 | * The caller is not required to hold any lock. |
| 1232 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1233 | static lpfc_iocb_type |
| 1234 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1235 | { |
| 1236 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1237 | |
| 1238 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1239 | return 0; |
| 1240 | |
| 1241 | switch (iocb_cmnd) { |
| 1242 | case CMD_XMIT_SEQUENCE_CR: |
| 1243 | case CMD_XMIT_SEQUENCE_CX: |
| 1244 | case CMD_XMIT_BCAST_CN: |
| 1245 | case CMD_XMIT_BCAST_CX: |
| 1246 | case CMD_ELS_REQUEST_CR: |
| 1247 | case CMD_ELS_REQUEST_CX: |
| 1248 | case CMD_CREATE_XRI_CR: |
| 1249 | case CMD_CREATE_XRI_CX: |
| 1250 | case CMD_GET_RPI_CN: |
| 1251 | case CMD_XMIT_ELS_RSP_CX: |
| 1252 | case CMD_GET_RPI_CR: |
| 1253 | case CMD_FCP_IWRITE_CR: |
| 1254 | case CMD_FCP_IWRITE_CX: |
| 1255 | case CMD_FCP_IREAD_CR: |
| 1256 | case CMD_FCP_IREAD_CX: |
| 1257 | case CMD_FCP_ICMND_CR: |
| 1258 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1259 | case CMD_FCP_TSEND_CX: |
| 1260 | case CMD_FCP_TRSP_CX: |
| 1261 | case CMD_FCP_TRECEIVE_CX: |
| 1262 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | case CMD_ADAPTER_MSG: |
| 1264 | case CMD_ADAPTER_DUMP: |
| 1265 | case CMD_XMIT_SEQUENCE64_CR: |
| 1266 | case CMD_XMIT_SEQUENCE64_CX: |
| 1267 | case CMD_XMIT_BCAST64_CN: |
| 1268 | case CMD_XMIT_BCAST64_CX: |
| 1269 | case CMD_ELS_REQUEST64_CR: |
| 1270 | case CMD_ELS_REQUEST64_CX: |
| 1271 | case CMD_FCP_IWRITE64_CR: |
| 1272 | case CMD_FCP_IWRITE64_CX: |
| 1273 | case CMD_FCP_IREAD64_CR: |
| 1274 | case CMD_FCP_IREAD64_CX: |
| 1275 | case CMD_FCP_ICMND64_CR: |
| 1276 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1277 | case CMD_FCP_TSEND64_CX: |
| 1278 | case CMD_FCP_TRSP64_CX: |
| 1279 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1280 | case CMD_GEN_REQUEST64_CR: |
| 1281 | case CMD_GEN_REQUEST64_CX: |
| 1282 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1283 | case DSSCMD_IWRITE64_CR: |
| 1284 | case DSSCMD_IWRITE64_CX: |
| 1285 | case DSSCMD_IREAD64_CR: |
| 1286 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | type = LPFC_SOL_IOCB; |
| 1288 | break; |
| 1289 | case CMD_ABORT_XRI_CN: |
| 1290 | case CMD_ABORT_XRI_CX: |
| 1291 | case CMD_CLOSE_XRI_CN: |
| 1292 | case CMD_CLOSE_XRI_CX: |
| 1293 | case CMD_XRI_ABORTED_CX: |
| 1294 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1295 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | type = LPFC_ABORT_IOCB; |
| 1297 | break; |
| 1298 | case CMD_RCV_SEQUENCE_CX: |
| 1299 | case CMD_RCV_ELS_REQ_CX: |
| 1300 | case CMD_RCV_SEQUENCE64_CX: |
| 1301 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1302 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1303 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1304 | case CMD_IOCB_RCV_ELS64_CX: |
| 1305 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1306 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1307 | type = LPFC_UNSOL_IOCB; |
| 1308 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1309 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1310 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1311 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1312 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1313 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1314 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1315 | case CMD_IOCB_RET_HBQE64_CN: |
| 1316 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1317 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1318 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1319 | case CMD_IOCB_LOGENTRY_CN: |
| 1320 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1321 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1322 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1323 | type = LPFC_UNKNOWN_IOCB; |
| 1324 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1325 | default: |
| 1326 | type = LPFC_UNKNOWN_IOCB; |
| 1327 | break; |
| 1328 | } |
| 1329 | |
| 1330 | return type; |
| 1331 | } |
| 1332 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1333 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1334 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1335 | * @phba: Pointer to HBA context object. |
| 1336 | * |
| 1337 | * This function is called from SLI initialization code |
| 1338 | * to configure every ring of the HBA's SLI interface. The |
| 1339 | * caller is not required to hold any lock. This function issues |
| 1340 | * a config_ring mailbox command for each ring. |
| 1341 | * This function returns zero if successful else returns a negative |
| 1342 | * error code. |
| 1343 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1344 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1345 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1346 | { |
| 1347 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1348 | LPFC_MBOXQ_t *pmb; |
| 1349 | MAILBOX_t *pmbox; |
| 1350 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1351 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1352 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1353 | if (!pmb) |
| 1354 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1355 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1356 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1357 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1358 | lpfc_config_ring(phba, i, pmb); |
| 1359 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1360 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1361 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1362 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1364 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1365 | rc, pmbox->mbxCommand, |
| 1366 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1367 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1368 | ret = -ENXIO; |
| 1369 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1370 | } |
| 1371 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1372 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1373 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1374 | } |
| 1375 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1376 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1377 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1378 | * @phba: Pointer to HBA context object. |
| 1379 | * @pring: Pointer to driver SLI ring object. |
| 1380 | * @piocb: Pointer to the driver iocb object. |
| 1381 | * |
| 1382 | * This function is called with hbalock held. The function adds the |
| 1383 | * new iocb to txcmplq of the given ring. This function always returns |
| 1384 | * 0. If this function is called for ELS ring, this function checks if |
| 1385 | * there is a vport associated with the ELS command. This function also |
| 1386 | * starts els_tmofunc timer if this is an ELS command. |
| 1387 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1389 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1390 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1391 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1392 | lockdep_assert_held(&phba->hbalock); |
| 1393 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1394 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1395 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1396 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1397 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1398 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1399 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1400 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1401 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1402 | BUG_ON(!piocb->vport); |
| 1403 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1404 | mod_timer(&piocb->vport->els_tmofunc, |
| 1405 | jiffies + |
| 1406 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1407 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1409 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1410 | } |
| 1411 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1412 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1413 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1414 | * @phba: Pointer to HBA context object. |
| 1415 | * @pring: Pointer to driver SLI ring object. |
| 1416 | * |
| 1417 | * This function is called with hbalock held to get next |
| 1418 | * iocb in txq of the given ring. If there is any iocb in |
| 1419 | * the txq, the function returns first iocb in the list after |
| 1420 | * removing the iocb from the list, else it returns NULL. |
| 1421 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1422 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1423 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1424 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | struct lpfc_iocbq *cmd_iocb; |
| 1426 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1427 | lockdep_assert_held(&phba->hbalock); |
| 1428 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1429 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1430 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1431 | } |
| 1432 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1433 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1434 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1435 | * @phba: Pointer to HBA context object. |
| 1436 | * @pring: Pointer to driver SLI ring object. |
| 1437 | * |
| 1438 | * This function is called with hbalock held and the caller must post the |
| 1439 | * iocb without releasing the lock. If the caller releases the lock, |
| 1440 | * iocb slot returned by the function is not guaranteed to be available. |
| 1441 | * The function returns pointer to the next available iocb slot if there |
| 1442 | * is available slot in the ring, else it returns NULL. |
| 1443 | * If the get index of the ring is ahead of the put index, the function |
| 1444 | * will post an error attention event to the worker thread to take the |
| 1445 | * HBA to offline state. |
| 1446 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | static IOCB_t * |
| 1448 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1449 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1450 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1451 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1452 | |
| 1453 | lockdep_assert_held(&phba->hbalock); |
| 1454 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1455 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1456 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1457 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1458 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1459 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1460 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1462 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1464 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1465 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1466 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1467 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1468 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1469 | pring->sli.sli3.local_getidx, |
| 1470 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1472 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1473 | /* |
| 1474 | * All error attention handlers are posted to |
| 1475 | * worker thread |
| 1476 | */ |
| 1477 | phba->work_ha |= HA_ERATT; |
| 1478 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1479 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1480 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | |
| 1482 | return NULL; |
| 1483 | } |
| 1484 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1485 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1486 | return NULL; |
| 1487 | } |
| 1488 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1489 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | } |
| 1491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1492 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1493 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1494 | * @phba: Pointer to HBA context object. |
| 1495 | * @iocbq: Pointer to driver iocb object. |
| 1496 | * |
| 1497 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1498 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1499 | * array and assigns a new iotag. |
| 1500 | * The function returns the allocated iotag if successful, else returns zero. |
| 1501 | * Zero is not a valid iotag. |
| 1502 | * The caller is not required to hold any lock. |
| 1503 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1504 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1505 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1506 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1507 | struct lpfc_iocbq **new_arr; |
| 1508 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1509 | size_t new_len; |
| 1510 | struct lpfc_sli *psli = &phba->sli; |
| 1511 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1513 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1514 | iotag = psli->last_iotag; |
| 1515 | if(++iotag < psli->iocbq_lookup_len) { |
| 1516 | psli->last_iotag = iotag; |
| 1517 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1518 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1519 | iocbq->iotag = iotag; |
| 1520 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1521 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1522 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1523 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1524 | spin_unlock_irq(&phba->hbalock); |
| 1525 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1526 | GFP_KERNEL); |
| 1527 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1528 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1529 | old_arr = psli->iocbq_lookup; |
| 1530 | if (new_len <= psli->iocbq_lookup_len) { |
| 1531 | /* highly unprobable case */ |
| 1532 | kfree(new_arr); |
| 1533 | iotag = psli->last_iotag; |
| 1534 | if(++iotag < psli->iocbq_lookup_len) { |
| 1535 | psli->last_iotag = iotag; |
| 1536 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1537 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1538 | iocbq->iotag = iotag; |
| 1539 | return iotag; |
| 1540 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1542 | return 0; |
| 1543 | } |
| 1544 | if (psli->iocbq_lookup) |
| 1545 | memcpy(new_arr, old_arr, |
| 1546 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1547 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1548 | psli->iocbq_lookup = new_arr; |
| 1549 | psli->iocbq_lookup_len = new_len; |
| 1550 | psli->last_iotag = iotag; |
| 1551 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1552 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1553 | iocbq->iotag = iotag; |
| 1554 | kfree(old_arr); |
| 1555 | return iotag; |
| 1556 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1557 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1558 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1560 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1561 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1562 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1564 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | } |
| 1566 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1567 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1568 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1569 | * @phba: Pointer to HBA context object. |
| 1570 | * @pring: Pointer to driver SLI ring object. |
| 1571 | * @iocb: Pointer to iocb slot in the ring. |
| 1572 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1573 | * posted to firmware. |
| 1574 | * |
| 1575 | * This function is called with hbalock held to post a new iocb to |
| 1576 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1577 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1578 | * a completion call back for this iocb else the function will free the |
| 1579 | * iocb object. |
| 1580 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1581 | static void |
| 1582 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1583 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1584 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1585 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1587 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1589 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1591 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1592 | if (pring->ringno == LPFC_ELS_RING) { |
| 1593 | lpfc_debugfs_slow_ring_trc(phba, |
| 1594 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1595 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1596 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1597 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1598 | } |
| 1599 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1600 | /* |
| 1601 | * Issue iocb command to adapter |
| 1602 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1603 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1604 | wmb(); |
| 1605 | pring->stats.iocb_cmd++; |
| 1606 | |
| 1607 | /* |
| 1608 | * If there is no completion routine to call, we can release the |
| 1609 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1610 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1611 | */ |
| 1612 | if (nextiocb->iocb_cmpl) |
| 1613 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1614 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1615 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | |
| 1617 | /* |
| 1618 | * Let the HBA know what IOCB slot will be the next one the |
| 1619 | * driver will put a command into. |
| 1620 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1621 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1622 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | } |
| 1624 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1625 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1626 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1627 | * @phba: Pointer to HBA context object. |
| 1628 | * @pring: Pointer to driver SLI ring object. |
| 1629 | * |
| 1630 | * The caller is not required to hold any lock for calling this function. |
| 1631 | * This function updates the chip attention bits for the ring to inform firmware |
| 1632 | * that there are pending work to be done for this ring and requests an |
| 1633 | * interrupt when there is space available in the ring. This function is |
| 1634 | * called when the driver is unable to post more iocbs to the ring due |
| 1635 | * to unavailability of space in the ring. |
| 1636 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1637 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1638 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | { |
| 1640 | int ringno = pring->ringno; |
| 1641 | |
| 1642 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1643 | |
| 1644 | wmb(); |
| 1645 | |
| 1646 | /* |
| 1647 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1648 | * The HBA will tell us when an IOCB entry is available. |
| 1649 | */ |
| 1650 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1651 | readl(phba->CAregaddr); /* flush */ |
| 1652 | |
| 1653 | pring->stats.iocb_cmd_full++; |
| 1654 | } |
| 1655 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1656 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1657 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1658 | * @phba: Pointer to HBA context object. |
| 1659 | * @pring: Pointer to driver SLI ring object. |
| 1660 | * |
| 1661 | * This function updates the chip attention register bit for the |
| 1662 | * given ring to inform HBA that there is more work to be done |
| 1663 | * in this ring. The caller is not required to hold any lock. |
| 1664 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1665 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1666 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1667 | { |
| 1668 | int ringno = pring->ringno; |
| 1669 | |
| 1670 | /* |
| 1671 | * Tell the HBA that there is work to do in this ring. |
| 1672 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1673 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1674 | wmb(); |
| 1675 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1676 | readl(phba->CAregaddr); /* flush */ |
| 1677 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1678 | } |
| 1679 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1680 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1681 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1682 | * @phba: Pointer to HBA context object. |
| 1683 | * @pring: Pointer to driver SLI ring object. |
| 1684 | * |
| 1685 | * This function is called with hbalock held to post pending iocbs |
| 1686 | * in the txq to the firmware. This function is called when driver |
| 1687 | * detects space available in the ring. |
| 1688 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1690 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | { |
| 1692 | IOCB_t *iocb; |
| 1693 | struct lpfc_iocbq *nextiocb; |
| 1694 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1695 | lockdep_assert_held(&phba->hbalock); |
| 1696 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | /* |
| 1698 | * Check to see if: |
| 1699 | * (a) there is anything on the txq to send |
| 1700 | * (b) link is up |
| 1701 | * (c) link attention events can be processed (fcp ring only) |
| 1702 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1703 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1704 | |
| 1705 | if (lpfc_is_link_up(phba) && |
| 1706 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1707 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1708 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | |
| 1710 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1711 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1712 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1713 | |
| 1714 | if (iocb) |
| 1715 | lpfc_sli_update_ring(phba, pring); |
| 1716 | else |
| 1717 | lpfc_sli_update_full_ring(phba, pring); |
| 1718 | } |
| 1719 | |
| 1720 | return; |
| 1721 | } |
| 1722 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1723 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1724 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1725 | * @phba: Pointer to HBA context object. |
| 1726 | * @hbqno: HBQ number. |
| 1727 | * |
| 1728 | * This function is called with hbalock held to get the next |
| 1729 | * available slot for the given HBQ. If there is free slot |
| 1730 | * available for the HBQ it will return pointer to the next available |
| 1731 | * HBQ entry else it will return NULL. |
| 1732 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1733 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1734 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1735 | { |
| 1736 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1737 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1738 | lockdep_assert_held(&phba->hbalock); |
| 1739 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1740 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1741 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1742 | hbqp->next_hbqPutIdx = 0; |
| 1743 | |
| 1744 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1745 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1746 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1747 | |
| 1748 | hbqp->local_hbqGetIdx = getidx; |
| 1749 | |
| 1750 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1751 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1752 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1753 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1754 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1755 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1756 | hbqp->entry_count); |
| 1757 | |
| 1758 | phba->link_state = LPFC_HBA_ERROR; |
| 1759 | return NULL; |
| 1760 | } |
| 1761 | |
| 1762 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1763 | return NULL; |
| 1764 | } |
| 1765 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1766 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1767 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1768 | } |
| 1769 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1770 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1771 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1772 | * @phba: Pointer to HBA context object. |
| 1773 | * |
| 1774 | * This function is called with no lock held to free all the |
| 1775 | * hbq buffers while uninitializing the SLI interface. It also |
| 1776 | * frees the HBQ buffers returned by the firmware but not yet |
| 1777 | * processed by the upper layers. |
| 1778 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1779 | void |
| 1780 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1781 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1782 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1783 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1784 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1785 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1786 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1787 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1788 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1789 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1790 | for (i = 0; i < hbq_count; ++i) { |
| 1791 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1792 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1793 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1794 | list_del(&hbq_buf->dbuf.list); |
| 1795 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1796 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1797 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1798 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1799 | |
| 1800 | /* Mark the HBQs not in use */ |
| 1801 | phba->hbq_in_use = 0; |
| 1802 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1803 | } |
| 1804 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1805 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1806 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1807 | * @phba: Pointer to HBA context object. |
| 1808 | * @hbqno: HBQ number. |
| 1809 | * @hbq_buf: Pointer to HBQ buffer. |
| 1810 | * |
| 1811 | * This function is called with the hbalock held to post a |
| 1812 | * hbq buffer to the firmware. If the function finds an empty |
| 1813 | * slot in the HBQ, it will post the buffer. The function will return |
| 1814 | * pointer to the hbq entry if it successfully post the buffer |
| 1815 | * else it will return NULL. |
| 1816 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1817 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1818 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1819 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1820 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1821 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1822 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1827 | * @phba: Pointer to HBA context object. |
| 1828 | * @hbqno: HBQ number. |
| 1829 | * @hbq_buf: Pointer to HBQ buffer. |
| 1830 | * |
| 1831 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1832 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1833 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1834 | * it successfully post the buffer else it will return an error. |
| 1835 | **/ |
| 1836 | static int |
| 1837 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1838 | struct hbq_dmabuf *hbq_buf) |
| 1839 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1840 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1841 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1842 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1843 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1844 | /* Get next HBQ entry slot to use */ |
| 1845 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1846 | if (hbqe) { |
| 1847 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1848 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1849 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1850 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1851 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1852 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1853 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1854 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1855 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1856 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1857 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1858 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1859 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1860 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1861 | return 0; |
| 1862 | } else |
| 1863 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1864 | } |
| 1865 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1866 | /** |
| 1867 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1868 | * @phba: Pointer to HBA context object. |
| 1869 | * @hbqno: HBQ number. |
| 1870 | * @hbq_buf: Pointer to HBQ buffer. |
| 1871 | * |
| 1872 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1873 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1874 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1875 | **/ |
| 1876 | static int |
| 1877 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1878 | struct hbq_dmabuf *hbq_buf) |
| 1879 | { |
| 1880 | int rc; |
| 1881 | struct lpfc_rqe hrqe; |
| 1882 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1883 | struct lpfc_queue *hrq; |
| 1884 | struct lpfc_queue *drq; |
| 1885 | |
| 1886 | if (hbqno != LPFC_ELS_HBQ) |
| 1887 | return 1; |
| 1888 | hrq = phba->sli4_hba.hdr_rq; |
| 1889 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1890 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1891 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1892 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1893 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1894 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1895 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1896 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1897 | if (rc < 0) |
| 1898 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1899 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1900 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1901 | return 0; |
| 1902 | } |
| 1903 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1904 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1905 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1906 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1907 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1908 | .mask_count = 0, |
| 1909 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1910 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1911 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1912 | .init_count = 40, |
| 1913 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1914 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1915 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1916 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1917 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1918 | &lpfc_els_hbq, |
| 1919 | }; |
| 1920 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1921 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1922 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1923 | * @phba: Pointer to HBA context object. |
| 1924 | * @hbqno: HBQ number. |
| 1925 | * @count: Number of HBQ buffers to be posted. |
| 1926 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1927 | * This function is called with no lock held to post more hbq buffers to the |
| 1928 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1929 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1930 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1931 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1932 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1933 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1934 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1935 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1936 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1937 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1938 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1939 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1940 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1941 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1942 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1943 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1944 | phba->hbqs[hbqno].buffer_count; |
| 1945 | if (!count) |
| 1946 | return 0; |
| 1947 | /* Allocate HBQ entries */ |
| 1948 | for (i = 0; i < count; i++) { |
| 1949 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1950 | if (!hbq_buffer) |
| 1951 | break; |
| 1952 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1953 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1954 | /* Check whether HBQ is still in use */ |
| 1955 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1956 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1957 | goto err; |
| 1958 | while (!list_empty(&hbq_buf_list)) { |
| 1959 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1960 | dbuf.list); |
| 1961 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1962 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1963 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1964 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1965 | posted++; |
| 1966 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1967 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1968 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1969 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1970 | return posted; |
| 1971 | err: |
| 1972 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1973 | while (!list_empty(&hbq_buf_list)) { |
| 1974 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1975 | dbuf.list); |
| 1976 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1977 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1978 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1979 | } |
| 1980 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1981 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1982 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1983 | * @phba: Pointer to HBA context object. |
| 1984 | * @qno: HBQ number. |
| 1985 | * |
| 1986 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1987 | * is called with no lock held. The function returns the number of HBQ entries |
| 1988 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1989 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1990 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1991 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1992 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1993 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1994 | return 0; |
| 1995 | else |
| 1996 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1997 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1998 | } |
| 1999 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2000 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2001 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2002 | * @phba: Pointer to HBA context object. |
| 2003 | * @qno: HBQ queue number. |
| 2004 | * |
| 2005 | * This function is called from SLI initialization code path with |
| 2006 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2007 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2008 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2009 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2010 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2011 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2012 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2013 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2014 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2015 | else |
| 2016 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2017 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2018 | } |
| 2019 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2020 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2021 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2022 | * @phba: Pointer to HBA context object. |
| 2023 | * @hbqno: HBQ number. |
| 2024 | * |
| 2025 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2026 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2027 | **/ |
| 2028 | static struct hbq_dmabuf * |
| 2029 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2030 | { |
| 2031 | struct lpfc_dmabuf *d_buf; |
| 2032 | |
| 2033 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2034 | if (!d_buf) |
| 2035 | return NULL; |
| 2036 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2037 | } |
| 2038 | |
| 2039 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2040 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2041 | * @phba: Pointer to HBA context object. |
| 2042 | * @hbqno: HBQ number. |
| 2043 | * |
| 2044 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2045 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2046 | **/ |
| 2047 | static struct rqb_dmabuf * |
| 2048 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2049 | { |
| 2050 | struct lpfc_dmabuf *h_buf; |
| 2051 | struct lpfc_rqb *rqbp; |
| 2052 | |
| 2053 | rqbp = hrq->rqbp; |
| 2054 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2055 | struct lpfc_dmabuf, list); |
| 2056 | if (!h_buf) |
| 2057 | return NULL; |
| 2058 | rqbp->buffer_count--; |
| 2059 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2060 | } |
| 2061 | |
| 2062 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2063 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2064 | * @phba: Pointer to HBA context object. |
| 2065 | * @tag: Tag of the hbq buffer. |
| 2066 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2067 | * This function searches for the hbq buffer associated with the given tag in |
| 2068 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2069 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2070 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2071 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2072 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2073 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2074 | struct lpfc_dmabuf *d_buf; |
| 2075 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2076 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2077 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2078 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2079 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2080 | return NULL; |
| 2081 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2082 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2083 | 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] | 2084 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2085 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2086 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2087 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2088 | } |
| 2089 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2090 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2091 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2092 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2093 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2094 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2095 | } |
| 2096 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2097 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2098 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2099 | * @phba: Pointer to HBA context object. |
| 2100 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2101 | * |
| 2102 | * This function is called with hbalock. This function gives back |
| 2103 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2104 | * post the buffer, it will free the buffer. |
| 2105 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2106 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2107 | 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] | 2108 | { |
| 2109 | uint32_t hbqno; |
| 2110 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2111 | if (hbq_buffer) { |
| 2112 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2113 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2114 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2118 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2119 | * 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] | 2120 | * @mbxCommand: mailbox command code. |
| 2121 | * |
| 2122 | * This function is called by the mailbox event handler function to verify |
| 2123 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2124 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2125 | * and the mailbox event handler will take the HBA offline. |
| 2126 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | static int |
| 2128 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2129 | { |
| 2130 | uint8_t ret; |
| 2131 | |
| 2132 | switch (mbxCommand) { |
| 2133 | case MBX_LOAD_SM: |
| 2134 | case MBX_READ_NV: |
| 2135 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2136 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | case MBX_RUN_BIU_DIAG: |
| 2138 | case MBX_INIT_LINK: |
| 2139 | case MBX_DOWN_LINK: |
| 2140 | case MBX_CONFIG_LINK: |
| 2141 | case MBX_CONFIG_RING: |
| 2142 | case MBX_RESET_RING: |
| 2143 | case MBX_READ_CONFIG: |
| 2144 | case MBX_READ_RCONFIG: |
| 2145 | case MBX_READ_SPARM: |
| 2146 | case MBX_READ_STATUS: |
| 2147 | case MBX_READ_RPI: |
| 2148 | case MBX_READ_XRI: |
| 2149 | case MBX_READ_REV: |
| 2150 | case MBX_READ_LNK_STAT: |
| 2151 | case MBX_REG_LOGIN: |
| 2152 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | case MBX_CLEAR_LA: |
| 2154 | case MBX_DUMP_MEMORY: |
| 2155 | case MBX_DUMP_CONTEXT: |
| 2156 | case MBX_RUN_DIAGS: |
| 2157 | case MBX_RESTART: |
| 2158 | case MBX_UPDATE_CFG: |
| 2159 | case MBX_DOWN_LOAD: |
| 2160 | case MBX_DEL_LD_ENTRY: |
| 2161 | case MBX_RUN_PROGRAM: |
| 2162 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2163 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2165 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2167 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | case MBX_LOAD_AREA: |
| 2169 | case MBX_RUN_BIU_DIAG64: |
| 2170 | case MBX_CONFIG_PORT: |
| 2171 | case MBX_READ_SPARM64: |
| 2172 | case MBX_READ_RPI64: |
| 2173 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2174 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2175 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2176 | case MBX_SET_DEBUG: |
| 2177 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2178 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2179 | case MBX_REG_VPI: |
| 2180 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2181 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2182 | case MBX_PORT_CAPABILITIES: |
| 2183 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2184 | case MBX_SLI4_CONFIG: |
| 2185 | case MBX_SLI4_REQ_FTRS: |
| 2186 | case MBX_REG_FCFI: |
| 2187 | case MBX_UNREG_FCFI: |
| 2188 | case MBX_REG_VFI: |
| 2189 | case MBX_UNREG_VFI: |
| 2190 | case MBX_INIT_VPI: |
| 2191 | case MBX_INIT_VFI: |
| 2192 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2193 | case MBX_READ_EVENT_LOG_STATUS: |
| 2194 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2195 | case MBX_SECURITY_MGMT: |
| 2196 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2197 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | ret = mbxCommand; |
| 2199 | break; |
| 2200 | default: |
| 2201 | ret = MBX_SHUTDOWN; |
| 2202 | break; |
| 2203 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2204 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2206 | |
| 2207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2208 | * 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] | 2209 | * @phba: Pointer to HBA context object. |
| 2210 | * @pmboxq: Pointer to mailbox command. |
| 2211 | * |
| 2212 | * This is completion handler function for mailbox commands issued from |
| 2213 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2214 | * mailbox event handler function with no lock held. This function |
| 2215 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2216 | * of the mailbox. |
| 2217 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2218 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2219 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | { |
| 2221 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2222 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | |
| 2224 | /* |
| 2225 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2226 | * continued running. |
| 2227 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2228 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2229 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2231 | if (pdone_q) |
| 2232 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2233 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2234 | return; |
| 2235 | } |
| 2236 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2237 | |
| 2238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2239 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2240 | * @phba: Pointer to HBA context object. |
| 2241 | * @pmb: Pointer to mailbox object. |
| 2242 | * |
| 2243 | * This function is the default mailbox completion handler. It |
| 2244 | * frees the memory resources associated with the completed mailbox |
| 2245 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2246 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2247 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2249 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2251 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2253 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2254 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2255 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2256 | int rc; |
| 2257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2259 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | if (mp) { |
| 2261 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2262 | kfree(mp); |
| 2263 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2264 | |
| 2265 | /* |
| 2266 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2267 | * is in re-discovery driver need to cleanup the RPI. |
| 2268 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2269 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2270 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2271 | !pmb->u.mb.mbxStatus) { |
| 2272 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2273 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2274 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2275 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2276 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2277 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2278 | if (rc != MBX_NOT_FINISHED) |
| 2279 | return; |
| 2280 | } |
| 2281 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2282 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2283 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2284 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2285 | shost = lpfc_shost_from_vport(vport); |
| 2286 | spin_lock_irq(shost->host_lock); |
| 2287 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2288 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2289 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2290 | } |
| 2291 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2292 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2293 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2294 | lpfc_nlp_put(ndlp); |
| 2295 | pmb->context2 = NULL; |
| 2296 | } |
| 2297 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2298 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2299 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2300 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2301 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2302 | "2860 SLI authentication is required " |
| 2303 | "for INIT_LINK but has not done yet\n"); |
| 2304 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2305 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2306 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2307 | else |
| 2308 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2310 | /** |
| 2311 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2312 | * @phba: Pointer to HBA context object. |
| 2313 | * @pmb: Pointer to mailbox object. |
| 2314 | * |
| 2315 | * This function is the unreg rpi mailbox completion handler. It |
| 2316 | * frees the memory resources associated with the completed mailbox |
| 2317 | * command. An additional refrenece is put on the ndlp to prevent |
| 2318 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2319 | * the unreg mailbox command completes, this routine puts the |
| 2320 | * reference back. |
| 2321 | * |
| 2322 | **/ |
| 2323 | void |
| 2324 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2325 | { |
| 2326 | struct lpfc_vport *vport = pmb->vport; |
| 2327 | struct lpfc_nodelist *ndlp; |
| 2328 | |
| 2329 | ndlp = pmb->context1; |
| 2330 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2331 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2332 | (bf_get(lpfc_sli_intf_if_type, |
| 2333 | &phba->sli4_hba.sli_intf) == |
| 2334 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2335 | if (ndlp) { |
| 2336 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2337 | "0010 UNREG_LOGIN vpi:%x " |
| 2338 | "rpi:%x DID:%x map:%x %p\n", |
| 2339 | vport->vpi, ndlp->nlp_rpi, |
| 2340 | ndlp->nlp_DID, |
| 2341 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2342 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2343 | lpfc_nlp_put(ndlp); |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2349 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2350 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2351 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2352 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2353 | * @phba: Pointer to HBA context object. |
| 2354 | * |
| 2355 | * This function is called with no lock held. This function processes all |
| 2356 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2357 | * service routine processes mailbox completion interrupt and adds completed |
| 2358 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2359 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2360 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2361 | * function returns the mailbox commands to the upper layer by calling the |
| 2362 | * completion handler function of each mailbox. |
| 2363 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2365 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2367 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2369 | int rc; |
| 2370 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | |
| 2372 | phba->sli.slistat.mbox_event++; |
| 2373 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2374 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2375 | spin_lock_irq(&phba->hbalock); |
| 2376 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2377 | spin_unlock_irq(&phba->hbalock); |
| 2378 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2380 | do { |
| 2381 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2382 | if (pmb == NULL) |
| 2383 | break; |
| 2384 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2385 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2387 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2388 | if (pmb->vport) { |
| 2389 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2390 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2391 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2392 | (uint32_t)pmbox->mbxCommand, |
| 2393 | pmbox->un.varWords[0], |
| 2394 | pmbox->un.varWords[1]); |
| 2395 | } |
| 2396 | else { |
| 2397 | lpfc_debugfs_disc_trc(phba->pport, |
| 2398 | LPFC_DISC_TRC_MBOX, |
| 2399 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2400 | (uint32_t)pmbox->mbxCommand, |
| 2401 | pmbox->un.varWords[0], |
| 2402 | pmbox->un.varWords[1]); |
| 2403 | } |
| 2404 | } |
| 2405 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | /* |
| 2407 | * It is a fatal error if unknown mbox command completion. |
| 2408 | */ |
| 2409 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2410 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2411 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2412 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2413 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2414 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2415 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2416 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2417 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2418 | pmb), |
| 2419 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2420 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2421 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | phba->work_hs = HS_FFER3; |
| 2423 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2424 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | } |
| 2426 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | if (pmbox->mbxStatus) { |
| 2428 | phba->sli.slistat.mbox_stat_err++; |
| 2429 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2430 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2431 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2432 | LOG_MBOX | LOG_SLI, |
| 2433 | "(%d):0305 Mbox cmd cmpl " |
| 2434 | "error - RETRYing Data: x%x " |
| 2435 | "(x%x/x%x) x%x x%x x%x\n", |
| 2436 | pmb->vport ? pmb->vport->vpi : 0, |
| 2437 | pmbox->mbxCommand, |
| 2438 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2439 | pmb), |
| 2440 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2441 | pmb), |
| 2442 | pmbox->mbxStatus, |
| 2443 | pmbox->un.varWords[0], |
| 2444 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2445 | pmbox->mbxStatus = 0; |
| 2446 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2448 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2449 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2454 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2455 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2456 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2457 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2458 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2460 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2461 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | pmb->mbox_cmpl, |
| 2463 | *((uint32_t *) pmbox), |
| 2464 | pmbox->un.varWords[0], |
| 2465 | pmbox->un.varWords[1], |
| 2466 | pmbox->un.varWords[2], |
| 2467 | pmbox->un.varWords[3], |
| 2468 | pmbox->un.varWords[4], |
| 2469 | pmbox->un.varWords[5], |
| 2470 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2471 | pmbox->un.varWords[7], |
| 2472 | pmbox->un.varWords[8], |
| 2473 | pmbox->un.varWords[9], |
| 2474 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2475 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2476 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2477 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2478 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2479 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2480 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2481 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2482 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2483 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2484 | * @phba: Pointer to HBA context object. |
| 2485 | * @pring: Pointer to driver SLI ring object. |
| 2486 | * @tag: buffer tag. |
| 2487 | * |
| 2488 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2489 | * is set in the tag the buffer is posted for a particular exchange, |
| 2490 | * the function will return the buffer without replacing the buffer. |
| 2491 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2492 | * returns the buffer and also posts another buffer to the firmware. |
| 2493 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2494 | static struct lpfc_dmabuf * |
| 2495 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2496 | struct lpfc_sli_ring *pring, |
| 2497 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2498 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2499 | struct hbq_dmabuf *hbq_entry; |
| 2500 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2501 | if (tag & QUE_BUFTAG_BIT) |
| 2502 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2503 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2504 | if (!hbq_entry) |
| 2505 | return NULL; |
| 2506 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2507 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2508 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2509 | /** |
| 2510 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2511 | * @phba: Pointer to HBA context object. |
| 2512 | * @pring: Pointer to driver SLI ring object. |
| 2513 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2514 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2515 | * @fch_type: the type for the first frame of the sequence. |
| 2516 | * |
| 2517 | * This function is called with no lock held. This function uses the r_ctl and |
| 2518 | * type of the received sequence to find the correct callback function to call |
| 2519 | * to process the sequence. |
| 2520 | **/ |
| 2521 | static int |
| 2522 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2523 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2524 | uint32_t fch_type) |
| 2525 | { |
| 2526 | int i; |
| 2527 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2528 | switch (fch_type) { |
| 2529 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2530 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2531 | return 1; |
| 2532 | default: |
| 2533 | break; |
| 2534 | } |
| 2535 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2536 | /* unSolicited Responses */ |
| 2537 | if (pring->prt[0].profile) { |
| 2538 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2539 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2540 | saveq); |
| 2541 | return 1; |
| 2542 | } |
| 2543 | /* We must search, based on rctl / type |
| 2544 | for the right routine */ |
| 2545 | for (i = 0; i < pring->num_mask; i++) { |
| 2546 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2547 | (pring->prt[i].type == fch_type)) { |
| 2548 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2549 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2550 | (phba, pring, saveq); |
| 2551 | return 1; |
| 2552 | } |
| 2553 | } |
| 2554 | return 0; |
| 2555 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2556 | |
| 2557 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2558 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2559 | * @phba: Pointer to HBA context object. |
| 2560 | * @pring: Pointer to driver SLI ring object. |
| 2561 | * @saveq: Pointer to the unsolicited iocb. |
| 2562 | * |
| 2563 | * This function is called with no lock held by the ring event handler |
| 2564 | * when there is an unsolicited iocb posted to the response ring by the |
| 2565 | * firmware. This function gets the buffer associated with the iocbs |
| 2566 | * and calls the event handler for the ring. This function handles both |
| 2567 | * qring buffers and hbq buffers. |
| 2568 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2569 | * upper layer functions will free the iocb objects. |
| 2570 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | static int |
| 2572 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2573 | struct lpfc_iocbq *saveq) |
| 2574 | { |
| 2575 | IOCB_t * irsp; |
| 2576 | WORD5 * w5p; |
| 2577 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2578 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2579 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2580 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2582 | |
| 2583 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2584 | if (pring->lpfc_sli_rcv_async_status) |
| 2585 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2586 | else |
| 2587 | lpfc_printf_log(phba, |
| 2588 | KERN_WARNING, |
| 2589 | LOG_SLI, |
| 2590 | "0316 Ring %d handler: unexpected " |
| 2591 | "ASYNC_STATUS iocb received evt_code " |
| 2592 | "0x%x\n", |
| 2593 | pring->ringno, |
| 2594 | irsp->un.asyncstat.evt_code); |
| 2595 | return 1; |
| 2596 | } |
| 2597 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2598 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2599 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2600 | if (irsp->ulpBdeCount > 0) { |
| 2601 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2602 | irsp->un.ulpWord[3]); |
| 2603 | lpfc_in_buf_free(phba, dmzbuf); |
| 2604 | } |
| 2605 | |
| 2606 | if (irsp->ulpBdeCount > 1) { |
| 2607 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2608 | irsp->unsli3.sli3Words[3]); |
| 2609 | lpfc_in_buf_free(phba, dmzbuf); |
| 2610 | } |
| 2611 | |
| 2612 | if (irsp->ulpBdeCount > 2) { |
| 2613 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2614 | irsp->unsli3.sli3Words[7]); |
| 2615 | lpfc_in_buf_free(phba, dmzbuf); |
| 2616 | } |
| 2617 | |
| 2618 | return 1; |
| 2619 | } |
| 2620 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2621 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2622 | if (irsp->ulpBdeCount != 0) { |
| 2623 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2624 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2625 | if (!saveq->context2) |
| 2626 | lpfc_printf_log(phba, |
| 2627 | KERN_ERR, |
| 2628 | LOG_SLI, |
| 2629 | "0341 Ring %d Cannot find buffer for " |
| 2630 | "an unsolicited iocb. tag 0x%x\n", |
| 2631 | pring->ringno, |
| 2632 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2633 | } |
| 2634 | if (irsp->ulpBdeCount == 2) { |
| 2635 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2636 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2637 | if (!saveq->context3) |
| 2638 | lpfc_printf_log(phba, |
| 2639 | KERN_ERR, |
| 2640 | LOG_SLI, |
| 2641 | "0342 Ring %d Cannot find buffer for an" |
| 2642 | " unsolicited iocb. tag 0x%x\n", |
| 2643 | pring->ringno, |
| 2644 | irsp->unsli3.sli3Words[7]); |
| 2645 | } |
| 2646 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2647 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2648 | if (irsp->ulpBdeCount != 0) { |
| 2649 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2650 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2651 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2652 | lpfc_printf_log(phba, |
| 2653 | KERN_ERR, |
| 2654 | LOG_SLI, |
| 2655 | "0343 Ring %d Cannot find " |
| 2656 | "buffer for an unsolicited iocb" |
| 2657 | ". tag 0x%x\n", pring->ringno, |
| 2658 | irsp->un.ulpWord[3]); |
| 2659 | } |
| 2660 | if (irsp->ulpBdeCount == 2) { |
| 2661 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2662 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2663 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2664 | lpfc_printf_log(phba, |
| 2665 | KERN_ERR, |
| 2666 | LOG_SLI, |
| 2667 | "0344 Ring %d Cannot find " |
| 2668 | "buffer for an unsolicited " |
| 2669 | "iocb. tag 0x%x\n", |
| 2670 | pring->ringno, |
| 2671 | irsp->unsli3.sli3Words[7]); |
| 2672 | } |
| 2673 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2674 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2675 | if (irsp->ulpBdeCount != 0 && |
| 2676 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2677 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2678 | int found = 0; |
| 2679 | |
| 2680 | /* search continue save q for same XRI */ |
| 2681 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2682 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2683 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2684 | list_add_tail(&saveq->list, &iocbq->list); |
| 2685 | found = 1; |
| 2686 | break; |
| 2687 | } |
| 2688 | } |
| 2689 | if (!found) |
| 2690 | list_add_tail(&saveq->clist, |
| 2691 | &pring->iocb_continue_saveq); |
| 2692 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2693 | list_del_init(&iocbq->clist); |
| 2694 | saveq = iocbq; |
| 2695 | irsp = &(saveq->iocb); |
| 2696 | } else |
| 2697 | return 0; |
| 2698 | } |
| 2699 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2700 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2701 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2702 | Rctl = FC_RCTL_ELS_REQ; |
| 2703 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2704 | } else { |
| 2705 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2706 | Rctl = w5p->hcsw.Rctl; |
| 2707 | Type = w5p->hcsw.Type; |
| 2708 | |
| 2709 | /* Firmware Workaround */ |
| 2710 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2711 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2712 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2713 | Rctl = FC_RCTL_ELS_REQ; |
| 2714 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2715 | w5p->hcsw.Rctl = Rctl; |
| 2716 | w5p->hcsw.Type = Type; |
| 2717 | } |
| 2718 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2719 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2720 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2721 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2722 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2723 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2724 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2725 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2726 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2727 | } |
| 2728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2730 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2731 | * @phba: Pointer to HBA context object. |
| 2732 | * @pring: Pointer to driver SLI ring object. |
| 2733 | * @prspiocb: Pointer to response iocb object. |
| 2734 | * |
| 2735 | * This function looks up the iocb_lookup table to get the command iocb |
| 2736 | * corresponding to the given response iocb using the iotag of the |
| 2737 | * response iocb. This function is called with the hbalock held. |
| 2738 | * This function returns the command iocb object if it finds the command |
| 2739 | * iocb else returns NULL. |
| 2740 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2742 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2743 | struct lpfc_sli_ring *pring, |
| 2744 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2747 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2748 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2749 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2750 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2752 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2753 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2754 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2755 | /* remove from txcmpl queue list */ |
| 2756 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2757 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2758 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2759 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | } |
| 2761 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2762 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2763 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2764 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2765 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2766 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2767 | return NULL; |
| 2768 | } |
| 2769 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2770 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2771 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2772 | * @phba: Pointer to HBA context object. |
| 2773 | * @pring: Pointer to driver SLI ring object. |
| 2774 | * @iotag: IOCB tag. |
| 2775 | * |
| 2776 | * This function looks up the iocb_lookup table to get the command iocb |
| 2777 | * corresponding to the given iotag. This function is called with the |
| 2778 | * hbalock held. |
| 2779 | * This function returns the command iocb object if it finds the command |
| 2780 | * iocb else returns NULL. |
| 2781 | **/ |
| 2782 | static struct lpfc_iocbq * |
| 2783 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2784 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2785 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2786 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2787 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2788 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2789 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2790 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2791 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2792 | /* remove from txcmpl queue list */ |
| 2793 | list_del_init(&cmd_iocb->list); |
| 2794 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2795 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2796 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2797 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2798 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2799 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2800 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 2801 | "iocb_flag x%x\n", |
| 2802 | iotag, phba->sli.last_iotag, |
| 2803 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2804 | return NULL; |
| 2805 | } |
| 2806 | |
| 2807 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2808 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2809 | * @phba: Pointer to HBA context object. |
| 2810 | * @pring: Pointer to driver SLI ring object. |
| 2811 | * @saveq: Pointer to the response iocb to be processed. |
| 2812 | * |
| 2813 | * This function is called by the ring event handler for non-fcp |
| 2814 | * rings when there is a new response iocb in the response ring. |
| 2815 | * The caller is not required to hold any locks. This function |
| 2816 | * gets the command iocb associated with the response iocb and |
| 2817 | * calls the completion handler for the command iocb. If there |
| 2818 | * is no completion handler, the function will free the resources |
| 2819 | * associated with command iocb. If the response iocb is for |
| 2820 | * an already aborted command iocb, the status of the completion |
| 2821 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2822 | * This function always returns 1. |
| 2823 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2825 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | struct lpfc_iocbq *saveq) |
| 2827 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2828 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | int rc = 1; |
| 2830 | unsigned long iflag; |
| 2831 | |
| 2832 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2833 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2834 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2835 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2836 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2837 | if (cmdiocbp) { |
| 2838 | if (cmdiocbp->iocb_cmpl) { |
| 2839 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2840 | * If an ELS command failed send an event to mgmt |
| 2841 | * application. |
| 2842 | */ |
| 2843 | if (saveq->iocb.ulpStatus && |
| 2844 | (pring->ringno == LPFC_ELS_RING) && |
| 2845 | (cmdiocbp->iocb.ulpCommand == |
| 2846 | CMD_ELS_REQUEST64_CR)) |
| 2847 | lpfc_send_els_failure_event(phba, |
| 2848 | cmdiocbp, saveq); |
| 2849 | |
| 2850 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | * Post all ELS completions to the worker thread. |
| 2852 | * All other are passed to the completion callback. |
| 2853 | */ |
| 2854 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2855 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2856 | (cmdiocbp->iocb_flag & |
| 2857 | LPFC_DRIVER_ABORTED)) { |
| 2858 | spin_lock_irqsave(&phba->hbalock, |
| 2859 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2860 | cmdiocbp->iocb_flag &= |
| 2861 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2862 | spin_unlock_irqrestore(&phba->hbalock, |
| 2863 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2864 | saveq->iocb.ulpStatus = |
| 2865 | IOSTAT_LOCAL_REJECT; |
| 2866 | saveq->iocb.un.ulpWord[4] = |
| 2867 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2868 | |
| 2869 | /* Firmware could still be in progress |
| 2870 | * of DMAing payload, so don't free data |
| 2871 | * buffer till after a hbeat. |
| 2872 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2873 | spin_lock_irqsave(&phba->hbalock, |
| 2874 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2875 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2876 | spin_unlock_irqrestore(&phba->hbalock, |
| 2877 | iflag); |
| 2878 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2879 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2880 | if (saveq->iocb_flag & |
| 2881 | LPFC_EXCHANGE_BUSY) { |
| 2882 | /* Set cmdiocb flag for the |
| 2883 | * exchange busy so sgl (xri) |
| 2884 | * will not be released until |
| 2885 | * the abort xri is received |
| 2886 | * from hba. |
| 2887 | */ |
| 2888 | spin_lock_irqsave( |
| 2889 | &phba->hbalock, iflag); |
| 2890 | cmdiocbp->iocb_flag |= |
| 2891 | LPFC_EXCHANGE_BUSY; |
| 2892 | spin_unlock_irqrestore( |
| 2893 | &phba->hbalock, iflag); |
| 2894 | } |
| 2895 | if (cmdiocbp->iocb_flag & |
| 2896 | LPFC_DRIVER_ABORTED) { |
| 2897 | /* |
| 2898 | * Clear LPFC_DRIVER_ABORTED |
| 2899 | * bit in case it was driver |
| 2900 | * initiated abort. |
| 2901 | */ |
| 2902 | spin_lock_irqsave( |
| 2903 | &phba->hbalock, iflag); |
| 2904 | cmdiocbp->iocb_flag &= |
| 2905 | ~LPFC_DRIVER_ABORTED; |
| 2906 | spin_unlock_irqrestore( |
| 2907 | &phba->hbalock, iflag); |
| 2908 | cmdiocbp->iocb.ulpStatus = |
| 2909 | IOSTAT_LOCAL_REJECT; |
| 2910 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2911 | IOERR_ABORT_REQUESTED; |
| 2912 | /* |
| 2913 | * For SLI4, irsiocb contains |
| 2914 | * NO_XRI in sli_xritag, it |
| 2915 | * shall not affect releasing |
| 2916 | * sgl (xri) process. |
| 2917 | */ |
| 2918 | saveq->iocb.ulpStatus = |
| 2919 | IOSTAT_LOCAL_REJECT; |
| 2920 | saveq->iocb.un.ulpWord[4] = |
| 2921 | IOERR_SLI_ABORTED; |
| 2922 | spin_lock_irqsave( |
| 2923 | &phba->hbalock, iflag); |
| 2924 | saveq->iocb_flag |= |
| 2925 | LPFC_DELAY_MEM_FREE; |
| 2926 | spin_unlock_irqrestore( |
| 2927 | &phba->hbalock, iflag); |
| 2928 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2929 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2930 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2931 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2932 | } else |
| 2933 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2934 | } else { |
| 2935 | /* |
| 2936 | * Unknown initiating command based on the response iotag. |
| 2937 | * This could be the case on the ELS ring because of |
| 2938 | * lpfc_els_abort(). |
| 2939 | */ |
| 2940 | if (pring->ringno != LPFC_ELS_RING) { |
| 2941 | /* |
| 2942 | * Ring <ringno> handler: unexpected completion IoTag |
| 2943 | * <IoTag> |
| 2944 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2945 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2946 | "0322 Ring %d handler: " |
| 2947 | "unexpected completion IoTag x%x " |
| 2948 | "Data: x%x x%x x%x x%x\n", |
| 2949 | pring->ringno, |
| 2950 | saveq->iocb.ulpIoTag, |
| 2951 | saveq->iocb.ulpStatus, |
| 2952 | saveq->iocb.un.ulpWord[4], |
| 2953 | saveq->iocb.ulpCommand, |
| 2954 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2955 | } |
| 2956 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2957 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2958 | return rc; |
| 2959 | } |
| 2960 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2961 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2962 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2963 | * @phba: Pointer to HBA context object. |
| 2964 | * @pring: Pointer to driver SLI ring object. |
| 2965 | * |
| 2966 | * This function is called from the iocb ring event handlers when |
| 2967 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2968 | * an error attention condition to the worker thread and the worker |
| 2969 | * thread will transition the HBA to offline state. |
| 2970 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2971 | static void |
| 2972 | 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] | 2973 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2974 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2975 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2976 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2977 | * rsp ring <portRspMax> |
| 2978 | */ |
| 2979 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2980 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2981 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2982 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2983 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2984 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2985 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2986 | |
| 2987 | /* |
| 2988 | * All error attention handlers are posted to |
| 2989 | * worker thread |
| 2990 | */ |
| 2991 | phba->work_ha |= HA_ERATT; |
| 2992 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2993 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2994 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2995 | |
| 2996 | return; |
| 2997 | } |
| 2998 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2999 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3000 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3001 | * @ptr: Pointer to address of HBA context object. |
| 3002 | * |
| 3003 | * This function is invoked by the Error Attention polling timer when the |
| 3004 | * timer times out. It will check the SLI Error Attention register for |
| 3005 | * possible attention events. If so, it will post an Error Attention event |
| 3006 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3007 | * Error Attention polling timer for the next poll. |
| 3008 | **/ |
| 3009 | void lpfc_poll_eratt(unsigned long ptr) |
| 3010 | { |
| 3011 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3012 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3013 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3014 | |
| 3015 | phba = (struct lpfc_hba *)ptr; |
| 3016 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3017 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3018 | sli_intr = phba->sli.slistat.sli_intr; |
| 3019 | |
| 3020 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3021 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3022 | sli_intr); |
| 3023 | else |
| 3024 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3025 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3026 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3027 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3028 | phba->sli.slistat.sli_ips = cnt; |
| 3029 | |
| 3030 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3031 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3032 | /* Check chip HA register for error event */ |
| 3033 | eratt = lpfc_sli_check_eratt(phba); |
| 3034 | |
| 3035 | if (eratt) |
| 3036 | /* Tell the worker thread there is work to do */ |
| 3037 | lpfc_worker_wake_up(phba); |
| 3038 | else |
| 3039 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3040 | mod_timer(&phba->eratt_poll, |
| 3041 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3042 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3043 | return; |
| 3044 | } |
| 3045 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3046 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3047 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3048 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3049 | * @phba: Pointer to HBA context object. |
| 3050 | * @pring: Pointer to driver SLI ring object. |
| 3051 | * @mask: Host attention register mask for this ring. |
| 3052 | * |
| 3053 | * This function is called from the interrupt context when there is a ring |
| 3054 | * event for the fcp ring. The caller does not hold any lock. |
| 3055 | * 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] | 3056 | * 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] | 3057 | * LE bit set. The function will call the completion handler of the command iocb |
| 3058 | * if the response iocb indicates a completion for a command iocb or it is |
| 3059 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3060 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3061 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3062 | * to check it explicitly. |
| 3063 | */ |
| 3064 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3065 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3066 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3068 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3070 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3071 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3072 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3073 | uint32_t status; |
| 3074 | uint32_t portRspPut, portRspMax; |
| 3075 | int rc = 1; |
| 3076 | lpfc_iocb_type type; |
| 3077 | unsigned long iflag; |
| 3078 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3080 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3081 | pring->stats.iocb_event++; |
| 3082 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3083 | /* |
| 3084 | * The next available response entry should never exceed the maximum |
| 3085 | * entries. If it does, treat it as an adapter hardware error. |
| 3086 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3087 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3088 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3089 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3090 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3091 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3092 | return 1; |
| 3093 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3094 | if (phba->fcp_ring_in_use) { |
| 3095 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3096 | return 1; |
| 3097 | } else |
| 3098 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3099 | |
| 3100 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3101 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3102 | /* |
| 3103 | * Fetch an entry off the ring and copy it into a local data |
| 3104 | * structure. The copy involves a byte-swap since the |
| 3105 | * network byte order and pci byte orders are different. |
| 3106 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3107 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3108 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3109 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3110 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3111 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3112 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3113 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3114 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3115 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3116 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3117 | irsp = &rspiocbq.iocb; |
| 3118 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3120 | pring->stats.iocb_rsp++; |
| 3121 | rsp_cmpl++; |
| 3122 | |
| 3123 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3124 | /* |
| 3125 | * If resource errors reported from HBA, reduce |
| 3126 | * queuedepths of the SCSI device. |
| 3127 | */ |
| 3128 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3129 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3130 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3131 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3132 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3133 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3134 | } |
| 3135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | /* Rsp ring <ringno> error: IOCB */ |
| 3137 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3138 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3139 | "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] | 3140 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3141 | irsp->un.ulpWord[0], |
| 3142 | irsp->un.ulpWord[1], |
| 3143 | irsp->un.ulpWord[2], |
| 3144 | irsp->un.ulpWord[3], |
| 3145 | irsp->un.ulpWord[4], |
| 3146 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3147 | *(uint32_t *)&irsp->un1, |
| 3148 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | switch (type) { |
| 3152 | case LPFC_ABORT_IOCB: |
| 3153 | case LPFC_SOL_IOCB: |
| 3154 | /* |
| 3155 | * Idle exchange closed via ABTS from port. No iocb |
| 3156 | * resources need to be recovered. |
| 3157 | */ |
| 3158 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3159 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3160 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3161 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3162 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3163 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | break; |
| 3165 | } |
| 3166 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3167 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3168 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3169 | if (unlikely(!cmdiocbq)) |
| 3170 | break; |
| 3171 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3172 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3173 | if (cmdiocbq->iocb_cmpl) { |
| 3174 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3175 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3176 | &rspiocbq); |
| 3177 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3178 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3179 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3180 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3181 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3182 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3183 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3184 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3185 | default: |
| 3186 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3187 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3188 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3189 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3190 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3191 | dev_warn(&((phba->pcidev)->dev), |
| 3192 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3193 | phba->brd_no, adaptermsg); |
| 3194 | } else { |
| 3195 | /* Unknown IOCB command */ |
| 3196 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3197 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3198 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3199 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3200 | irsp->ulpStatus, |
| 3201 | irsp->ulpIoTag, |
| 3202 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | } |
| 3204 | break; |
| 3205 | } |
| 3206 | |
| 3207 | /* |
| 3208 | * The response IOCB has been processed. Update the ring |
| 3209 | * pointer in SLIM. If the port response put pointer has not |
| 3210 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3211 | * response put pointer. |
| 3212 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3213 | writel(pring->sli.sli3.rspidx, |
| 3214 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3216 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3218 | } |
| 3219 | |
| 3220 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3221 | pring->stats.iocb_rsp_full++; |
| 3222 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3223 | writel(status, phba->CAregaddr); |
| 3224 | readl(phba->CAregaddr); |
| 3225 | } |
| 3226 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3227 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3228 | pring->stats.iocb_cmd_empty++; |
| 3229 | |
| 3230 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3231 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3232 | lpfc_sli_resume_iocb(phba, pring); |
| 3233 | |
| 3234 | if ((pring->lpfc_sli_cmd_available)) |
| 3235 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3236 | |
| 3237 | } |
| 3238 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3239 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3240 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3241 | return rc; |
| 3242 | } |
| 3243 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3244 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3245 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3246 | * @phba: Pointer to HBA context object. |
| 3247 | * @pring: Pointer to driver SLI ring object. |
| 3248 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3249 | * |
| 3250 | * This function is called from the worker thread when there is a slow-path |
| 3251 | * response IOCB to process. This function chains all the response iocbs until |
| 3252 | * seeing the iocb with the LE bit set. The function will call |
| 3253 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3254 | * completion of a command iocb. The function will call the |
| 3255 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3256 | * The function frees the resources or calls the completion handler if this |
| 3257 | * iocb is an abort completion. The function returns NULL when the response |
| 3258 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3259 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3260 | * response iocb passed in. |
| 3261 | **/ |
| 3262 | static struct lpfc_iocbq * |
| 3263 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3264 | struct lpfc_iocbq *rspiocbp) |
| 3265 | { |
| 3266 | struct lpfc_iocbq *saveq; |
| 3267 | struct lpfc_iocbq *cmdiocbp; |
| 3268 | struct lpfc_iocbq *next_iocb; |
| 3269 | IOCB_t *irsp = NULL; |
| 3270 | uint32_t free_saveq; |
| 3271 | uint8_t iocb_cmd_type; |
| 3272 | lpfc_iocb_type type; |
| 3273 | unsigned long iflag; |
| 3274 | int rc; |
| 3275 | |
| 3276 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3277 | /* First add the response iocb to the countinueq list */ |
| 3278 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3279 | pring->iocb_continueq_cnt++; |
| 3280 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3281 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3282 | irsp = &rspiocbp->iocb; |
| 3283 | if (irsp->ulpLe) { |
| 3284 | /* |
| 3285 | * By default, the driver expects to free all resources |
| 3286 | * associated with this iocb completion. |
| 3287 | */ |
| 3288 | free_saveq = 1; |
| 3289 | saveq = list_get_first(&pring->iocb_continueq, |
| 3290 | struct lpfc_iocbq, list); |
| 3291 | irsp = &(saveq->iocb); |
| 3292 | list_del_init(&pring->iocb_continueq); |
| 3293 | pring->iocb_continueq_cnt = 0; |
| 3294 | |
| 3295 | pring->stats.iocb_rsp++; |
| 3296 | |
| 3297 | /* |
| 3298 | * If resource errors reported from HBA, reduce |
| 3299 | * queuedepths of the SCSI device. |
| 3300 | */ |
| 3301 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3302 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3303 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3304 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3305 | phba->lpfc_rampdown_queue_depth(phba); |
| 3306 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3307 | } |
| 3308 | |
| 3309 | if (irsp->ulpStatus) { |
| 3310 | /* Rsp ring <ringno> error: IOCB */ |
| 3311 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3312 | "0328 Rsp Ring %d error: " |
| 3313 | "IOCB Data: " |
| 3314 | "x%x x%x x%x x%x " |
| 3315 | "x%x x%x x%x x%x " |
| 3316 | "x%x x%x x%x x%x " |
| 3317 | "x%x x%x x%x x%x\n", |
| 3318 | pring->ringno, |
| 3319 | irsp->un.ulpWord[0], |
| 3320 | irsp->un.ulpWord[1], |
| 3321 | irsp->un.ulpWord[2], |
| 3322 | irsp->un.ulpWord[3], |
| 3323 | irsp->un.ulpWord[4], |
| 3324 | irsp->un.ulpWord[5], |
| 3325 | *(((uint32_t *) irsp) + 6), |
| 3326 | *(((uint32_t *) irsp) + 7), |
| 3327 | *(((uint32_t *) irsp) + 8), |
| 3328 | *(((uint32_t *) irsp) + 9), |
| 3329 | *(((uint32_t *) irsp) + 10), |
| 3330 | *(((uint32_t *) irsp) + 11), |
| 3331 | *(((uint32_t *) irsp) + 12), |
| 3332 | *(((uint32_t *) irsp) + 13), |
| 3333 | *(((uint32_t *) irsp) + 14), |
| 3334 | *(((uint32_t *) irsp) + 15)); |
| 3335 | } |
| 3336 | |
| 3337 | /* |
| 3338 | * Fetch the IOCB command type and call the correct completion |
| 3339 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3340 | * get freed back to the lpfc_iocb_list by the discovery |
| 3341 | * kernel thread. |
| 3342 | */ |
| 3343 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3344 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3345 | switch (type) { |
| 3346 | case LPFC_SOL_IOCB: |
| 3347 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3348 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3349 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3350 | break; |
| 3351 | |
| 3352 | case LPFC_UNSOL_IOCB: |
| 3353 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3354 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3355 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3356 | if (!rc) |
| 3357 | free_saveq = 0; |
| 3358 | break; |
| 3359 | |
| 3360 | case LPFC_ABORT_IOCB: |
| 3361 | cmdiocbp = NULL; |
| 3362 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3363 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3364 | saveq); |
| 3365 | if (cmdiocbp) { |
| 3366 | /* Call the specified completion routine */ |
| 3367 | if (cmdiocbp->iocb_cmpl) { |
| 3368 | spin_unlock_irqrestore(&phba->hbalock, |
| 3369 | iflag); |
| 3370 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3371 | saveq); |
| 3372 | spin_lock_irqsave(&phba->hbalock, |
| 3373 | iflag); |
| 3374 | } else |
| 3375 | __lpfc_sli_release_iocbq(phba, |
| 3376 | cmdiocbp); |
| 3377 | } |
| 3378 | break; |
| 3379 | |
| 3380 | case LPFC_UNKNOWN_IOCB: |
| 3381 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3382 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3383 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3384 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3385 | MAX_MSG_DATA); |
| 3386 | dev_warn(&((phba->pcidev)->dev), |
| 3387 | "lpfc%d: %s\n", |
| 3388 | phba->brd_no, adaptermsg); |
| 3389 | } else { |
| 3390 | /* Unknown IOCB command */ |
| 3391 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3392 | "0335 Unknown IOCB " |
| 3393 | "command Data: x%x " |
| 3394 | "x%x x%x x%x\n", |
| 3395 | irsp->ulpCommand, |
| 3396 | irsp->ulpStatus, |
| 3397 | irsp->ulpIoTag, |
| 3398 | irsp->ulpContext); |
| 3399 | } |
| 3400 | break; |
| 3401 | } |
| 3402 | |
| 3403 | if (free_saveq) { |
| 3404 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3405 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3406 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3407 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3408 | } |
| 3409 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3410 | } |
| 3411 | rspiocbp = NULL; |
| 3412 | } |
| 3413 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3414 | return rspiocbp; |
| 3415 | } |
| 3416 | |
| 3417 | /** |
| 3418 | * 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] | 3419 | * @phba: Pointer to HBA context object. |
| 3420 | * @pring: Pointer to driver SLI ring object. |
| 3421 | * @mask: Host attention register mask for this ring. |
| 3422 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3423 | * This routine wraps the actual slow_ring event process routine from the |
| 3424 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3425 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3426 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3427 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3428 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3430 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3431 | } |
| 3432 | |
| 3433 | /** |
| 3434 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3435 | * @phba: Pointer to HBA context object. |
| 3436 | * @pring: Pointer to driver SLI ring object. |
| 3437 | * @mask: Host attention register mask for this ring. |
| 3438 | * |
| 3439 | * This function is called from the worker thread when there is a ring event |
| 3440 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3441 | * remove each response iocb in the response ring and calls the handle |
| 3442 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3443 | **/ |
| 3444 | static void |
| 3445 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3446 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3447 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3448 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | IOCB_t *entry; |
| 3450 | IOCB_t *irsp = NULL; |
| 3451 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3452 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3454 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3456 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3457 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | pring->stats.iocb_event++; |
| 3459 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | /* |
| 3461 | * The next available response entry should never exceed the maximum |
| 3462 | * entries. If it does, treat it as an adapter hardware error. |
| 3463 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3464 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3466 | if (portRspPut >= portRspMax) { |
| 3467 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3468 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | * rsp ring <portRspMax> |
| 3470 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3471 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3472 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3473 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3474 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3475 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3476 | phba->link_state = LPFC_HBA_ERROR; |
| 3477 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3478 | |
| 3479 | phba->work_hs = HS_FFER3; |
| 3480 | lpfc_handle_eratt(phba); |
| 3481 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3482 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3486 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3487 | /* |
| 3488 | * Build a completion list and call the appropriate handler. |
| 3489 | * The process is to get the next available response iocb, get |
| 3490 | * a free iocb from the list, copy the response data into the |
| 3491 | * free iocb, insert to the continuation list, and update the |
| 3492 | * next response index to slim. This process makes response |
| 3493 | * iocb's in the ring available to DMA as fast as possible but |
| 3494 | * pays a penalty for a copy operation. Since the iocb is |
| 3495 | * only 32 bytes, this penalty is considered small relative to |
| 3496 | * the PCI reads for register values and a slim write. When |
| 3497 | * the ulpLe field is set, the entire Command has been |
| 3498 | * received. |
| 3499 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3500 | entry = lpfc_resp_iocb(phba, pring); |
| 3501 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3502 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3503 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3504 | if (rspiocbp == NULL) { |
| 3505 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3506 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | break; |
| 3508 | } |
| 3509 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3510 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3511 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | irsp = &rspiocbp->iocb; |
| 3513 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3514 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3515 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3516 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3517 | if (pring->ringno == LPFC_ELS_RING) { |
| 3518 | lpfc_debugfs_slow_ring_trc(phba, |
| 3519 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3520 | *(((uint32_t *) irsp) + 4), |
| 3521 | *(((uint32_t *) irsp) + 6), |
| 3522 | *(((uint32_t *) irsp) + 7)); |
| 3523 | } |
| 3524 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3525 | writel(pring->sli.sli3.rspidx, |
| 3526 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3527 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3528 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3529 | /* Handle the response IOCB */ |
| 3530 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3531 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3532 | |
| 3533 | /* |
| 3534 | * If the port response put pointer has not been updated, sync |
| 3535 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3536 | * response put pointer. |
| 3537 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3538 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3540 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3541 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3543 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3544 | /* At least one response entry has been freed */ |
| 3545 | pring->stats.iocb_rsp_full++; |
| 3546 | /* SET RxRE_RSP in Chip Att register */ |
| 3547 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3548 | writel(status, phba->CAregaddr); |
| 3549 | readl(phba->CAregaddr); /* flush */ |
| 3550 | } |
| 3551 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3552 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3553 | pring->stats.iocb_cmd_empty++; |
| 3554 | |
| 3555 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3556 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3557 | lpfc_sli_resume_iocb(phba, pring); |
| 3558 | |
| 3559 | if ((pring->lpfc_sli_cmd_available)) |
| 3560 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3561 | |
| 3562 | } |
| 3563 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3564 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3565 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | } |
| 3567 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3568 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3569 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3570 | * @phba: Pointer to HBA context object. |
| 3571 | * @pring: Pointer to driver SLI ring object. |
| 3572 | * @mask: Host attention register mask for this ring. |
| 3573 | * |
| 3574 | * This function is called from the worker thread when there is a pending |
| 3575 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3576 | * queue. The caller does not hold any lock. The function will remove each |
| 3577 | * response iocb from the response worker queue and calls the handle |
| 3578 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3579 | **/ |
| 3580 | static void |
| 3581 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3582 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3583 | { |
| 3584 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3585 | struct hbq_dmabuf *dmabuf; |
| 3586 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3587 | unsigned long iflag; |
James Smart | 7f4b23e | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3588 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3589 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3590 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3591 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3592 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3593 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3594 | /* Get the response iocb from the head of work queue */ |
| 3595 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3596 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3597 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3598 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3599 | |
| 3600 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3601 | case CQE_CODE_COMPL_WQE: |
| 3602 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3603 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3604 | /* Translate ELS WCQE to response IOCBQ */ |
| 3605 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3606 | irspiocbq); |
| 3607 | if (irspiocbq) |
| 3608 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3609 | irspiocbq); |
James Smart | 7f4b23e | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3610 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3611 | break; |
| 3612 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3613 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3614 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3615 | cq_event); |
| 3616 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 7f4b23e | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3617 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3618 | break; |
| 3619 | default: |
| 3620 | break; |
| 3621 | } |
James Smart | 7f4b23e | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3622 | |
| 3623 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 3624 | if (count == 64) |
| 3625 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3630 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3631 | * @phba: Pointer to HBA context object. |
| 3632 | * @pring: Pointer to driver SLI ring object. |
| 3633 | * |
| 3634 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3635 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3636 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3637 | * the return of this function. The caller is not required to hold any locks. |
| 3638 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3639 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3640 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3641 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3642 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3643 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3644 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3645 | if (pring->ringno == LPFC_ELS_RING) { |
| 3646 | lpfc_fabric_abort_hba(phba); |
| 3647 | } |
| 3648 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | /* Error everything on txq and txcmplq |
| 3650 | * First do the txq. |
| 3651 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3652 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3653 | spin_lock_irq(&pring->ring_lock); |
| 3654 | list_splice_init(&pring->txq, &completions); |
| 3655 | pring->txq_cnt = 0; |
| 3656 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3657 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3658 | spin_lock_irq(&phba->hbalock); |
| 3659 | /* Next issue ABTS for everything on the txcmplq */ |
| 3660 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3661 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3662 | spin_unlock_irq(&phba->hbalock); |
| 3663 | } else { |
| 3664 | spin_lock_irq(&phba->hbalock); |
| 3665 | list_splice_init(&pring->txq, &completions); |
| 3666 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3667 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3668 | /* Next issue ABTS for everything on the txcmplq */ |
| 3669 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3670 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3671 | spin_unlock_irq(&phba->hbalock); |
| 3672 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3673 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3674 | /* Cancel all the IOCBs from the completions list */ |
| 3675 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3676 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3677 | } |
| 3678 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3679 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3680 | * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring |
| 3681 | * @phba: Pointer to HBA context object. |
| 3682 | * @pring: Pointer to driver SLI ring object. |
| 3683 | * |
| 3684 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3685 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3686 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3687 | * the return of this function. The caller is not required to hold any locks. |
| 3688 | **/ |
| 3689 | void |
| 3690 | lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3691 | { |
| 3692 | LIST_HEAD(completions); |
| 3693 | struct lpfc_iocbq *iocb, *next_iocb; |
| 3694 | |
| 3695 | if (pring->ringno == LPFC_ELS_RING) |
| 3696 | lpfc_fabric_abort_hba(phba); |
| 3697 | |
| 3698 | spin_lock_irq(&phba->hbalock); |
| 3699 | /* Next issue ABTS for everything on the txcmplq */ |
| 3700 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3701 | lpfc_sli4_abort_nvme_io(phba, pring, iocb); |
| 3702 | spin_unlock_irq(&phba->hbalock); |
| 3703 | } |
| 3704 | |
| 3705 | |
| 3706 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3707 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3708 | * @phba: Pointer to HBA context object. |
| 3709 | * @pring: Pointer to driver SLI ring object. |
| 3710 | * |
| 3711 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3712 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3713 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3714 | * the return of this function. The caller is not required to hold any locks. |
| 3715 | **/ |
| 3716 | void |
| 3717 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3718 | { |
| 3719 | struct lpfc_sli *psli = &phba->sli; |
| 3720 | struct lpfc_sli_ring *pring; |
| 3721 | uint32_t i; |
| 3722 | |
| 3723 | /* Look on all the FCP Rings for the iotag */ |
| 3724 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3725 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3726 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3727 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3728 | } |
| 3729 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3730 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3731 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3732 | } |
| 3733 | } |
| 3734 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3735 | /** |
| 3736 | * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings |
| 3737 | * @phba: Pointer to HBA context object. |
| 3738 | * |
| 3739 | * This function aborts all wqes in NVME rings. This function issues an |
| 3740 | * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in |
| 3741 | * the txcmplq is not guaranteed to complete before the return of this |
| 3742 | * function. The caller is not required to hold any locks. |
| 3743 | **/ |
| 3744 | void |
| 3745 | lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba) |
| 3746 | { |
| 3747 | struct lpfc_sli_ring *pring; |
| 3748 | uint32_t i; |
| 3749 | |
| 3750 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3751 | return; |
| 3752 | |
| 3753 | /* Abort all IO on each NVME ring. */ |
| 3754 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 3755 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 3756 | lpfc_sli_abort_wqe_ring(phba, pring); |
| 3757 | } |
| 3758 | } |
| 3759 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3760 | |
| 3761 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3762 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3763 | * @phba: Pointer to HBA context object. |
| 3764 | * |
| 3765 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3766 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3767 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3768 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3769 | * slot has been permanently disabled. |
| 3770 | **/ |
| 3771 | void |
| 3772 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3773 | { |
| 3774 | LIST_HEAD(txq); |
| 3775 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3776 | struct lpfc_sli *psli = &phba->sli; |
| 3777 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3778 | uint32_t i; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3779 | |
| 3780 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3781 | /* Indicate the I/O queues are flushed */ |
| 3782 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3783 | spin_unlock_irq(&phba->hbalock); |
| 3784 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3785 | /* Look on all the FCP Rings for the iotag */ |
| 3786 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3787 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3788 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3789 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3790 | spin_lock_irq(&pring->ring_lock); |
| 3791 | /* Retrieve everything on txq */ |
| 3792 | list_splice_init(&pring->txq, &txq); |
| 3793 | /* Retrieve everything on the txcmplq */ |
| 3794 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3795 | pring->txq_cnt = 0; |
| 3796 | pring->txcmplq_cnt = 0; |
| 3797 | spin_unlock_irq(&pring->ring_lock); |
| 3798 | |
| 3799 | /* Flush the txq */ |
| 3800 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 3801 | IOSTAT_LOCAL_REJECT, |
| 3802 | IOERR_SLI_DOWN); |
| 3803 | /* Flush the txcmpq */ |
| 3804 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3805 | IOSTAT_LOCAL_REJECT, |
| 3806 | IOERR_SLI_DOWN); |
| 3807 | } |
| 3808 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3809 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3810 | |
| 3811 | spin_lock_irq(&phba->hbalock); |
| 3812 | /* Retrieve everything on txq */ |
| 3813 | list_splice_init(&pring->txq, &txq); |
| 3814 | /* Retrieve everything on the txcmplq */ |
| 3815 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3816 | pring->txq_cnt = 0; |
| 3817 | pring->txcmplq_cnt = 0; |
| 3818 | spin_unlock_irq(&phba->hbalock); |
| 3819 | |
| 3820 | /* Flush the txq */ |
| 3821 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3822 | IOERR_SLI_DOWN); |
| 3823 | /* Flush the txcmpq */ |
| 3824 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3825 | IOERR_SLI_DOWN); |
| 3826 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3827 | } |
| 3828 | |
| 3829 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3830 | * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings |
| 3831 | * @phba: Pointer to HBA context object. |
| 3832 | * |
| 3833 | * This function flushes all wqes in the nvme rings and frees all resources |
| 3834 | * in the txcmplq. This function does not issue abort wqes for the IO |
| 3835 | * commands in txcmplq, they will just be returned with |
| 3836 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3837 | * slot has been permanently disabled. |
| 3838 | **/ |
| 3839 | void |
| 3840 | lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba) |
| 3841 | { |
| 3842 | LIST_HEAD(txcmplq); |
| 3843 | struct lpfc_sli_ring *pring; |
| 3844 | uint32_t i; |
| 3845 | |
| 3846 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3847 | return; |
| 3848 | |
| 3849 | /* Hint to other driver operations that a flush is in progress. */ |
| 3850 | spin_lock_irq(&phba->hbalock); |
| 3851 | phba->hba_flag |= HBA_NVME_IOQ_FLUSH; |
| 3852 | spin_unlock_irq(&phba->hbalock); |
| 3853 | |
| 3854 | /* Cycle through all NVME rings and complete each IO with |
| 3855 | * a local driver reason code. This is a flush so no |
| 3856 | * abort exchange to FW. |
| 3857 | */ |
| 3858 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 3859 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 3860 | |
| 3861 | /* Retrieve everything on the txcmplq */ |
| 3862 | spin_lock_irq(&pring->ring_lock); |
| 3863 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3864 | pring->txcmplq_cnt = 0; |
| 3865 | spin_unlock_irq(&pring->ring_lock); |
| 3866 | |
| 3867 | /* Flush the txcmpq &&&PAE */ |
| 3868 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3869 | IOSTAT_LOCAL_REJECT, |
| 3870 | IOERR_SLI_DOWN); |
| 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3875 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3876 | * @phba: Pointer to HBA context object. |
| 3877 | * @mask: Bit mask to be checked. |
| 3878 | * |
| 3879 | * This function reads the host status register and compares |
| 3880 | * with the provided bit mask to check if HBA completed |
| 3881 | * the restart. This function will wait in a loop for the |
| 3882 | * HBA to complete restart. If the HBA does not restart within |
| 3883 | * 15 iterations, the function will reset the HBA again. The |
| 3884 | * function returns 1 when HBA fail to restart otherwise returns |
| 3885 | * zero. |
| 3886 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3887 | static int |
| 3888 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3890 | uint32_t status; |
| 3891 | int i = 0; |
| 3892 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3893 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3894 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3895 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3896 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3898 | /* |
| 3899 | * Check status register every 100ms for 5 retries, then every |
| 3900 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3901 | * every 2.5 sec for 4. |
| 3902 | * Break our of the loop if errors occurred during init. |
| 3903 | */ |
| 3904 | while (((status & mask) != mask) && |
| 3905 | !(status & HS_FFERM) && |
| 3906 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3907 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3908 | if (i <= 5) |
| 3909 | msleep(10); |
| 3910 | else if (i <= 10) |
| 3911 | msleep(500); |
| 3912 | else |
| 3913 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3914 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3915 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3916 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3917 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3918 | lpfc_sli_brdrestart(phba); |
| 3919 | } |
| 3920 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3921 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3922 | retval = 1; |
| 3923 | break; |
| 3924 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3925 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3927 | /* Check to see if any errors occurred during init */ |
| 3928 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3929 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3930 | "2751 Adapter failed to restart, " |
| 3931 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3932 | status, |
| 3933 | readl(phba->MBslimaddr + 0xa8), |
| 3934 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3935 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3936 | retval = 1; |
| 3937 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3939 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | } |
| 3941 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3942 | /** |
| 3943 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3944 | * @phba: Pointer to HBA context object. |
| 3945 | * @mask: Bit mask to be checked. |
| 3946 | * |
| 3947 | * This function checks the host status register to check if HBA is |
| 3948 | * ready. This function will wait in a loop for the HBA to be ready |
| 3949 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3950 | * function again. The function returns 1 when HBA fail to be ready |
| 3951 | * otherwise returns zero. |
| 3952 | **/ |
| 3953 | static int |
| 3954 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3955 | { |
| 3956 | uint32_t status; |
| 3957 | int retval = 0; |
| 3958 | |
| 3959 | /* Read the HBA Host Status Register */ |
| 3960 | status = lpfc_sli4_post_status_check(phba); |
| 3961 | |
| 3962 | if (status) { |
| 3963 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3964 | lpfc_sli_brdrestart(phba); |
| 3965 | status = lpfc_sli4_post_status_check(phba); |
| 3966 | } |
| 3967 | |
| 3968 | /* Check to see if any errors occurred during init */ |
| 3969 | if (status) { |
| 3970 | phba->link_state = LPFC_HBA_ERROR; |
| 3971 | retval = 1; |
| 3972 | } else |
| 3973 | phba->sli4_hba.intr_enable = 0; |
| 3974 | |
| 3975 | return retval; |
| 3976 | } |
| 3977 | |
| 3978 | /** |
| 3979 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3980 | * @phba: Pointer to HBA context object. |
| 3981 | * @mask: Bit mask to be checked. |
| 3982 | * |
| 3983 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3984 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3985 | **/ |
| 3986 | int |
| 3987 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3988 | { |
| 3989 | return phba->lpfc_sli_brdready(phba, mask); |
| 3990 | } |
| 3991 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3992 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3995 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3996 | * @phba: Pointer to HBA context object. |
| 3997 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3998 | * This function is called before resetting an HBA. This function is called |
| 3999 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4000 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4002 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4003 | uint32_t __iomem *resp_buf; |
| 4004 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4005 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4006 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4007 | int i; |
| 4008 | uint8_t hdrtype; |
| 4009 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4010 | lockdep_assert_held(&phba->hbalock); |
| 4011 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4012 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4013 | if (hdrtype != 0x80 || |
| 4014 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4015 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4016 | return; |
| 4017 | |
| 4018 | /* |
| 4019 | * Tell the other part of the chip to suspend temporarily all |
| 4020 | * its DMA activity. |
| 4021 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4022 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4023 | |
| 4024 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4025 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4026 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4027 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4028 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4029 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4030 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4031 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4032 | return; |
| 4033 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4034 | /* Clear Chip error bit */ |
| 4035 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4036 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | mbox = 0; |
| 4040 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4041 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4042 | |
| 4043 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4044 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4045 | writel(mbox, mbox_buf); |
| 4046 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4047 | for (i = 0; i < 50; i++) { |
| 4048 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4049 | return; |
| 4050 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4051 | mdelay(1); |
| 4052 | else |
| 4053 | break; |
| 4054 | } |
| 4055 | resp_data = 0; |
| 4056 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4057 | return; |
| 4058 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4059 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4060 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4061 | goto restore_hc; |
| 4062 | else |
| 4063 | goto clear_errat; |
| 4064 | } |
| 4065 | |
| 4066 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4067 | resp_data = 0; |
| 4068 | for (i = 0; i < 500; i++) { |
| 4069 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4070 | return; |
| 4071 | if (resp_data != mbox) |
| 4072 | mdelay(1); |
| 4073 | else |
| 4074 | break; |
| 4075 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4076 | |
| 4077 | clear_errat: |
| 4078 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4079 | while (++i < 500) { |
| 4080 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4081 | return; |
| 4082 | if (!(ha_copy & HA_ERATT)) |
| 4083 | mdelay(1); |
| 4084 | else |
| 4085 | break; |
| 4086 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4087 | |
| 4088 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4089 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4090 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4094 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4095 | writel(hc_copy, phba->HCregaddr); |
| 4096 | readl(phba->HCregaddr); /* flush */ |
| 4097 | } |
| 4098 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4099 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4100 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4101 | * @phba: Pointer to HBA context object. |
| 4102 | * |
| 4103 | * This function issues a kill_board mailbox command and waits for |
| 4104 | * the error attention interrupt. This function is called for stopping |
| 4105 | * the firmware processing. The caller is not required to hold any |
| 4106 | * locks. This function calls lpfc_hba_down_post function to free |
| 4107 | * any pending commands after the kill. The function will return 1 when it |
| 4108 | * fails to kill the board else will return 0. |
| 4109 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4110 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4111 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4113 | struct lpfc_sli *psli; |
| 4114 | LPFC_MBOXQ_t *pmb; |
| 4115 | uint32_t status; |
| 4116 | uint32_t ha_copy; |
| 4117 | int retval; |
| 4118 | int i = 0; |
| 4119 | |
| 4120 | psli = &phba->sli; |
| 4121 | |
| 4122 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4123 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4124 | "0329 Kill HBA Data: x%x x%x\n", |
| 4125 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4126 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4127 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4128 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4129 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4130 | |
| 4131 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4132 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4133 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4134 | spin_unlock_irq(&phba->hbalock); |
| 4135 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4136 | return 1; |
| 4137 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4138 | status &= ~HC_ERINT_ENA; |
| 4139 | writel(status, phba->HCregaddr); |
| 4140 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4141 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4142 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4143 | |
| 4144 | lpfc_kill_board(phba, pmb); |
| 4145 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4146 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4147 | |
| 4148 | if (retval != MBX_SUCCESS) { |
| 4149 | if (retval != MBX_BUSY) |
| 4150 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4151 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4152 | "2752 KILL_BOARD command failed retval %d\n", |
| 4153 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4154 | spin_lock_irq(&phba->hbalock); |
| 4155 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4156 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4157 | return 1; |
| 4158 | } |
| 4159 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4160 | spin_lock_irq(&phba->hbalock); |
| 4161 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4162 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4163 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4164 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4165 | |
| 4166 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4167 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4168 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4169 | * board is now undefined. |
| 4170 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4171 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4172 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4173 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4174 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4175 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4176 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4180 | if (ha_copy & HA_ERATT) { |
| 4181 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4182 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4183 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4184 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4185 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4186 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4187 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4188 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4189 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4190 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4191 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4192 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4193 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4194 | } |
| 4195 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4196 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4197 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4198 | * @phba: Pointer to HBA context object. |
| 4199 | * |
| 4200 | * This function resets the HBA by writing HC_INITFF to the control |
| 4201 | * register. After the HBA resets, this function resets all the iocb ring |
| 4202 | * indices. This function disables PCI layer parity checking during |
| 4203 | * the reset. |
| 4204 | * This function returns 0 always. |
| 4205 | * The caller is not required to hold any locks. |
| 4206 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4207 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4208 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4209 | { |
| 4210 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4211 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4212 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4215 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4217 | /* Reset HBA */ |
| 4218 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4219 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4220 | (phba->pport) ? phba->pport->port_state : 0, |
| 4221 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4222 | |
| 4223 | /* perform board reset */ |
| 4224 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4225 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4226 | if (phba->pport) { |
| 4227 | phba->pport->fc_myDID = 0; |
| 4228 | phba->pport->fc_prevDID = 0; |
| 4229 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4230 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4231 | /* Turn off parity checking and serr during the physical reset */ |
| 4232 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4233 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4234 | (cfg_value & |
| 4235 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4236 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4237 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4238 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4239 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4240 | writel(HC_INITFF, phba->HCregaddr); |
| 4241 | mdelay(1); |
| 4242 | readl(phba->HCregaddr); /* flush */ |
| 4243 | writel(0, phba->HCregaddr); |
| 4244 | readl(phba->HCregaddr); /* flush */ |
| 4245 | |
| 4246 | /* Restore PCI cmd register */ |
| 4247 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4248 | |
| 4249 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4250 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4251 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4253 | pring->sli.sli3.rspidx = 0; |
| 4254 | pring->sli.sli3.next_cmdidx = 0; |
| 4255 | pring->sli.sli3.local_getidx = 0; |
| 4256 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4257 | pring->missbufcnt = 0; |
| 4258 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4260 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4261 | return 0; |
| 4262 | } |
| 4263 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4264 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4265 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4266 | * @phba: Pointer to HBA context object. |
| 4267 | * |
| 4268 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4269 | * checking during resets the device. The caller is not required to hold |
| 4270 | * any locks. |
| 4271 | * |
| 4272 | * This function returns 0 always. |
| 4273 | **/ |
| 4274 | int |
| 4275 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4276 | { |
| 4277 | struct lpfc_sli *psli = &phba->sli; |
| 4278 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4279 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4280 | |
| 4281 | /* Reset HBA */ |
| 4282 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4283 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4284 | phba->pport->port_state, psli->sli_flag, |
| 4285 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4286 | |
| 4287 | /* perform board reset */ |
| 4288 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4289 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4290 | phba->pport->fc_myDID = 0; |
| 4291 | phba->pport->fc_prevDID = 0; |
| 4292 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4293 | spin_lock_irq(&phba->hbalock); |
| 4294 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4295 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4296 | spin_unlock_irq(&phba->hbalock); |
| 4297 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4298 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4299 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4300 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4301 | return rc; |
| 4302 | } |
| 4303 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4304 | /* Now physically reset the device */ |
| 4305 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4306 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4307 | |
| 4308 | /* Turn off parity checking and serr during the physical reset */ |
| 4309 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4310 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4311 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4312 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4313 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4314 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4315 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4316 | /* Restore PCI cmd register */ |
| 4317 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4318 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4319 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | /** |
| 4323 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4324 | * @phba: Pointer to HBA context object. |
| 4325 | * |
| 4326 | * This function is called in the SLI initialization code path to |
| 4327 | * restart the HBA. The caller is not required to hold any lock. |
| 4328 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4329 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4330 | * function to free any pending commands. The function enables |
| 4331 | * POST only during the first initialization. The function returns zero. |
| 4332 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4333 | * command before the return of this function. |
| 4334 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4335 | static int |
| 4336 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4337 | { |
| 4338 | MAILBOX_t *mb; |
| 4339 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4340 | volatile uint32_t word0; |
| 4341 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4342 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4343 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4344 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4345 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4346 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4347 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4348 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4349 | psli = &phba->sli; |
| 4350 | |
| 4351 | /* Restart HBA */ |
| 4352 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4353 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4354 | (phba->pport) ? phba->pport->port_state : 0, |
| 4355 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4356 | |
| 4357 | word0 = 0; |
| 4358 | mb = (MAILBOX_t *) &word0; |
| 4359 | mb->mbxCommand = MBX_RESTART; |
| 4360 | mb->mbxHc = 1; |
| 4361 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4362 | lpfc_reset_barrier(phba); |
| 4363 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4364 | to_slim = phba->MBslimaddr; |
| 4365 | writel(*(uint32_t *) mb, to_slim); |
| 4366 | readl(to_slim); /* flush */ |
| 4367 | |
| 4368 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4369 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4370 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4371 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4372 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4373 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4374 | writel(*(uint32_t *) mb, to_slim); |
| 4375 | readl(to_slim); /* flush */ |
| 4376 | |
| 4377 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4378 | if (phba->pport) |
| 4379 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4380 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4381 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4382 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4383 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4384 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4385 | psli->stats_start = get_seconds(); |
| 4386 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4387 | /* Give the INITFF and Post time to settle. */ |
| 4388 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4390 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4391 | if (hba_aer_enabled) |
| 4392 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4393 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4394 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4395 | |
| 4396 | return 0; |
| 4397 | } |
| 4398 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4399 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4400 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4401 | * @phba: Pointer to HBA context object. |
| 4402 | * |
| 4403 | * This function is called in the SLI initialization code path to restart |
| 4404 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4405 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4406 | * free any pending commands. |
| 4407 | **/ |
| 4408 | static int |
| 4409 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4410 | { |
| 4411 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4412 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4413 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4414 | |
| 4415 | /* Restart HBA */ |
| 4416 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4417 | "0296 Restart HBA Data: x%x x%x\n", |
| 4418 | phba->pport->port_state, psli->sli_flag); |
| 4419 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4420 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4421 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4422 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4423 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4424 | |
| 4425 | spin_lock_irq(&phba->hbalock); |
| 4426 | phba->pport->stopped = 0; |
| 4427 | phba->link_state = LPFC_INIT_START; |
| 4428 | phba->hba_flag = 0; |
| 4429 | spin_unlock_irq(&phba->hbalock); |
| 4430 | |
| 4431 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4432 | psli->stats_start = get_seconds(); |
| 4433 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4434 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4435 | if (hba_aer_enabled) |
| 4436 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4437 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4438 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4439 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4440 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4441 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4442 | } |
| 4443 | |
| 4444 | /** |
| 4445 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4446 | * @phba: Pointer to HBA context object. |
| 4447 | * |
| 4448 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4449 | * API jump table function pointer from the lpfc_hba struct. |
| 4450 | **/ |
| 4451 | int |
| 4452 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4453 | { |
| 4454 | return phba->lpfc_sli_brdrestart(phba); |
| 4455 | } |
| 4456 | |
| 4457 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4458 | * 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] | 4459 | * @phba: Pointer to HBA context object. |
| 4460 | * |
| 4461 | * This function is called after a HBA restart to wait for successful |
| 4462 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4463 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4464 | * iteration, the function will restart the HBA again. The function returns |
| 4465 | * zero if HBA successfully restarted else returns negative error code. |
| 4466 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4467 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4468 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4469 | { |
| 4470 | uint32_t status, i = 0; |
| 4471 | |
| 4472 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4473 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4474 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | |
| 4476 | /* Check status register to see what current state is */ |
| 4477 | i = 0; |
| 4478 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4479 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4480 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4481 | * retries, then every 1 sec for 50 retires for a total of |
| 4482 | * ~60 seconds before reset the board again and check every |
| 4483 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4484 | * board ready is required by the Falcon FIPS zeroization |
| 4485 | * complete, and any reset the board in between shall cause |
| 4486 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4487 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4488 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4489 | /* Adapter failed to init, timeout, status reg |
| 4490 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4491 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4492 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4493 | "timeout, status reg x%x, " |
| 4494 | "FW Data: A8 x%x AC x%x\n", status, |
| 4495 | readl(phba->MBslimaddr + 0xa8), |
| 4496 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4497 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4498 | return -ETIMEDOUT; |
| 4499 | } |
| 4500 | |
| 4501 | /* Check to see if any errors occurred during init */ |
| 4502 | if (status & HS_FFERM) { |
| 4503 | /* ERROR: During chipset initialization */ |
| 4504 | /* Adapter failed to init, chipset, status reg |
| 4505 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4507 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4508 | "chipset, status reg x%x, " |
| 4509 | "FW Data: A8 x%x AC x%x\n", status, |
| 4510 | readl(phba->MBslimaddr + 0xa8), |
| 4511 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4512 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4513 | return -EIO; |
| 4514 | } |
| 4515 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4516 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4517 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4518 | else if (i <= 100) |
| 4519 | msleep(100); |
| 4520 | else |
| 4521 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4523 | if (i == 150) { |
| 4524 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4525 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4526 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4527 | } |
| 4528 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4529 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4530 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | /* Check to see if any errors occurred during init */ |
| 4534 | if (status & HS_FFERM) { |
| 4535 | /* ERROR: During chipset initialization */ |
| 4536 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4538 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4539 | "status reg x%x, " |
| 4540 | "FW Data: A8 x%x AC x%x\n", status, |
| 4541 | readl(phba->MBslimaddr + 0xa8), |
| 4542 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4543 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4544 | return -EIO; |
| 4545 | } |
| 4546 | |
| 4547 | /* Clear all interrupt enable conditions */ |
| 4548 | writel(0, phba->HCregaddr); |
| 4549 | readl(phba->HCregaddr); /* flush */ |
| 4550 | |
| 4551 | /* setup host attn register */ |
| 4552 | writel(0xffffffff, phba->HAregaddr); |
| 4553 | readl(phba->HAregaddr); /* flush */ |
| 4554 | return 0; |
| 4555 | } |
| 4556 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4557 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4558 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4559 | * |
| 4560 | * This function calculates and returns the number of HBQs required to be |
| 4561 | * configured. |
| 4562 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4563 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4564 | lpfc_sli_hbq_count(void) |
| 4565 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4566 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4567 | } |
| 4568 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4569 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4570 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4571 | * |
| 4572 | * This function adds the number of hbq entries in every HBQ to get |
| 4573 | * the total number of hbq entries required for the HBA and returns |
| 4574 | * the total count. |
| 4575 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4576 | static int |
| 4577 | lpfc_sli_hbq_entry_count(void) |
| 4578 | { |
| 4579 | int hbq_count = lpfc_sli_hbq_count(); |
| 4580 | int count = 0; |
| 4581 | int i; |
| 4582 | |
| 4583 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4584 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4585 | return count; |
| 4586 | } |
| 4587 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4588 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4589 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4590 | * |
| 4591 | * This function calculates amount of memory required for all hbq entries |
| 4592 | * to be configured and returns the total memory required. |
| 4593 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4594 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4595 | lpfc_sli_hbq_size(void) |
| 4596 | { |
| 4597 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4598 | } |
| 4599 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4600 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4601 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4602 | * @phba: Pointer to HBA context object. |
| 4603 | * |
| 4604 | * This function is called during the SLI initialization to configure |
| 4605 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4606 | * required to hold any locks. This function will return zero if successful |
| 4607 | * else it will return negative error code. |
| 4608 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4609 | static int |
| 4610 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4611 | { |
| 4612 | int hbq_count = lpfc_sli_hbq_count(); |
| 4613 | LPFC_MBOXQ_t *pmb; |
| 4614 | MAILBOX_t *pmbox; |
| 4615 | uint32_t hbqno; |
| 4616 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4617 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4618 | /* Get a Mailbox buffer to setup mailbox |
| 4619 | * commands for HBA initialization |
| 4620 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4621 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4622 | |
| 4623 | if (!pmb) |
| 4624 | return -ENOMEM; |
| 4625 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4626 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4627 | |
| 4628 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4629 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4630 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4631 | |
| 4632 | hbq_entry_index = 0; |
| 4633 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4634 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4635 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4636 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4637 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4638 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4639 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4640 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4641 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4642 | |
| 4643 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4644 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4645 | mbxStatus <status>, ring <num> */ |
| 4646 | |
| 4647 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4648 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4649 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4650 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4651 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4652 | pmbox->mbxStatus, hbqno); |
| 4653 | |
| 4654 | phba->link_state = LPFC_HBA_ERROR; |
| 4655 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4656 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4657 | } |
| 4658 | } |
| 4659 | phba->hbq_count = hbq_count; |
| 4660 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4661 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4662 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4663 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4664 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4665 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4666 | return 0; |
| 4667 | } |
| 4668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4669 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4670 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4671 | * @phba: Pointer to HBA context object. |
| 4672 | * |
| 4673 | * This function is called during the SLI initialization to configure |
| 4674 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4675 | * required to hold any locks. This function will return zero if successful |
| 4676 | * else it will return negative error code. |
| 4677 | **/ |
| 4678 | static int |
| 4679 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4680 | { |
| 4681 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4682 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4683 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4684 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4685 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4686 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4687 | return 0; |
| 4688 | } |
| 4689 | |
| 4690 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4691 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4692 | * @phba: Pointer to HBA context object. |
| 4693 | * @sli_mode: sli mode - 2/3 |
| 4694 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4695 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4696 | * to issue config_port mailbox command. This function restarts the |
| 4697 | * HBA firmware and issues a config_port mailbox command to configure |
| 4698 | * the SLI interface in the sli mode specified by sli_mode |
| 4699 | * variable. The caller is not required to hold any locks. |
| 4700 | * The function returns 0 if successful, else returns negative error |
| 4701 | * code. |
| 4702 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4703 | int |
| 4704 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4705 | { |
| 4706 | LPFC_MBOXQ_t *pmb; |
| 4707 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4708 | |
| 4709 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4710 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4711 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4712 | return -ENOMEM; |
| 4713 | } |
| 4714 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4715 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4716 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4717 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4718 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4719 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4720 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4721 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | rc = lpfc_sli_chipset_init(phba); |
| 4723 | if (rc) |
| 4724 | break; |
| 4725 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4726 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4727 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4728 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4729 | resetcount++; |
| 4730 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4731 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4732 | * value of 0 means the call was successful. Any other |
| 4733 | * nonzero value is a failure, but if ERESTART is returned, |
| 4734 | * the driver may reset the HBA and try again. |
| 4735 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | rc = lpfc_config_port_prep(phba); |
| 4737 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4738 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4739 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4740 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4742 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4743 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4744 | lpfc_config_port(phba, pmb); |
| 4745 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4746 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4747 | LPFC_SLI3_HBQ_ENABLED | |
| 4748 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4749 | LPFC_SLI3_BG_ENABLED | |
| 4750 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4751 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4753 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4754 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4755 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4756 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4757 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4758 | spin_unlock_irq(&phba->hbalock); |
| 4759 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4760 | } else { |
| 4761 | /* Allow asynchronous mailbox command to go through */ |
| 4762 | spin_lock_irq(&phba->hbalock); |
| 4763 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4764 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4765 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4766 | |
| 4767 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4768 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4769 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4770 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4771 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4772 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4773 | if (!done) { |
| 4774 | rc = -EINVAL; |
| 4775 | goto do_prep_failed; |
| 4776 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4777 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4778 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4779 | rc = -ENXIO; |
| 4780 | goto do_prep_failed; |
| 4781 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4782 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4783 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4784 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4785 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4786 | phba->max_vpi : phba->max_vports; |
| 4787 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4788 | } else |
| 4789 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4790 | phba->fips_level = 0; |
| 4791 | phba->fips_spec_rev = 0; |
| 4792 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4793 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4794 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4795 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4796 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4797 | "2850 Security Crypto Active. FIPS x%d " |
| 4798 | "(Spec Rev: x%d)", |
| 4799 | phba->fips_level, phba->fips_spec_rev); |
| 4800 | } |
| 4801 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4802 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4803 | "2856 Config Port Security Crypto " |
| 4804 | "Error: x%x ", |
| 4805 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4806 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4807 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4808 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4809 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4810 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4811 | |
| 4812 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4813 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4814 | |
| 4815 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4816 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4817 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4818 | else |
| 4819 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4820 | "0443 Adapter did not grant " |
| 4821 | "BlockGuard\n"); |
| 4822 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4823 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4824 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4825 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4826 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4827 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4828 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4829 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4830 | return rc; |
| 4831 | } |
| 4832 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4833 | |
| 4834 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4835 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4836 | * @phba: Pointer to HBA context object. |
| 4837 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4838 | * This function is the main SLI initialization function. This function |
| 4839 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4840 | * error attention handler code. Caller is not required to hold any |
| 4841 | * locks. This function issues config_port mailbox command to configure |
| 4842 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4843 | * calls the config_port_post function to issue init_link mailbox |
| 4844 | * command and to start the discovery. The function will return zero |
| 4845 | * if successful, else it will return negative error code. |
| 4846 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4847 | int |
| 4848 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4849 | { |
| 4850 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4851 | int mode = 3, i; |
| 4852 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4853 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4854 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4855 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4856 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4857 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4858 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4859 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4860 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4861 | break; |
| 4862 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4863 | mode = 2; |
| 4864 | break; |
| 4865 | case 0: |
| 4866 | case 3: |
| 4867 | break; |
| 4868 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4869 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4870 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 4871 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4872 | |
| 4873 | break; |
| 4874 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 4875 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4876 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4877 | rc = lpfc_sli_config_port(phba, mode); |
| 4878 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4879 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4880 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4881 | "1820 Unable to select SLI-3. " |
| 4882 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4883 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4884 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 4885 | else if (rc && mode == 2) |
| 4886 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4887 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | goto lpfc_sli_hba_setup_error; |
| 4889 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4890 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4891 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4892 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4893 | if (!rc) { |
| 4894 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4895 | "2709 This device supports " |
| 4896 | "Advanced Error Reporting (AER)\n"); |
| 4897 | spin_lock_irq(&phba->hbalock); |
| 4898 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4899 | spin_unlock_irq(&phba->hbalock); |
| 4900 | } else { |
| 4901 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4902 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 4903 | "Advanced Error Reporting (AER): %d\n", |
| 4904 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4905 | phba->cfg_aer_support = 0; |
| 4906 | } |
| 4907 | } |
| 4908 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4909 | if (phba->sli_rev == 3) { |
| 4910 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4911 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4912 | } else { |
| 4913 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4914 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4915 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4916 | } |
| 4917 | |
| 4918 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4919 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4920 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4921 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4922 | |
| 4923 | if (rc) |
| 4924 | goto lpfc_sli_hba_setup_error; |
| 4925 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4926 | /* Initialize VPIs. */ |
| 4927 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4928 | /* |
| 4929 | * The VPI bitmask and physical ID array are allocated |
| 4930 | * and initialized once only - at driver load. A port |
| 4931 | * reset doesn't need to reinitialize this memory. |
| 4932 | */ |
| 4933 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4934 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4935 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4936 | GFP_KERNEL); |
| 4937 | if (!phba->vpi_bmask) { |
| 4938 | rc = -ENOMEM; |
| 4939 | goto lpfc_sli_hba_setup_error; |
| 4940 | } |
| 4941 | |
| 4942 | phba->vpi_ids = kzalloc( |
| 4943 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4944 | GFP_KERNEL); |
| 4945 | if (!phba->vpi_ids) { |
| 4946 | kfree(phba->vpi_bmask); |
| 4947 | rc = -ENOMEM; |
| 4948 | goto lpfc_sli_hba_setup_error; |
| 4949 | } |
| 4950 | for (i = 0; i < phba->max_vpi; i++) |
| 4951 | phba->vpi_ids[i] = i; |
| 4952 | } |
| 4953 | } |
| 4954 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4955 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4956 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4957 | rc = lpfc_sli_hbq_setup(phba); |
| 4958 | if (rc) |
| 4959 | goto lpfc_sli_hba_setup_error; |
| 4960 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4961 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4962 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4963 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4964 | |
| 4965 | rc = lpfc_config_port_post(phba); |
| 4966 | if (rc) |
| 4967 | goto lpfc_sli_hba_setup_error; |
| 4968 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4969 | return rc; |
| 4970 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4971 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4972 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4974 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4975 | return rc; |
| 4976 | } |
| 4977 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4978 | /** |
| 4979 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4980 | * @phba: Pointer to HBA context object. |
| 4981 | * @mboxq: mailbox pointer. |
| 4982 | * This function issue a dump mailbox command to read config region |
| 4983 | * 23 and parse the records in the region and populate driver |
| 4984 | * data structure. |
| 4985 | **/ |
| 4986 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4987 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4988 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4989 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4990 | struct lpfc_dmabuf *mp; |
| 4991 | struct lpfc_mqe *mqe; |
| 4992 | uint32_t data_length; |
| 4993 | int rc; |
| 4994 | |
| 4995 | /* Program the default value of vlan_id and fc_map */ |
| 4996 | phba->valid_vlan = 0; |
| 4997 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4998 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4999 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5000 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5001 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5002 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5003 | return -ENOMEM; |
| 5004 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5005 | mqe = &mboxq->u.mqe; |
| 5006 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5007 | rc = -ENOMEM; |
| 5008 | goto out_free_mboxq; |
| 5009 | } |
| 5010 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5011 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 5012 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5013 | |
| 5014 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5015 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5016 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5017 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5018 | "CQ: x%x x%x x%x x%x\n", |
| 5019 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5020 | bf_get(lpfc_mqe_command, mqe), |
| 5021 | bf_get(lpfc_mqe_status, mqe), |
| 5022 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5023 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5024 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5025 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5026 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5027 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5028 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5029 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5030 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5031 | mboxq->mcqe.word0, |
| 5032 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5033 | mboxq->mcqe.trailer); |
| 5034 | |
| 5035 | if (rc) { |
| 5036 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5037 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5038 | rc = -EIO; |
| 5039 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5040 | } |
| 5041 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5042 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5043 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5044 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5045 | rc = -EIO; |
| 5046 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5047 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5048 | |
| 5049 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5050 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5051 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5052 | rc = 0; |
| 5053 | |
| 5054 | out_free_mboxq: |
| 5055 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5056 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | /** |
| 5060 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5061 | * @phba: pointer to lpfc hba data structure. |
| 5062 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5063 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5064 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5065 | * On output, the number of data bytes in @vpd. |
| 5066 | * |
| 5067 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5068 | * addition, this routine gets the port vpd data. |
| 5069 | * |
| 5070 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5071 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5072 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5073 | **/ |
| 5074 | static int |
| 5075 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5076 | uint8_t *vpd, uint32_t *vpd_size) |
| 5077 | { |
| 5078 | int rc = 0; |
| 5079 | uint32_t dma_size; |
| 5080 | struct lpfc_dmabuf *dmabuf; |
| 5081 | struct lpfc_mqe *mqe; |
| 5082 | |
| 5083 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5084 | if (!dmabuf) |
| 5085 | return -ENOMEM; |
| 5086 | |
| 5087 | /* |
| 5088 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5089 | * mailbox command. |
| 5090 | */ |
| 5091 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 5092 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 5093 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5094 | if (!dmabuf->virt) { |
| 5095 | kfree(dmabuf); |
| 5096 | return -ENOMEM; |
| 5097 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5098 | |
| 5099 | /* |
| 5100 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5101 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5102 | * in SLI3. This code corrects the conflicts. |
| 5103 | */ |
| 5104 | lpfc_read_rev(phba, mboxq); |
| 5105 | mqe = &mboxq->u.mqe; |
| 5106 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5107 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5108 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5109 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5110 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5111 | |
| 5112 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5113 | if (rc) { |
| 5114 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5115 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5116 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5117 | return -EIO; |
| 5118 | } |
| 5119 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5120 | /* |
| 5121 | * The available vpd length cannot be bigger than the |
| 5122 | * DMA buffer passed to the port. Catch the less than |
| 5123 | * case and update the caller's size. |
| 5124 | */ |
| 5125 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5126 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5127 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5128 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5129 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5130 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5131 | dmabuf->virt, dmabuf->phys); |
| 5132 | kfree(dmabuf); |
| 5133 | return 0; |
| 5134 | } |
| 5135 | |
| 5136 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5137 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5138 | * @phba: pointer to lpfc hba data structure. |
| 5139 | * |
| 5140 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5141 | * is attached to. |
| 5142 | * |
| 5143 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5144 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5145 | * otherwise - failed to retrieve physical port name |
| 5146 | **/ |
| 5147 | static int |
| 5148 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5149 | { |
| 5150 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5151 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5152 | struct lpfc_controller_attribute *cntl_attr; |
| 5153 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5154 | void *virtaddr = NULL; |
| 5155 | uint32_t alloclen, reqlen; |
| 5156 | uint32_t shdr_status, shdr_add_status; |
| 5157 | union lpfc_sli4_cfg_shdr *shdr; |
| 5158 | char cport_name = 0; |
| 5159 | int rc; |
| 5160 | |
| 5161 | /* We assume nothing at this point */ |
| 5162 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5163 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5164 | |
| 5165 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5166 | if (!mboxq) |
| 5167 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5168 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5169 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5170 | lpfc_sli4_read_config(phba); |
| 5171 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5172 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5173 | |
| 5174 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5175 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5176 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5177 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5178 | LPFC_SLI4_MBX_NEMBED); |
| 5179 | if (alloclen < reqlen) { |
| 5180 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5181 | "3084 Allocated DMA memory size (%d) is " |
| 5182 | "less than the requested DMA memory size " |
| 5183 | "(%d)\n", alloclen, reqlen); |
| 5184 | rc = -ENOMEM; |
| 5185 | goto out_free_mboxq; |
| 5186 | } |
| 5187 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5188 | virtaddr = mboxq->sge_array->addr[0]; |
| 5189 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5190 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5191 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5192 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5193 | if (shdr_status || shdr_add_status || rc) { |
| 5194 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5195 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5196 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5197 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5198 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5199 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5200 | rc, shdr_status, shdr_add_status); |
| 5201 | rc = -ENXIO; |
| 5202 | goto out_free_mboxq; |
| 5203 | } |
| 5204 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5205 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5206 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5207 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5208 | phba->sli4_hba.lnk_info.lnk_no = |
| 5209 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5210 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5211 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5212 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5213 | phba->sli4_hba.lnk_info.lnk_no); |
| 5214 | |
| 5215 | retrieve_ppname: |
| 5216 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5217 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5218 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5219 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5220 | LPFC_SLI4_MBX_EMBED); |
| 5221 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5222 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5223 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5224 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5225 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5226 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5227 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5228 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5229 | if (shdr_status || shdr_add_status || rc) { |
| 5230 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5231 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5232 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5233 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5234 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5235 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5236 | rc, shdr_status, shdr_add_status); |
| 5237 | rc = -ENXIO; |
| 5238 | goto out_free_mboxq; |
| 5239 | } |
| 5240 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5241 | case LPFC_LINK_NUMBER_0: |
| 5242 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5243 | &get_port_name->u.response); |
| 5244 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5245 | break; |
| 5246 | case LPFC_LINK_NUMBER_1: |
| 5247 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5248 | &get_port_name->u.response); |
| 5249 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5250 | break; |
| 5251 | case LPFC_LINK_NUMBER_2: |
| 5252 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5253 | &get_port_name->u.response); |
| 5254 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5255 | break; |
| 5256 | case LPFC_LINK_NUMBER_3: |
| 5257 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5258 | &get_port_name->u.response); |
| 5259 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5260 | break; |
| 5261 | default: |
| 5262 | break; |
| 5263 | } |
| 5264 | |
| 5265 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5266 | phba->Port[0] = cport_name; |
| 5267 | phba->Port[1] = '\0'; |
| 5268 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5269 | "3091 SLI get port name: %s\n", phba->Port); |
| 5270 | } |
| 5271 | |
| 5272 | out_free_mboxq: |
| 5273 | if (rc != MBX_TIMEOUT) { |
| 5274 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5275 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5276 | else |
| 5277 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5278 | } |
| 5279 | return rc; |
| 5280 | } |
| 5281 | |
| 5282 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5283 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5284 | * @phba: pointer to lpfc hba data structure. |
| 5285 | * |
| 5286 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5287 | * event queues |
| 5288 | **/ |
| 5289 | static void |
| 5290 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5291 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5292 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5293 | |
| 5294 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 5295 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5296 | if (phba->sli4_hba.nvmels_cq) |
| 5297 | lpfc_sli4_cq_release(phba->sli4_hba.nvmels_cq, |
| 5298 | LPFC_QUEUE_REARM); |
| 5299 | |
| 5300 | if (phba->sli4_hba.fcp_cq) |
| 5301 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
| 5302 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[qidx], |
| 5303 | LPFC_QUEUE_REARM); |
| 5304 | |
| 5305 | if (phba->sli4_hba.nvme_cq) |
| 5306 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
| 5307 | lpfc_sli4_cq_release(phba->sli4_hba.nvme_cq[qidx], |
| 5308 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5309 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5310 | if (phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5311 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
| 5312 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5313 | if (phba->sli4_hba.hba_eq) |
| 5314 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) |
| 5315 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[qidx], |
| 5316 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5317 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5318 | if (phba->nvmet_support) { |
| 5319 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
| 5320 | lpfc_sli4_cq_release( |
| 5321 | phba->sli4_hba.nvmet_cqset[qidx], |
| 5322 | LPFC_QUEUE_REARM); |
| 5323 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5324 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5325 | |
| 5326 | if (phba->cfg_fof) |
| 5327 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5331 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5332 | * @phba: Pointer to HBA context object. |
| 5333 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5334 | * @extnt_count: buffer to hold port available extent count. |
| 5335 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5336 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5337 | * This function calls the port and retrievs the number of available |
| 5338 | * extents and their size for a particular extent type. |
| 5339 | * |
| 5340 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5341 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5342 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5343 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5344 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5345 | { |
| 5346 | int rc = 0; |
| 5347 | uint32_t length; |
| 5348 | uint32_t mbox_tmo; |
| 5349 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5350 | LPFC_MBOXQ_t *mbox; |
| 5351 | |
| 5352 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5353 | if (!mbox) |
| 5354 | return -ENOMEM; |
| 5355 | |
| 5356 | /* Find out how many extents are available for this resource type */ |
| 5357 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5358 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5359 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5360 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5361 | length, LPFC_SLI4_MBX_EMBED); |
| 5362 | |
| 5363 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5364 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5365 | LPFC_SLI4_MBX_EMBED); |
| 5366 | if (unlikely(rc)) { |
| 5367 | rc = -EIO; |
| 5368 | goto err_exit; |
| 5369 | } |
| 5370 | |
| 5371 | if (!phba->sli4_hba.intr_enable) |
| 5372 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5373 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5374 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5375 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5376 | } |
| 5377 | if (unlikely(rc)) { |
| 5378 | rc = -EIO; |
| 5379 | goto err_exit; |
| 5380 | } |
| 5381 | |
| 5382 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5383 | if (bf_get(lpfc_mbox_hdr_status, |
| 5384 | &rsrc_info->header.cfg_shdr.response)) { |
| 5385 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5386 | "2930 Failed to get resource extents " |
| 5387 | "Status 0x%x Add'l Status 0x%x\n", |
| 5388 | bf_get(lpfc_mbox_hdr_status, |
| 5389 | &rsrc_info->header.cfg_shdr.response), |
| 5390 | bf_get(lpfc_mbox_hdr_add_status, |
| 5391 | &rsrc_info->header.cfg_shdr.response)); |
| 5392 | rc = -EIO; |
| 5393 | goto err_exit; |
| 5394 | } |
| 5395 | |
| 5396 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5397 | &rsrc_info->u.rsp); |
| 5398 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5399 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5400 | |
| 5401 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5402 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5403 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5404 | |
| 5405 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5406 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5407 | return rc; |
| 5408 | } |
| 5409 | |
| 5410 | /** |
| 5411 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5412 | * @phba: Pointer to HBA context object. |
| 5413 | * @type: The extent type to check. |
| 5414 | * |
| 5415 | * This function reads the current available extents from the port and checks |
| 5416 | * if the extent count or extent size has changed since the last access. |
| 5417 | * Callers use this routine post port reset to understand if there is a |
| 5418 | * extent reprovisioning requirement. |
| 5419 | * |
| 5420 | * Returns: |
| 5421 | * -Error: error indicates problem. |
| 5422 | * 1: Extent count or size has changed. |
| 5423 | * 0: No changes. |
| 5424 | **/ |
| 5425 | static int |
| 5426 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5427 | { |
| 5428 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5429 | uint16_t size_diff, rsrc_ext_size; |
| 5430 | int rc = 0; |
| 5431 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5432 | struct list_head *rsrc_blk_list = NULL; |
| 5433 | |
| 5434 | size_diff = 0; |
| 5435 | curr_ext_cnt = 0; |
| 5436 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5437 | &rsrc_ext_cnt, |
| 5438 | &rsrc_ext_size); |
| 5439 | if (unlikely(rc)) |
| 5440 | return -EIO; |
| 5441 | |
| 5442 | switch (type) { |
| 5443 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5444 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5445 | break; |
| 5446 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5447 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5448 | break; |
| 5449 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5450 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5451 | break; |
| 5452 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5453 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5454 | break; |
| 5455 | default: |
| 5456 | break; |
| 5457 | } |
| 5458 | |
| 5459 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5460 | curr_ext_cnt++; |
| 5461 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5462 | size_diff++; |
| 5463 | } |
| 5464 | |
| 5465 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5466 | rc = 1; |
| 5467 | |
| 5468 | return rc; |
| 5469 | } |
| 5470 | |
| 5471 | /** |
| 5472 | * lpfc_sli4_cfg_post_extnts - |
| 5473 | * @phba: Pointer to HBA context object. |
| 5474 | * @extnt_cnt - number of available extents. |
| 5475 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5476 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5477 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5478 | * |
| 5479 | * This function executes the extents allocation request. It also |
| 5480 | * takes care of the amount of memory needed to allocate or get the |
| 5481 | * allocated extents. It is the caller's responsibility to evaluate |
| 5482 | * the response. |
| 5483 | * |
| 5484 | * Returns: |
| 5485 | * -Error: Error value describes the condition found. |
| 5486 | * 0: if successful |
| 5487 | **/ |
| 5488 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5489 | 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] | 5490 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5491 | { |
| 5492 | int rc = 0; |
| 5493 | uint32_t req_len; |
| 5494 | uint32_t emb_len; |
| 5495 | uint32_t alloc_len, mbox_tmo; |
| 5496 | |
| 5497 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5498 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5499 | |
| 5500 | /* |
| 5501 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5502 | * accounts for extents-specific word. |
| 5503 | */ |
| 5504 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5505 | sizeof(uint32_t); |
| 5506 | |
| 5507 | /* |
| 5508 | * Presume the allocation and response will fit into an embedded |
| 5509 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5510 | */ |
| 5511 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5512 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5513 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5514 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5515 | sizeof(uint32_t); |
| 5516 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5517 | } |
| 5518 | |
| 5519 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5520 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5521 | req_len, *emb); |
| 5522 | if (alloc_len < req_len) { |
| 5523 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5524 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5525 | "less than the requested DMA memory " |
| 5526 | "size (x%x)\n", alloc_len, req_len); |
| 5527 | return -ENOMEM; |
| 5528 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5529 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5530 | if (unlikely(rc)) |
| 5531 | return -EIO; |
| 5532 | |
| 5533 | if (!phba->sli4_hba.intr_enable) |
| 5534 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5535 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5536 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5537 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5538 | } |
| 5539 | |
| 5540 | if (unlikely(rc)) |
| 5541 | rc = -EIO; |
| 5542 | return rc; |
| 5543 | } |
| 5544 | |
| 5545 | /** |
| 5546 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5547 | * @phba: Pointer to HBA context object. |
| 5548 | * @type: The resource extent type to allocate. |
| 5549 | * |
| 5550 | * This function allocates the number of elements for the specified |
| 5551 | * resource type. |
| 5552 | **/ |
| 5553 | static int |
| 5554 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5555 | { |
| 5556 | bool emb = false; |
| 5557 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5558 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5559 | uint16_t *ids; |
| 5560 | int i, rc; |
| 5561 | unsigned long longs; |
| 5562 | unsigned long *bmask; |
| 5563 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5564 | LPFC_MBOXQ_t *mbox; |
| 5565 | uint32_t length; |
| 5566 | struct lpfc_id_range *id_array = NULL; |
| 5567 | void *virtaddr = NULL; |
| 5568 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5569 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5570 | struct list_head *ext_blk_list; |
| 5571 | |
| 5572 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5573 | &rsrc_cnt, |
| 5574 | &rsrc_size); |
| 5575 | if (unlikely(rc)) |
| 5576 | return -EIO; |
| 5577 | |
| 5578 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5579 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5580 | "3009 No available Resource Extents " |
| 5581 | "for resource type 0x%x: Count: 0x%x, " |
| 5582 | "Size 0x%x\n", type, rsrc_cnt, |
| 5583 | rsrc_size); |
| 5584 | return -ENOMEM; |
| 5585 | } |
| 5586 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5587 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5588 | "2903 Post resource extents type-0x%x: " |
| 5589 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5590 | |
| 5591 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5592 | if (!mbox) |
| 5593 | return -ENOMEM; |
| 5594 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5595 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5596 | if (unlikely(rc)) { |
| 5597 | rc = -EIO; |
| 5598 | goto err_exit; |
| 5599 | } |
| 5600 | |
| 5601 | /* |
| 5602 | * Figure out where the response is located. Then get local pointers |
| 5603 | * to the response data. The port does not guarantee to respond to |
| 5604 | * all extents counts request so update the local variable with the |
| 5605 | * allocated count from the port. |
| 5606 | */ |
| 5607 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5608 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5609 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5610 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5611 | } else { |
| 5612 | virtaddr = mbox->sge_array->addr[0]; |
| 5613 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5614 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5615 | id_array = &n_rsrc->id; |
| 5616 | } |
| 5617 | |
| 5618 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5619 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5620 | |
| 5621 | /* |
| 5622 | * Based on the resource size and count, correct the base and max |
| 5623 | * resource values. |
| 5624 | */ |
| 5625 | length = sizeof(struct lpfc_rsrc_blks); |
| 5626 | switch (type) { |
| 5627 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5628 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5629 | sizeof(unsigned long), |
| 5630 | GFP_KERNEL); |
| 5631 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5632 | rc = -ENOMEM; |
| 5633 | goto err_exit; |
| 5634 | } |
| 5635 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5636 | sizeof(uint16_t), |
| 5637 | GFP_KERNEL); |
| 5638 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5639 | kfree(phba->sli4_hba.rpi_bmask); |
| 5640 | rc = -ENOMEM; |
| 5641 | goto err_exit; |
| 5642 | } |
| 5643 | |
| 5644 | /* |
| 5645 | * The next_rpi was initialized with the maximum available |
| 5646 | * count but the port may allocate a smaller number. Catch |
| 5647 | * that case and update the next_rpi. |
| 5648 | */ |
| 5649 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5650 | |
| 5651 | /* Initialize local ptrs for common extent processing later. */ |
| 5652 | bmask = phba->sli4_hba.rpi_bmask; |
| 5653 | ids = phba->sli4_hba.rpi_ids; |
| 5654 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5655 | break; |
| 5656 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5657 | phba->vpi_bmask = kzalloc(longs * |
| 5658 | sizeof(unsigned long), |
| 5659 | GFP_KERNEL); |
| 5660 | if (unlikely(!phba->vpi_bmask)) { |
| 5661 | rc = -ENOMEM; |
| 5662 | goto err_exit; |
| 5663 | } |
| 5664 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5665 | sizeof(uint16_t), |
| 5666 | GFP_KERNEL); |
| 5667 | if (unlikely(!phba->vpi_ids)) { |
| 5668 | kfree(phba->vpi_bmask); |
| 5669 | rc = -ENOMEM; |
| 5670 | goto err_exit; |
| 5671 | } |
| 5672 | |
| 5673 | /* Initialize local ptrs for common extent processing later. */ |
| 5674 | bmask = phba->vpi_bmask; |
| 5675 | ids = phba->vpi_ids; |
| 5676 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5677 | break; |
| 5678 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5679 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5680 | sizeof(unsigned long), |
| 5681 | GFP_KERNEL); |
| 5682 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5683 | rc = -ENOMEM; |
| 5684 | goto err_exit; |
| 5685 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5686 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5687 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5688 | sizeof(uint16_t), |
| 5689 | GFP_KERNEL); |
| 5690 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5691 | kfree(phba->sli4_hba.xri_bmask); |
| 5692 | rc = -ENOMEM; |
| 5693 | goto err_exit; |
| 5694 | } |
| 5695 | |
| 5696 | /* Initialize local ptrs for common extent processing later. */ |
| 5697 | bmask = phba->sli4_hba.xri_bmask; |
| 5698 | ids = phba->sli4_hba.xri_ids; |
| 5699 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5700 | break; |
| 5701 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5702 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5703 | sizeof(unsigned long), |
| 5704 | GFP_KERNEL); |
| 5705 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5706 | rc = -ENOMEM; |
| 5707 | goto err_exit; |
| 5708 | } |
| 5709 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5710 | sizeof(uint16_t), |
| 5711 | GFP_KERNEL); |
| 5712 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5713 | kfree(phba->sli4_hba.vfi_bmask); |
| 5714 | rc = -ENOMEM; |
| 5715 | goto err_exit; |
| 5716 | } |
| 5717 | |
| 5718 | /* Initialize local ptrs for common extent processing later. */ |
| 5719 | bmask = phba->sli4_hba.vfi_bmask; |
| 5720 | ids = phba->sli4_hba.vfi_ids; |
| 5721 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5722 | break; |
| 5723 | default: |
| 5724 | /* Unsupported Opcode. Fail call. */ |
| 5725 | id_array = NULL; |
| 5726 | bmask = NULL; |
| 5727 | ids = NULL; |
| 5728 | ext_blk_list = NULL; |
| 5729 | goto err_exit; |
| 5730 | } |
| 5731 | |
| 5732 | /* |
| 5733 | * Complete initializing the extent configuration with the |
| 5734 | * allocated ids assigned to this function. The bitmask serves |
| 5735 | * as an index into the array and manages the available ids. The |
| 5736 | * array just stores the ids communicated to the port via the wqes. |
| 5737 | */ |
| 5738 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5739 | if ((i % 2) == 0) |
| 5740 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5741 | &id_array[k]); |
| 5742 | else |
| 5743 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5744 | &id_array[k]); |
| 5745 | |
| 5746 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5747 | if (unlikely(!rsrc_blks)) { |
| 5748 | rc = -ENOMEM; |
| 5749 | kfree(bmask); |
| 5750 | kfree(ids); |
| 5751 | goto err_exit; |
| 5752 | } |
| 5753 | rsrc_blks->rsrc_start = rsrc_id; |
| 5754 | rsrc_blks->rsrc_size = rsrc_size; |
| 5755 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5756 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5757 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5758 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5759 | lpfc_sli4_get_iocb_cnt(phba); |
| 5760 | phba->sli4_hba.nvme_xri_start = |
| 5761 | phba->sli4_hba.scsi_xri_start + |
| 5762 | phba->sli4_hba.scsi_xri_max; |
| 5763 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5764 | |
| 5765 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5766 | ids[j] = rsrc_id; |
| 5767 | rsrc_id++; |
| 5768 | j++; |
| 5769 | } |
| 5770 | /* Entire word processed. Get next word.*/ |
| 5771 | if ((i % 2) == 1) |
| 5772 | k++; |
| 5773 | } |
| 5774 | err_exit: |
| 5775 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5776 | return rc; |
| 5777 | } |
| 5778 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5779 | |
| 5780 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5781 | /** |
| 5782 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5783 | * @phba: Pointer to HBA context object. |
| 5784 | * @type: the extent's type. |
| 5785 | * |
| 5786 | * This function deallocates all extents of a particular resource type. |
| 5787 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5788 | * is the caller's responsibility to release all kernel memory resources. |
| 5789 | **/ |
| 5790 | static int |
| 5791 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5792 | { |
| 5793 | int rc; |
| 5794 | uint32_t length, mbox_tmo = 0; |
| 5795 | LPFC_MBOXQ_t *mbox; |
| 5796 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5797 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5798 | |
| 5799 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5800 | if (!mbox) |
| 5801 | return -ENOMEM; |
| 5802 | |
| 5803 | /* |
| 5804 | * This function sends an embedded mailbox because it only sends the |
| 5805 | * the resource type. All extents of this type are released by the |
| 5806 | * port. |
| 5807 | */ |
| 5808 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5809 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5810 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5811 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5812 | length, LPFC_SLI4_MBX_EMBED); |
| 5813 | |
| 5814 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5815 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5816 | LPFC_SLI4_MBX_EMBED); |
| 5817 | if (unlikely(rc)) { |
| 5818 | rc = -EIO; |
| 5819 | goto out_free_mbox; |
| 5820 | } |
| 5821 | if (!phba->sli4_hba.intr_enable) |
| 5822 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5823 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5824 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5825 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5826 | } |
| 5827 | if (unlikely(rc)) { |
| 5828 | rc = -EIO; |
| 5829 | goto out_free_mbox; |
| 5830 | } |
| 5831 | |
| 5832 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5833 | if (bf_get(lpfc_mbox_hdr_status, |
| 5834 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5835 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5836 | "2919 Failed to release resource extents " |
| 5837 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5838 | "Resource memory not released.\n", |
| 5839 | type, |
| 5840 | bf_get(lpfc_mbox_hdr_status, |
| 5841 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5842 | bf_get(lpfc_mbox_hdr_add_status, |
| 5843 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5844 | rc = -EIO; |
| 5845 | goto out_free_mbox; |
| 5846 | } |
| 5847 | |
| 5848 | /* Release kernel memory resources for the specific type. */ |
| 5849 | switch (type) { |
| 5850 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5851 | kfree(phba->vpi_bmask); |
| 5852 | kfree(phba->vpi_ids); |
| 5853 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5854 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5855 | &phba->lpfc_vpi_blk_list, list) { |
| 5856 | list_del_init(&rsrc_blk->list); |
| 5857 | kfree(rsrc_blk); |
| 5858 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5859 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5860 | break; |
| 5861 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5862 | kfree(phba->sli4_hba.xri_bmask); |
| 5863 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5864 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5865 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5866 | list_del_init(&rsrc_blk->list); |
| 5867 | kfree(rsrc_blk); |
| 5868 | } |
| 5869 | break; |
| 5870 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5871 | kfree(phba->sli4_hba.vfi_bmask); |
| 5872 | kfree(phba->sli4_hba.vfi_ids); |
| 5873 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5874 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5875 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5876 | list_del_init(&rsrc_blk->list); |
| 5877 | kfree(rsrc_blk); |
| 5878 | } |
| 5879 | break; |
| 5880 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5881 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5882 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5883 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5884 | list_del_init(&rsrc_blk->list); |
| 5885 | kfree(rsrc_blk); |
| 5886 | } |
| 5887 | break; |
| 5888 | default: |
| 5889 | break; |
| 5890 | } |
| 5891 | |
| 5892 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5893 | |
| 5894 | out_free_mbox: |
| 5895 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5896 | return rc; |
| 5897 | } |
| 5898 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5899 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5900 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 5901 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5902 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5903 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5904 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5905 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 5906 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5907 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5908 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 5909 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5910 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5911 | switch (feature) { |
| 5912 | case LPFC_SET_UE_RECOVERY: |
| 5913 | bf_set(lpfc_mbx_set_feature_UER, |
| 5914 | &mbox->u.mqe.un.set_feature, 1); |
| 5915 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 5916 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5917 | break; |
| 5918 | case LPFC_SET_MDS_DIAGS: |
| 5919 | bf_set(lpfc_mbx_set_feature_mds, |
| 5920 | &mbox->u.mqe.un.set_feature, 1); |
| 5921 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 5922 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5923 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 5924 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5925 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5926 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5927 | |
| 5928 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5929 | } |
| 5930 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5931 | /** |
| 5932 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5933 | * @phba: Pointer to HBA context object. |
| 5934 | * |
| 5935 | * This function allocates all SLI4 resource identifiers. |
| 5936 | **/ |
| 5937 | int |
| 5938 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5939 | { |
| 5940 | int i, rc, error = 0; |
| 5941 | uint16_t count, base; |
| 5942 | unsigned long longs; |
| 5943 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5944 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5945 | 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] | 5946 | if (phba->sli4_hba.extents_in_use) { |
| 5947 | /* |
| 5948 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5949 | * resource extent count must be read and allocated before |
| 5950 | * provisioning the resource id arrays. |
| 5951 | */ |
| 5952 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5953 | LPFC_IDX_RSRC_RDY) { |
| 5954 | /* |
| 5955 | * Extent-based resources are set - the driver could |
| 5956 | * be in a port reset. Figure out if any corrective |
| 5957 | * actions need to be taken. |
| 5958 | */ |
| 5959 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5960 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5961 | if (rc != 0) |
| 5962 | error++; |
| 5963 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5964 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5965 | if (rc != 0) |
| 5966 | error++; |
| 5967 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5968 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5969 | if (rc != 0) |
| 5970 | error++; |
| 5971 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5972 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5973 | if (rc != 0) |
| 5974 | error++; |
| 5975 | |
| 5976 | /* |
| 5977 | * It's possible that the number of resources |
| 5978 | * provided to this port instance changed between |
| 5979 | * resets. Detect this condition and reallocate |
| 5980 | * resources. Otherwise, there is no action. |
| 5981 | */ |
| 5982 | if (error) { |
| 5983 | lpfc_printf_log(phba, KERN_INFO, |
| 5984 | LOG_MBOX | LOG_INIT, |
| 5985 | "2931 Detected extent resource " |
| 5986 | "change. Reallocating all " |
| 5987 | "extents.\n"); |
| 5988 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5989 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5990 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5991 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5992 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5993 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5994 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5995 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5996 | } else |
| 5997 | return 0; |
| 5998 | } |
| 5999 | |
| 6000 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6001 | if (unlikely(rc)) |
| 6002 | goto err_exit; |
| 6003 | |
| 6004 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6005 | if (unlikely(rc)) |
| 6006 | goto err_exit; |
| 6007 | |
| 6008 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6009 | if (unlikely(rc)) |
| 6010 | goto err_exit; |
| 6011 | |
| 6012 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6013 | if (unlikely(rc)) |
| 6014 | goto err_exit; |
| 6015 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6016 | LPFC_IDX_RSRC_RDY); |
| 6017 | return rc; |
| 6018 | } else { |
| 6019 | /* |
| 6020 | * The port does not support resource extents. The XRI, VPI, |
| 6021 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6022 | * Just allocate the bitmasks and provision the resource id |
| 6023 | * arrays. If a port reset is active, the resources don't |
| 6024 | * need any action - just exit. |
| 6025 | */ |
| 6026 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6027 | LPFC_IDX_RSRC_RDY) { |
| 6028 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6029 | lpfc_sli4_remove_rpis(phba); |
| 6030 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6031 | /* RPIs. */ |
| 6032 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6033 | if (count <= 0) { |
| 6034 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6035 | "3279 Invalid provisioning of " |
| 6036 | "rpi:%d\n", count); |
| 6037 | rc = -EINVAL; |
| 6038 | goto err_exit; |
| 6039 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6040 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6041 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6042 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 6043 | sizeof(unsigned long), |
| 6044 | GFP_KERNEL); |
| 6045 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6046 | rc = -ENOMEM; |
| 6047 | goto err_exit; |
| 6048 | } |
| 6049 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 6050 | sizeof(uint16_t), |
| 6051 | GFP_KERNEL); |
| 6052 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6053 | rc = -ENOMEM; |
| 6054 | goto free_rpi_bmask; |
| 6055 | } |
| 6056 | |
| 6057 | for (i = 0; i < count; i++) |
| 6058 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6059 | |
| 6060 | /* VPIs. */ |
| 6061 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6062 | if (count <= 0) { |
| 6063 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6064 | "3280 Invalid provisioning of " |
| 6065 | "vpi:%d\n", count); |
| 6066 | rc = -EINVAL; |
| 6067 | goto free_rpi_ids; |
| 6068 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6069 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6070 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6071 | phba->vpi_bmask = kzalloc(longs * |
| 6072 | sizeof(unsigned long), |
| 6073 | GFP_KERNEL); |
| 6074 | if (unlikely(!phba->vpi_bmask)) { |
| 6075 | rc = -ENOMEM; |
| 6076 | goto free_rpi_ids; |
| 6077 | } |
| 6078 | phba->vpi_ids = kzalloc(count * |
| 6079 | sizeof(uint16_t), |
| 6080 | GFP_KERNEL); |
| 6081 | if (unlikely(!phba->vpi_ids)) { |
| 6082 | rc = -ENOMEM; |
| 6083 | goto free_vpi_bmask; |
| 6084 | } |
| 6085 | |
| 6086 | for (i = 0; i < count; i++) |
| 6087 | phba->vpi_ids[i] = base + i; |
| 6088 | |
| 6089 | /* XRIs. */ |
| 6090 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6091 | if (count <= 0) { |
| 6092 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6093 | "3281 Invalid provisioning of " |
| 6094 | "xri:%d\n", count); |
| 6095 | rc = -EINVAL; |
| 6096 | goto free_vpi_ids; |
| 6097 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6098 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6099 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6100 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 6101 | sizeof(unsigned long), |
| 6102 | GFP_KERNEL); |
| 6103 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6104 | rc = -ENOMEM; |
| 6105 | goto free_vpi_ids; |
| 6106 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6107 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6108 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 6109 | sizeof(uint16_t), |
| 6110 | GFP_KERNEL); |
| 6111 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6112 | rc = -ENOMEM; |
| 6113 | goto free_xri_bmask; |
| 6114 | } |
| 6115 | |
| 6116 | for (i = 0; i < count; i++) |
| 6117 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6118 | |
| 6119 | /* VFIs. */ |
| 6120 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6121 | if (count <= 0) { |
| 6122 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6123 | "3282 Invalid provisioning of " |
| 6124 | "vfi:%d\n", count); |
| 6125 | rc = -EINVAL; |
| 6126 | goto free_xri_ids; |
| 6127 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6128 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6129 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6130 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 6131 | sizeof(unsigned long), |
| 6132 | GFP_KERNEL); |
| 6133 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6134 | rc = -ENOMEM; |
| 6135 | goto free_xri_ids; |
| 6136 | } |
| 6137 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 6138 | sizeof(uint16_t), |
| 6139 | GFP_KERNEL); |
| 6140 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6141 | rc = -ENOMEM; |
| 6142 | goto free_vfi_bmask; |
| 6143 | } |
| 6144 | |
| 6145 | for (i = 0; i < count; i++) |
| 6146 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6147 | |
| 6148 | /* |
| 6149 | * Mark all resources ready. An HBA reset doesn't need |
| 6150 | * to reset the initialization. |
| 6151 | */ |
| 6152 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6153 | LPFC_IDX_RSRC_RDY); |
| 6154 | return 0; |
| 6155 | } |
| 6156 | |
| 6157 | free_vfi_bmask: |
| 6158 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6159 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6160 | free_xri_ids: |
| 6161 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6162 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6163 | free_xri_bmask: |
| 6164 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6165 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6166 | free_vpi_ids: |
| 6167 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6168 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6169 | free_vpi_bmask: |
| 6170 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6171 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6172 | free_rpi_ids: |
| 6173 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6174 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6175 | free_rpi_bmask: |
| 6176 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6177 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6178 | err_exit: |
| 6179 | return rc; |
| 6180 | } |
| 6181 | |
| 6182 | /** |
| 6183 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6184 | * @phba: Pointer to HBA context object. |
| 6185 | * |
| 6186 | * This function allocates the number of elements for the specified |
| 6187 | * resource type. |
| 6188 | **/ |
| 6189 | int |
| 6190 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6191 | { |
| 6192 | if (phba->sli4_hba.extents_in_use) { |
| 6193 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6194 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6195 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6196 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6197 | } else { |
| 6198 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6199 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6200 | kfree(phba->vpi_ids); |
| 6201 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6202 | kfree(phba->sli4_hba.xri_bmask); |
| 6203 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6204 | kfree(phba->sli4_hba.vfi_bmask); |
| 6205 | kfree(phba->sli4_hba.vfi_ids); |
| 6206 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6207 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6208 | } |
| 6209 | |
| 6210 | return 0; |
| 6211 | } |
| 6212 | |
| 6213 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6214 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6215 | * @phba: Pointer to HBA context object. |
| 6216 | * @type: The resource extent type. |
| 6217 | * @extnt_count: buffer to hold port extent count response |
| 6218 | * @extnt_size: buffer to hold port extent size response. |
| 6219 | * |
| 6220 | * This function calls the port to read the host allocated extents |
| 6221 | * for a particular type. |
| 6222 | **/ |
| 6223 | int |
| 6224 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6225 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6226 | { |
| 6227 | bool emb; |
| 6228 | int rc = 0; |
| 6229 | uint16_t curr_blks = 0; |
| 6230 | uint32_t req_len, emb_len; |
| 6231 | uint32_t alloc_len, mbox_tmo; |
| 6232 | struct list_head *blk_list_head; |
| 6233 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6234 | LPFC_MBOXQ_t *mbox; |
| 6235 | void *virtaddr = NULL; |
| 6236 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6237 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6238 | union lpfc_sli4_cfg_shdr *shdr; |
| 6239 | |
| 6240 | switch (type) { |
| 6241 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6242 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6243 | break; |
| 6244 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6245 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6246 | break; |
| 6247 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6248 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6249 | break; |
| 6250 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6251 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6252 | break; |
| 6253 | default: |
| 6254 | return -EIO; |
| 6255 | } |
| 6256 | |
| 6257 | /* Count the number of extents currently allocatd for this type. */ |
| 6258 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6259 | if (curr_blks == 0) { |
| 6260 | /* |
| 6261 | * The GET_ALLOCATED mailbox does not return the size, |
| 6262 | * just the count. The size should be just the size |
| 6263 | * stored in the current allocated block and all sizes |
| 6264 | * for an extent type are the same so set the return |
| 6265 | * value now. |
| 6266 | */ |
| 6267 | *extnt_size = rsrc_blk->rsrc_size; |
| 6268 | } |
| 6269 | curr_blks++; |
| 6270 | } |
| 6271 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6272 | /* |
| 6273 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6274 | * accounts for extents-specific word. |
| 6275 | */ |
| 6276 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6277 | sizeof(uint32_t); |
| 6278 | |
| 6279 | /* |
| 6280 | * Presume the allocation and response will fit into an embedded |
| 6281 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6282 | */ |
| 6283 | emb = LPFC_SLI4_MBX_EMBED; |
| 6284 | req_len = emb_len; |
| 6285 | if (req_len > emb_len) { |
| 6286 | req_len = curr_blks * sizeof(uint16_t) + |
| 6287 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6288 | sizeof(uint32_t); |
| 6289 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6290 | } |
| 6291 | |
| 6292 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6293 | if (!mbox) |
| 6294 | return -ENOMEM; |
| 6295 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6296 | |
| 6297 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6298 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6299 | req_len, emb); |
| 6300 | if (alloc_len < req_len) { |
| 6301 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6302 | "2983 Allocated DMA memory size (x%x) is " |
| 6303 | "less than the requested DMA memory " |
| 6304 | "size (x%x)\n", alloc_len, req_len); |
| 6305 | rc = -ENOMEM; |
| 6306 | goto err_exit; |
| 6307 | } |
| 6308 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6309 | if (unlikely(rc)) { |
| 6310 | rc = -EIO; |
| 6311 | goto err_exit; |
| 6312 | } |
| 6313 | |
| 6314 | if (!phba->sli4_hba.intr_enable) |
| 6315 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6316 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6317 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6318 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6319 | } |
| 6320 | |
| 6321 | if (unlikely(rc)) { |
| 6322 | rc = -EIO; |
| 6323 | goto err_exit; |
| 6324 | } |
| 6325 | |
| 6326 | /* |
| 6327 | * Figure out where the response is located. Then get local pointers |
| 6328 | * to the response data. The port does not guarantee to respond to |
| 6329 | * all extents counts request so update the local variable with the |
| 6330 | * allocated count from the port. |
| 6331 | */ |
| 6332 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6333 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6334 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6335 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6336 | } else { |
| 6337 | virtaddr = mbox->sge_array->addr[0]; |
| 6338 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6339 | shdr = &n_rsrc->cfg_shdr; |
| 6340 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6341 | } |
| 6342 | |
| 6343 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6344 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6345 | "2984 Failed to read allocated resources " |
| 6346 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6347 | type, |
| 6348 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6349 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6350 | rc = -EIO; |
| 6351 | goto err_exit; |
| 6352 | } |
| 6353 | err_exit: |
| 6354 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6355 | return rc; |
| 6356 | } |
| 6357 | |
| 6358 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6359 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6360 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6361 | * @pring: Pointer to driver SLI ring object. |
| 6362 | * @sgl_list: linked link of sgl buffers to post |
| 6363 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6364 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6365 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6366 | * repost them to the port by using SGL block post. This is needed after a |
| 6367 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6368 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6369 | * SGL block post mailbox commands to post them to the port. For single |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6370 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6371 | * mailbox command for posting. |
| 6372 | * |
| 6373 | * Returns: 0 = success, non-zero failure. |
| 6374 | **/ |
| 6375 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6376 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6377 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6378 | { |
| 6379 | struct lpfc_sglq *sglq_entry = NULL; |
| 6380 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6381 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6382 | int status, total_cnt; |
| 6383 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6384 | int last_xritag = NO_XRI; |
| 6385 | LIST_HEAD(prep_sgl_list); |
| 6386 | LIST_HEAD(blck_sgl_list); |
| 6387 | LIST_HEAD(allc_sgl_list); |
| 6388 | LIST_HEAD(post_sgl_list); |
| 6389 | LIST_HEAD(free_sgl_list); |
| 6390 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6391 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6392 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6393 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6394 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6395 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6396 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6397 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6398 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6399 | &allc_sgl_list, list) { |
| 6400 | list_del_init(&sglq_entry->list); |
| 6401 | block_cnt++; |
| 6402 | if ((last_xritag != NO_XRI) && |
| 6403 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6404 | /* a hole in xri block, form a sgl posting block */ |
| 6405 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6406 | post_cnt = block_cnt - 1; |
| 6407 | /* prepare list for next posting block */ |
| 6408 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6409 | block_cnt = 1; |
| 6410 | } else { |
| 6411 | /* prepare list for next posting block */ |
| 6412 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6413 | /* enough sgls for non-embed sgl mbox command */ |
| 6414 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6415 | list_splice_init(&prep_sgl_list, |
| 6416 | &blck_sgl_list); |
| 6417 | post_cnt = block_cnt; |
| 6418 | block_cnt = 0; |
| 6419 | } |
| 6420 | } |
| 6421 | num_posted++; |
| 6422 | |
| 6423 | /* keep track of last sgl's xritag */ |
| 6424 | last_xritag = sglq_entry->sli4_xritag; |
| 6425 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6426 | /* end of repost sgl list condition for buffers */ |
| 6427 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6428 | if (post_cnt == 0) { |
| 6429 | list_splice_init(&prep_sgl_list, |
| 6430 | &blck_sgl_list); |
| 6431 | post_cnt = block_cnt; |
| 6432 | } else if (block_cnt == 1) { |
| 6433 | status = lpfc_sli4_post_sgl(phba, |
| 6434 | sglq_entry->phys, 0, |
| 6435 | sglq_entry->sli4_xritag); |
| 6436 | if (!status) { |
| 6437 | /* successful, put sgl to posted list */ |
| 6438 | list_add_tail(&sglq_entry->list, |
| 6439 | &post_sgl_list); |
| 6440 | } else { |
| 6441 | /* Failure, put sgl to free list */ |
| 6442 | lpfc_printf_log(phba, KERN_WARNING, |
| 6443 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6444 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6445 | "sgl, xritag:x%x\n", |
| 6446 | sglq_entry->sli4_xritag); |
| 6447 | list_add_tail(&sglq_entry->list, |
| 6448 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6449 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6450 | } |
| 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | /* continue until a nembed page worth of sgls */ |
| 6455 | if (post_cnt == 0) |
| 6456 | continue; |
| 6457 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6458 | /* post the buffer list sgls as a block */ |
| 6459 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 6460 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6461 | |
| 6462 | if (!status) { |
| 6463 | /* success, put sgl list to posted sgl list */ |
| 6464 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6465 | } else { |
| 6466 | /* Failure, put sgl list to free sgl list */ |
| 6467 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6468 | struct lpfc_sglq, |
| 6469 | list); |
| 6470 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6471 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6472 | "xritag:x%x-x%x\n", |
| 6473 | sglq_entry_first->sli4_xritag, |
| 6474 | (sglq_entry_first->sli4_xritag + |
| 6475 | post_cnt - 1)); |
| 6476 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6477 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6478 | } |
| 6479 | |
| 6480 | /* don't reset xirtag due to hole in xri block */ |
| 6481 | if (block_cnt == 0) |
| 6482 | last_xritag = NO_XRI; |
| 6483 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6484 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6485 | post_cnt = 0; |
| 6486 | } |
| 6487 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6488 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6489 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6490 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6491 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6492 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6493 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6494 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6495 | list_splice_init(&post_sgl_list, sgl_list); |
| 6496 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6497 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6498 | } else { |
| 6499 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6500 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6501 | return -EIO; |
| 6502 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6503 | |
| 6504 | /* return the number of XRIs actually posted */ |
| 6505 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6506 | } |
| 6507 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6508 | void |
| 6509 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 6510 | { |
| 6511 | uint32_t len; |
| 6512 | |
| 6513 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 6514 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6515 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6516 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 6517 | LPFC_SLI4_MBX_EMBED); |
| 6518 | |
| 6519 | mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION; |
James Smart | b2fd103 | 2016-12-19 15:07:21 -0800 | [diff] [blame] | 6520 | mbox->u.mqe.un.set_host_data.param_len = |
| 6521 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6522 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 6523 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 6524 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 6525 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 6526 | } |
| 6527 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6528 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6529 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6530 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6531 | { |
| 6532 | int rc, i; |
| 6533 | struct lpfc_rqe hrqe; |
| 6534 | struct lpfc_rqe drqe; |
| 6535 | struct lpfc_rqb *rqbp; |
| 6536 | struct rqb_dmabuf *rqb_buffer; |
| 6537 | LIST_HEAD(rqb_buf_list); |
| 6538 | |
| 6539 | rqbp = hrq->rqbp; |
| 6540 | for (i = 0; i < count; i++) { |
| 6541 | /* IF RQ is already full, don't bother */ |
| 6542 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 6543 | break; |
| 6544 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 6545 | if (!rqb_buffer) |
| 6546 | break; |
| 6547 | rqb_buffer->hrq = hrq; |
| 6548 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6549 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6550 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 6551 | } |
| 6552 | while (!list_empty(&rqb_buf_list)) { |
| 6553 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 6554 | hbuf.list); |
| 6555 | |
| 6556 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 6557 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 6558 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 6559 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 6560 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 6561 | if (rc < 0) { |
| 6562 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 6563 | } else { |
| 6564 | list_add_tail(&rqb_buffer->hbuf.list, |
| 6565 | &rqbp->rqb_buffer_list); |
| 6566 | rqbp->buffer_count++; |
| 6567 | } |
| 6568 | } |
| 6569 | return 1; |
| 6570 | } |
| 6571 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6572 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 6573 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6574 | * @phba: Pointer to HBA context object. |
| 6575 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 6576 | * This function is the main SLI4 device initialization PCI function. This |
| 6577 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6578 | * HBA error attention handler code. Caller is not required to hold any |
| 6579 | * locks. |
| 6580 | **/ |
| 6581 | int |
| 6582 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6583 | { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6584 | int rc, i, cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6585 | LPFC_MBOXQ_t *mboxq; |
| 6586 | struct lpfc_mqe *mqe; |
| 6587 | uint8_t *vpd; |
| 6588 | uint32_t vpd_size; |
| 6589 | uint32_t ftr_rsp = 0; |
| 6590 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6591 | struct lpfc_vport *vport = phba->pport; |
| 6592 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6593 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6594 | |
| 6595 | /* Perform a PCI function reset to start from clean */ |
| 6596 | rc = lpfc_pci_function_reset(phba); |
| 6597 | if (unlikely(rc)) |
| 6598 | return -ENODEV; |
| 6599 | |
| 6600 | /* Check the HBA Host Status Register for readyness */ |
| 6601 | rc = lpfc_sli4_post_status_check(phba); |
| 6602 | if (unlikely(rc)) |
| 6603 | return -ENODEV; |
| 6604 | else { |
| 6605 | spin_lock_irq(&phba->hbalock); |
| 6606 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6607 | spin_unlock_irq(&phba->hbalock); |
| 6608 | } |
| 6609 | |
| 6610 | /* |
| 6611 | * Allocate a single mailbox container for initializing the |
| 6612 | * port. |
| 6613 | */ |
| 6614 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6615 | if (!mboxq) |
| 6616 | return -ENOMEM; |
| 6617 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6618 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6619 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6620 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6621 | if (!vpd) { |
| 6622 | rc = -ENOMEM; |
| 6623 | goto out_free_mbox; |
| 6624 | } |
| 6625 | |
| 6626 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6627 | if (unlikely(rc)) { |
| 6628 | kfree(vpd); |
| 6629 | goto out_free_mbox; |
| 6630 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6631 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6632 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6633 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6634 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6635 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6636 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 6637 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6638 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6639 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6640 | |
| 6641 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6642 | LPFC_DCBX_CEE_MODE) |
| 6643 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6644 | else |
| 6645 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6646 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6647 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6648 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6649 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6650 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6651 | "0376 READ_REV Error. SLI Level %d " |
| 6652 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6653 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6654 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6655 | kfree(vpd); |
| 6656 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6657 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6658 | |
| 6659 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6660 | * Continue initialization with default values even if driver failed |
| 6661 | * to read FCoE param config regions, only read parameters if the |
| 6662 | * board is FCoE |
| 6663 | */ |
| 6664 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6665 | lpfc_sli4_read_fcoe_params(phba)) |
| 6666 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6667 | "2570 Failed to read FCoE parameters\n"); |
| 6668 | |
| 6669 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6670 | * Retrieve sli4 device physical port name, failure of doing it |
| 6671 | * is considered as non-fatal. |
| 6672 | */ |
| 6673 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6674 | if (!rc) |
| 6675 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6676 | "3080 Successful retrieving SLI4 device " |
| 6677 | "physical port name: %s.\n", phba->Port); |
| 6678 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6679 | /* |
| 6680 | * Evaluate the read rev and vpd data. Populate the driver |
| 6681 | * state with the results. If this routine fails, the failure |
| 6682 | * is not fatal as the driver will use generic values. |
| 6683 | */ |
| 6684 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6685 | if (unlikely(!rc)) { |
| 6686 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6687 | "0377 Error %d parsing vpd. " |
| 6688 | "Using defaults.\n", rc); |
| 6689 | rc = 0; |
| 6690 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6691 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6692 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6693 | /* Save information as VPD data */ |
| 6694 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6695 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6696 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6697 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6698 | &mqe->un.read_rev); |
| 6699 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6700 | &mqe->un.read_rev); |
| 6701 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6702 | &mqe->un.read_rev); |
| 6703 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6704 | &mqe->un.read_rev); |
| 6705 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6706 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6707 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6708 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6709 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6710 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6711 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6712 | "(%d):0380 READ_REV Status x%x " |
| 6713 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6714 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6715 | bf_get(lpfc_mqe_status, mqe), |
| 6716 | phba->vpd.rev.opFwName, |
| 6717 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6718 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6719 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6720 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6721 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6722 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6723 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6724 | "3362 LUN queue depth changed from %d to %d\n", |
| 6725 | phba->pport->cfg_lun_queue_depth, rc); |
| 6726 | phba->pport->cfg_lun_queue_depth = rc; |
| 6727 | } |
| 6728 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6729 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6730 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6731 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 6732 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6733 | if (rc == MBX_SUCCESS) { |
| 6734 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 6735 | /* Set 1Sec interval to detect UE */ |
| 6736 | phba->eratt_poll_interval = 1; |
| 6737 | phba->sli4_hba.ue_to_sr = bf_get( |
| 6738 | lpfc_mbx_set_feature_UESR, |
| 6739 | &mboxq->u.mqe.un.set_feature); |
| 6740 | phba->sli4_hba.ue_to_rp = bf_get( |
| 6741 | lpfc_mbx_set_feature_UERP, |
| 6742 | &mboxq->u.mqe.un.set_feature); |
| 6743 | } |
| 6744 | } |
| 6745 | |
| 6746 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 6747 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 6748 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 6749 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6750 | if (rc != MBX_SUCCESS) |
| 6751 | phba->mds_diags_support = 0; |
| 6752 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6753 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6754 | /* |
| 6755 | * Discover the port's supported feature set and match it against the |
| 6756 | * hosts requests. |
| 6757 | */ |
| 6758 | lpfc_request_features(phba, mboxq); |
| 6759 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6760 | if (unlikely(rc)) { |
| 6761 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6762 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | /* |
| 6766 | * The port must support FCP initiator mode as this is the |
| 6767 | * only mode running in the host. |
| 6768 | */ |
| 6769 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6770 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6771 | "0378 No support for fcpi mode.\n"); |
| 6772 | ftr_rsp++; |
| 6773 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6774 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6775 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6776 | else |
| 6777 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6778 | /* |
| 6779 | * If the port cannot support the host's requested features |
| 6780 | * then turn off the global config parameters to disable the |
| 6781 | * feature in the driver. This is not a fatal error. |
| 6782 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6783 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6784 | if (phba->cfg_enable_bg) { |
| 6785 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6786 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6787 | else |
| 6788 | ftr_rsp++; |
| 6789 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6790 | |
| 6791 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6792 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6793 | ftr_rsp++; |
| 6794 | |
| 6795 | if (ftr_rsp) { |
| 6796 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6797 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6798 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6799 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6800 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6801 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6802 | phba->cfg_enable_bg = 0; |
| 6803 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6804 | phba->cfg_enable_npiv = 0; |
| 6805 | } |
| 6806 | |
| 6807 | /* These SLI3 features are assumed in SLI4 */ |
| 6808 | spin_lock_irq(&phba->hbalock); |
| 6809 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6810 | spin_unlock_irq(&phba->hbalock); |
| 6811 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6812 | /* |
| 6813 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6814 | * calls depends on these resources to complete port setup. |
| 6815 | */ |
| 6816 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6817 | if (rc) { |
| 6818 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6819 | "2920 Failed to alloc Resource IDs " |
| 6820 | "rc = x%x\n", rc); |
| 6821 | goto out_free_mbox; |
| 6822 | } |
| 6823 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6824 | lpfc_set_host_data(phba, mboxq); |
| 6825 | |
| 6826 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6827 | if (rc) { |
| 6828 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6829 | "2134 Failed to set host os driver version %x", |
| 6830 | rc); |
| 6831 | } |
| 6832 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6833 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6834 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6835 | if (rc) { |
| 6836 | phba->link_state = LPFC_HBA_ERROR; |
| 6837 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6838 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6839 | } |
| 6840 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6841 | mboxq->vport = vport; |
| 6842 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6843 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6844 | if (rc == MBX_SUCCESS) { |
| 6845 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6846 | rc = 0; |
| 6847 | } |
| 6848 | |
| 6849 | /* |
| 6850 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6851 | * it to the mbuf pool. |
| 6852 | */ |
| 6853 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6854 | kfree(mp); |
| 6855 | mboxq->context1 = NULL; |
| 6856 | if (unlikely(rc)) { |
| 6857 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6858 | "0382 READ_SPARAM command failed " |
| 6859 | "status %d, mbxStatus x%x\n", |
| 6860 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6861 | phba->link_state = LPFC_HBA_ERROR; |
| 6862 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6863 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6864 | } |
| 6865 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6866 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6867 | |
| 6868 | /* Update the fc_host data structures with new wwn. */ |
| 6869 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6870 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6871 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6872 | /* Create all the SLI4 queues */ |
| 6873 | rc = lpfc_sli4_queue_create(phba); |
| 6874 | if (rc) { |
| 6875 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6876 | "3089 Failed to allocate queues\n"); |
| 6877 | rc = -ENODEV; |
| 6878 | goto out_free_mbox; |
| 6879 | } |
| 6880 | /* Set up all the queues to the device */ |
| 6881 | rc = lpfc_sli4_queue_setup(phba); |
| 6882 | if (unlikely(rc)) { |
| 6883 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6884 | "0381 Error %d during queue setup.\n ", rc); |
| 6885 | goto out_stop_timers; |
| 6886 | } |
| 6887 | /* Initialize the driver internal SLI layer lists. */ |
| 6888 | lpfc_sli4_setup(phba); |
| 6889 | lpfc_sli4_queue_init(phba); |
| 6890 | |
| 6891 | /* update host els xri-sgl sizes and mappings */ |
| 6892 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6893 | if (unlikely(rc)) { |
| 6894 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6895 | "1400 Failed to update xri-sgl size and " |
| 6896 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6897 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6898 | } |
| 6899 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6900 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6901 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 6902 | phba->sli4_hba.els_xri_cnt); |
| 6903 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6904 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6905 | "0582 Error %d during els sgl post " |
| 6906 | "operation\n", rc); |
| 6907 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6908 | goto out_destroy_queue; |
| 6909 | } |
| 6910 | phba->sli4_hba.els_xri_cnt = rc; |
| 6911 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6912 | if (phba->nvmet_support) { |
| 6913 | /* update host nvmet xri-sgl sizes and mappings */ |
| 6914 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 6915 | if (unlikely(rc)) { |
| 6916 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6917 | "6308 Failed to update nvmet-sgl size " |
| 6918 | "and mapping: %d\n", rc); |
| 6919 | goto out_destroy_queue; |
| 6920 | } |
| 6921 | |
| 6922 | /* register the nvmet sgl pool to the port */ |
| 6923 | rc = lpfc_sli4_repost_sgl_list( |
| 6924 | phba, |
| 6925 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 6926 | phba->sli4_hba.nvmet_xri_cnt); |
| 6927 | if (unlikely(rc < 0)) { |
| 6928 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6929 | "3117 Error %d during nvmet " |
| 6930 | "sgl post\n", rc); |
| 6931 | rc = -ENODEV; |
| 6932 | goto out_destroy_queue; |
| 6933 | } |
| 6934 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6935 | |
| 6936 | cnt = phba->cfg_iocb_cnt * 1024; |
| 6937 | /* We need 1 iocbq for every SGL, for IO processing */ |
| 6938 | cnt += phba->sli4_hba.nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6939 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6940 | /* update host scsi xri-sgl sizes and mappings */ |
| 6941 | rc = lpfc_sli4_scsi_sgl_update(phba); |
| 6942 | if (unlikely(rc)) { |
| 6943 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6944 | "6309 Failed to update scsi-sgl size " |
| 6945 | "and mapping: %d\n", rc); |
| 6946 | goto out_destroy_queue; |
| 6947 | } |
| 6948 | |
| 6949 | /* update host nvme xri-sgl sizes and mappings */ |
| 6950 | rc = lpfc_sli4_nvme_sgl_update(phba); |
| 6951 | if (unlikely(rc)) { |
| 6952 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6953 | "6082 Failed to update nvme-sgl size " |
| 6954 | "and mapping: %d\n", rc); |
| 6955 | goto out_destroy_queue; |
| 6956 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6957 | |
| 6958 | cnt = phba->cfg_iocb_cnt * 1024; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6962 | /* Initialize and populate the iocb list per host */ |
| 6963 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6964 | "2821 initialize iocb list %d total %d\n", |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6965 | phba->cfg_iocb_cnt, cnt); |
| 6966 | rc = lpfc_init_iocb_list(phba, cnt); |
| 6967 | if (rc) { |
| 6968 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6969 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6970 | goto out_destroy_queue; |
| 6971 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6972 | } |
| 6973 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6974 | if (phba->nvmet_support) |
| 6975 | lpfc_nvmet_create_targetport(phba); |
| 6976 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6977 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6978 | /* Post initial buffers to all RQs created */ |
| 6979 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 6980 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 6981 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 6982 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 6983 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 6984 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6985 | rqbp->buffer_count = 0; |
| 6986 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6987 | lpfc_post_rq_buffer( |
| 6988 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 6989 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6990 | LPFC_NVMET_RQE_DEF_COUNT, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6991 | } |
| 6992 | } |
| 6993 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6994 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 6995 | /* register the allocated scsi sgl pool to the port */ |
| 6996 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6997 | if (unlikely(rc)) { |
| 6998 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6999 | "0383 Error %d during scsi sgl post " |
| 7000 | "operation\n", rc); |
| 7001 | /* Some Scsi buffers were moved to abort scsi list */ |
| 7002 | /* A pci function reset will repost them */ |
| 7003 | rc = -ENODEV; |
| 7004 | goto out_destroy_queue; |
| 7005 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7006 | } |
| 7007 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 7008 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 7009 | (phba->nvmet_support == 0)) { |
| 7010 | |
| 7011 | /* register the allocated nvme sgl pool to the port */ |
| 7012 | rc = lpfc_repost_nvme_sgl_list(phba); |
| 7013 | if (unlikely(rc)) { |
| 7014 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7015 | "6116 Error %d during nvme sgl post " |
| 7016 | "operation\n", rc); |
| 7017 | /* Some NVME buffers were moved to abort nvme list */ |
| 7018 | /* A pci function reset will repost them */ |
| 7019 | rc = -ENODEV; |
| 7020 | goto out_destroy_queue; |
| 7021 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7022 | } |
| 7023 | |
| 7024 | /* Post the rpi header region to the device. */ |
| 7025 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7026 | if (unlikely(rc)) { |
| 7027 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7028 | "0393 Error %d during rpi post operation\n", |
| 7029 | rc); |
| 7030 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7031 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7032 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7033 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7034 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7035 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7036 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7037 | /* |
| 7038 | * The FC Port needs to register FCFI (index 0) |
| 7039 | */ |
| 7040 | lpfc_reg_fcfi(phba, mboxq); |
| 7041 | mboxq->vport = phba->pport; |
| 7042 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7043 | if (rc != MBX_SUCCESS) |
| 7044 | goto out_unset_queue; |
| 7045 | rc = 0; |
| 7046 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7047 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7048 | } else { |
| 7049 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7050 | |
| 7051 | /* First register the FCFI */ |
| 7052 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7053 | mboxq->vport = phba->pport; |
| 7054 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7055 | if (rc != MBX_SUCCESS) |
| 7056 | goto out_unset_queue; |
| 7057 | rc = 0; |
| 7058 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7059 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7060 | |
| 7061 | /* Next register the MRQs */ |
| 7062 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7063 | mboxq->vport = phba->pport; |
| 7064 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7065 | if (rc != MBX_SUCCESS) |
| 7066 | goto out_unset_queue; |
| 7067 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7068 | } |
| 7069 | /* Check if the port is configured to be disabled */ |
| 7070 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7071 | } |
| 7072 | |
| 7073 | /* Arm the CQs and then EQs on device */ |
| 7074 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7075 | |
| 7076 | /* Indicate device interrupt mode */ |
| 7077 | phba->sli4_hba.intr_enable = 1; |
| 7078 | |
| 7079 | /* Allow asynchronous mailbox command to go through */ |
| 7080 | spin_lock_irq(&phba->hbalock); |
| 7081 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7082 | spin_unlock_irq(&phba->hbalock); |
| 7083 | |
| 7084 | /* Post receive buffers to the device */ |
| 7085 | lpfc_sli4_rb_setup(phba); |
| 7086 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7087 | /* Reset HBA FCF states after HBA reset */ |
| 7088 | phba->fcf.fcf_flag = 0; |
| 7089 | phba->fcf.current_rec.flag = 0; |
| 7090 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7091 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7092 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7093 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7094 | |
| 7095 | /* Start heart beat timer */ |
| 7096 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7097 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7098 | phba->hb_outstanding = 0; |
| 7099 | phba->last_completion_time = jiffies; |
| 7100 | |
| 7101 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7102 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7103 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7104 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7105 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7106 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7107 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7108 | if (!rc) { |
| 7109 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7110 | "2829 This device supports " |
| 7111 | "Advanced Error Reporting (AER)\n"); |
| 7112 | spin_lock_irq(&phba->hbalock); |
| 7113 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7114 | spin_unlock_irq(&phba->hbalock); |
| 7115 | } else { |
| 7116 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7117 | "2830 This device does not support " |
| 7118 | "Advanced Error Reporting (AER)\n"); |
| 7119 | phba->cfg_aer_support = 0; |
| 7120 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7121 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7122 | } |
| 7123 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7124 | /* |
| 7125 | * The port is ready, set the host's link state to LINK_DOWN |
| 7126 | * in preparation for link interrupts. |
| 7127 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7128 | spin_lock_irq(&phba->hbalock); |
| 7129 | phba->link_state = LPFC_LINK_DOWN; |
| 7130 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7131 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7132 | (phba->hba_flag & LINK_DISABLED)) { |
| 7133 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7134 | "3103 Adapter Link is disabled.\n"); |
| 7135 | lpfc_down_link(phba, mboxq); |
| 7136 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7137 | if (rc != MBX_SUCCESS) { |
| 7138 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7139 | "3104 Adapter failed to issue " |
| 7140 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 7141 | goto out_unset_queue; |
| 7142 | } |
| 7143 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7144 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7145 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7146 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7147 | if (rc) |
| 7148 | goto out_unset_queue; |
| 7149 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7150 | } |
| 7151 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7152 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7153 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7154 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7155 | lpfc_sli4_queue_unset(phba); |
| 7156 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7157 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7158 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7159 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7160 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7161 | out_free_mbox: |
| 7162 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7163 | return rc; |
| 7164 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7165 | |
| 7166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7167 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7168 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7169 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7170 | * This is the callback function for mailbox timer. The mailbox |
| 7171 | * timer is armed when a new mailbox command is issued and the timer |
| 7172 | * is deleted when the mailbox complete. The function is called by |
| 7173 | * the kernel timer code when a mailbox does not complete within |
| 7174 | * expected time. This function wakes up the worker thread to |
| 7175 | * process the mailbox timeout and returns. All the processing is |
| 7176 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7177 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7178 | void |
| 7179 | lpfc_mbox_timeout(unsigned long ptr) |
| 7180 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7181 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7182 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7183 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7184 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7185 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7186 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7187 | if (!tmo_posted) |
| 7188 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7189 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7190 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7191 | if (!tmo_posted) |
| 7192 | lpfc_worker_wake_up(phba); |
| 7193 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7194 | } |
| 7195 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7196 | /** |
| 7197 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7198 | * are pending |
| 7199 | * @phba: Pointer to HBA context object. |
| 7200 | * |
| 7201 | * This function checks if any mailbox completions are present on the mailbox |
| 7202 | * completion queue. |
| 7203 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7204 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7205 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7206 | { |
| 7207 | |
| 7208 | uint32_t idx; |
| 7209 | struct lpfc_queue *mcq; |
| 7210 | struct lpfc_mcqe *mcqe; |
| 7211 | bool pending_completions = false; |
| 7212 | |
| 7213 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7214 | return false; |
| 7215 | |
| 7216 | /* Check for completions on mailbox completion queue */ |
| 7217 | |
| 7218 | mcq = phba->sli4_hba.mbx_cq; |
| 7219 | idx = mcq->hba_index; |
| 7220 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { |
| 7221 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 7222 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7223 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7224 | pending_completions = true; |
| 7225 | break; |
| 7226 | } |
| 7227 | idx = (idx + 1) % mcq->entry_count; |
| 7228 | if (mcq->hba_index == idx) |
| 7229 | break; |
| 7230 | } |
| 7231 | return pending_completions; |
| 7232 | |
| 7233 | } |
| 7234 | |
| 7235 | /** |
| 7236 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7237 | * that were missed. |
| 7238 | * @phba: Pointer to HBA context object. |
| 7239 | * |
| 7240 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7241 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7242 | * checks to see if mbox completions are on the mailbox completion queue |
| 7243 | * and will process all the completions associated with the eq for the |
| 7244 | * mailbox completion queue. |
| 7245 | **/ |
| 7246 | bool |
| 7247 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7248 | { |
| 7249 | |
| 7250 | uint32_t eqidx; |
| 7251 | struct lpfc_queue *fpeq = NULL; |
| 7252 | struct lpfc_eqe *eqe; |
| 7253 | bool mbox_pending; |
| 7254 | |
| 7255 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7256 | return false; |
| 7257 | |
| 7258 | /* Find the eq associated with the mcq */ |
| 7259 | |
| 7260 | if (phba->sli4_hba.hba_eq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7261 | for (eqidx = 0; eqidx < phba->io_channel_irqs; eqidx++) |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7262 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == |
| 7263 | phba->sli4_hba.mbx_cq->assoc_qid) { |
| 7264 | fpeq = phba->sli4_hba.hba_eq[eqidx]; |
| 7265 | break; |
| 7266 | } |
| 7267 | if (!fpeq) |
| 7268 | return false; |
| 7269 | |
| 7270 | /* Turn off interrupts from this EQ */ |
| 7271 | |
| 7272 | lpfc_sli4_eq_clr_intr(fpeq); |
| 7273 | |
| 7274 | /* Check to see if a mbox completion is pending */ |
| 7275 | |
| 7276 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7277 | |
| 7278 | /* |
| 7279 | * If a mbox completion is pending, process all the events on EQ |
| 7280 | * associated with the mbox completion queue (this could include |
| 7281 | * mailbox commands, async events, els commands, receive queue data |
| 7282 | * and fcp commands) |
| 7283 | */ |
| 7284 | |
| 7285 | if (mbox_pending) |
| 7286 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 7287 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 7288 | fpeq->EQ_processed++; |
| 7289 | } |
| 7290 | |
| 7291 | /* Always clear and re-arm the EQ */ |
| 7292 | |
| 7293 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 7294 | |
| 7295 | return mbox_pending; |
| 7296 | |
| 7297 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7298 | |
| 7299 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7300 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7301 | * @phba: Pointer to HBA context object. |
| 7302 | * |
| 7303 | * This function is called from worker thread when a mailbox command times out. |
| 7304 | * The caller is not required to hold any locks. This function will reset the |
| 7305 | * HBA and recover all the pending commands. |
| 7306 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7307 | void |
| 7308 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7309 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7310 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7311 | MAILBOX_t *mb = NULL; |
| 7312 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7313 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7314 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7315 | /* If the mailbox completed, process the completion and return */ |
| 7316 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7317 | return; |
| 7318 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7319 | if (pmbox != NULL) |
| 7320 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7321 | /* Check the pmbox pointer first. There is a race condition |
| 7322 | * between the mbox timeout handler getting executed in the |
| 7323 | * worklist and the mailbox actually completing. When this |
| 7324 | * race condition occurs, the mbox_active will be NULL. |
| 7325 | */ |
| 7326 | spin_lock_irq(&phba->hbalock); |
| 7327 | if (pmbox == NULL) { |
| 7328 | lpfc_printf_log(phba, KERN_WARNING, |
| 7329 | LOG_MBOX | LOG_SLI, |
| 7330 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7331 | "exiting\n"); |
| 7332 | spin_unlock_irq(&phba->hbalock); |
| 7333 | return; |
| 7334 | } |
| 7335 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7336 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7337 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7338 | "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] | 7339 | mb->mbxCommand, |
| 7340 | phba->pport->port_state, |
| 7341 | phba->sli.sli_flag, |
| 7342 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7343 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7344 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7345 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7346 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7347 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7348 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7349 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7350 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7351 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7352 | spin_lock_irq(&phba->hbalock); |
| 7353 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7354 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7355 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7356 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 7357 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7358 | |
| 7359 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 7360 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7361 | |
| 7362 | /* Reset the HBA device */ |
| 7363 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7364 | } |
| 7365 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7366 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7367 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7368 | * @phba: Pointer to HBA context object. |
| 7369 | * @pmbox: Pointer to mailbox object. |
| 7370 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7371 | * |
| 7372 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7373 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 7374 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7375 | * The mailbox command can be submitted in polling mode, in which case |
| 7376 | * this function will wait in a polling loop for the completion of the |
| 7377 | * mailbox. |
| 7378 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 7379 | * function will submit the command and returns immediately without waiting |
| 7380 | * for the mailbox completion. The no_wait is supported only when HBA |
| 7381 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 7382 | * The SLI interface allows only one mailbox pending at a time. If the |
| 7383 | * mailbox is issued in polling mode and there is already a mailbox |
| 7384 | * pending, then the function will return an error. If the mailbox is issued |
| 7385 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 7386 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 7387 | * The sli layer owns the mailbox object until the completion of mailbox |
| 7388 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 7389 | * return codes the caller owns the mailbox command after the return of |
| 7390 | * the function. |
| 7391 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7392 | static int |
| 7393 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 7394 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7395 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7396 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7397 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7398 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7399 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7400 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7401 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7402 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7403 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7404 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7405 | int processing_queue = 0; |
| 7406 | |
| 7407 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7408 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 7409 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7410 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7411 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7412 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7413 | return MBX_SUCCESS; |
| 7414 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7415 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7416 | pmbox = lpfc_mbox_get(phba); |
| 7417 | if (!pmbox) { |
| 7418 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7419 | return MBX_SUCCESS; |
| 7420 | } |
| 7421 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7422 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7423 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7424 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7425 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7426 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7427 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7428 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7429 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7430 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7431 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7432 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7433 | } |
| 7434 | } |
| 7435 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7436 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7437 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 7438 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7439 | goto out_not_finished; |
| 7440 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7441 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7442 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7443 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 7444 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7445 | goto out_not_finished; |
| 7446 | } |
| 7447 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7448 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7449 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7450 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7451 | status = MBX_SUCCESS; |
| 7452 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7453 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 7454 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7455 | |
| 7456 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7457 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7458 | "(%d):0311 Mailbox command x%x cannot " |
| 7459 | "issue Data: x%x x%x\n", |
| 7460 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7461 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7462 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7463 | } |
| 7464 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7465 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7466 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 7467 | !(hc_copy & HC_MBINT_ENA)) { |
| 7468 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7469 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7470 | "(%d):2528 Mailbox command x%x cannot " |
| 7471 | "issue Data: x%x x%x\n", |
| 7472 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7473 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7474 | goto out_not_finished; |
| 7475 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 7476 | } |
| 7477 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7478 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7479 | /* Polling for a mbox command when another one is already active |
| 7480 | * is not allowed in SLI. Also, the driver must have established |
| 7481 | * SLI2 mode to queue and process multiple mbox commands. |
| 7482 | */ |
| 7483 | |
| 7484 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7485 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7486 | |
| 7487 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7488 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7489 | "(%d):2529 Mailbox command x%x " |
| 7490 | "cannot issue Data: x%x x%x\n", |
| 7491 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7492 | pmbox->u.mb.mbxCommand, |
| 7493 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7494 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7495 | } |
| 7496 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7497 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7498 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7499 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7500 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7501 | "(%d):2530 Mailbox command x%x " |
| 7502 | "cannot issue Data: x%x x%x\n", |
| 7503 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7504 | pmbox->u.mb.mbxCommand, |
| 7505 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7506 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7507 | } |
| 7508 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7509 | /* Another mailbox command is still being processed, queue this |
| 7510 | * command to be processed later. |
| 7511 | */ |
| 7512 | lpfc_mbox_put(phba, pmbox); |
| 7513 | |
| 7514 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7515 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7516 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7517 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7518 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 7519 | mbx->mbxCommand, |
| 7520 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7521 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7522 | |
| 7523 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7524 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7525 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7526 | if (pmbox->vport) { |
| 7527 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7528 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7529 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7530 | (uint32_t)mbx->mbxCommand, |
| 7531 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7532 | } |
| 7533 | else { |
| 7534 | lpfc_debugfs_disc_trc(phba->pport, |
| 7535 | LPFC_DISC_TRC_MBOX, |
| 7536 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7537 | (uint32_t)mbx->mbxCommand, |
| 7538 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7539 | } |
| 7540 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7541 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7542 | } |
| 7543 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7544 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7545 | |
| 7546 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 7547 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7548 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7549 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7550 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7551 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7552 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7553 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7554 | "(%d):2531 Mailbox command x%x " |
| 7555 | "cannot issue Data: x%x x%x\n", |
| 7556 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7557 | pmbox->u.mb.mbxCommand, |
| 7558 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7559 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7560 | } |
| 7561 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7562 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7563 | 1000); |
| 7564 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7565 | } |
| 7566 | |
| 7567 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7568 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7569 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7570 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7571 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 7572 | mbx->mbxCommand, |
| 7573 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7574 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7575 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7576 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7577 | if (pmbox->vport) { |
| 7578 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7579 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7580 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7581 | (uint32_t)mbx->mbxCommand, |
| 7582 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7583 | } |
| 7584 | else { |
| 7585 | lpfc_debugfs_disc_trc(phba->pport, |
| 7586 | LPFC_DISC_TRC_MBOX, |
| 7587 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7588 | (uint32_t)mbx->mbxCommand, |
| 7589 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7590 | } |
| 7591 | } |
| 7592 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7593 | psli->slistat.mbox_cmd++; |
| 7594 | evtctr = psli->slistat.mbox_event; |
| 7595 | |
| 7596 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7597 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7598 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7599 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7600 | /* Populate mbox extension offset word. */ |
| 7601 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7602 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7603 | = (uint8_t *)phba->mbox_ext |
| 7604 | - (uint8_t *)phba->mbox; |
| 7605 | } |
| 7606 | |
| 7607 | /* Copy the mailbox extension data */ |
| 7608 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7609 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 7610 | (uint8_t *)phba->mbox_ext, |
| 7611 | pmbox->in_ext_byte_len); |
| 7612 | } |
| 7613 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7614 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7615 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7616 | /* Populate mbox extension offset word. */ |
| 7617 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7618 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7619 | = MAILBOX_HBA_EXT_OFFSET; |
| 7620 | |
| 7621 | /* Copy the mailbox extension data */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7622 | if (pmbox->in_ext_byte_len && pmbox->context2) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7623 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7624 | MAILBOX_HBA_EXT_OFFSET, |
| 7625 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7626 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7627 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7628 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7629 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 7630 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7631 | |
| 7632 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7633 | word */ |
| 7634 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7635 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7636 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7637 | |
| 7638 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7639 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7640 | to_slim = phba->MBslimaddr; |
| 7641 | writel(ldata, to_slim); |
| 7642 | readl(to_slim); /* flush */ |
| 7643 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7644 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7645 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7646 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7647 | } |
| 7648 | |
| 7649 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7650 | |
| 7651 | switch (flag) { |
| 7652 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7653 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7654 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7655 | /* Interrupt board to do it */ |
| 7656 | writel(CA_MBATT, phba->CAregaddr); |
| 7657 | readl(phba->CAregaddr); /* flush */ |
| 7658 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7659 | break; |
| 7660 | |
| 7661 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7662 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7663 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7664 | /* Interrupt board to do it */ |
| 7665 | writel(CA_MBATT, phba->CAregaddr); |
| 7666 | readl(phba->CAregaddr); /* flush */ |
| 7667 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7668 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7669 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7670 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7671 | word0 = le32_to_cpu(word0); |
| 7672 | } else { |
| 7673 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7674 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7675 | spin_unlock_irqrestore(&phba->hbalock, |
| 7676 | drvr_flag); |
| 7677 | goto out_not_finished; |
| 7678 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7679 | } |
| 7680 | |
| 7681 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7682 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7683 | spin_unlock_irqrestore(&phba->hbalock, |
| 7684 | drvr_flag); |
| 7685 | goto out_not_finished; |
| 7686 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7687 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7688 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7689 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7690 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7691 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7692 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7693 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7694 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7695 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7696 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7697 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7698 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7699 | } |
| 7700 | |
| 7701 | /* Check if we took a mbox interrupt while we were |
| 7702 | polling */ |
| 7703 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7704 | && (evtctr != psli->slistat.mbox_event)) |
| 7705 | break; |
| 7706 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7707 | if (i++ > 10) { |
| 7708 | spin_unlock_irqrestore(&phba->hbalock, |
| 7709 | drvr_flag); |
| 7710 | msleep(1); |
| 7711 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7712 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7713 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7714 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7715 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7716 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7717 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7718 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7719 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7720 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7721 | /* Check real SLIM for any errors */ |
| 7722 | slimword0 = readl(phba->MBslimaddr); |
| 7723 | slimmb = (MAILBOX_t *) & slimword0; |
| 7724 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7725 | && slimmb->mbxStatus) { |
| 7726 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7727 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7728 | word0 = slimword0; |
| 7729 | } |
| 7730 | } |
| 7731 | } else { |
| 7732 | /* First copy command data */ |
| 7733 | word0 = readl(phba->MBslimaddr); |
| 7734 | } |
| 7735 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7736 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7737 | spin_unlock_irqrestore(&phba->hbalock, |
| 7738 | drvr_flag); |
| 7739 | goto out_not_finished; |
| 7740 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7741 | } |
| 7742 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7743 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7744 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7745 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 7746 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7747 | /* Copy the mailbox extension data */ |
| 7748 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7749 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7750 | pmbox->context2, |
| 7751 | pmbox->out_ext_byte_len); |
| 7752 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7753 | } else { |
| 7754 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7755 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7756 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7757 | /* Copy the mailbox extension data */ |
| 7758 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7759 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7760 | phba->MBslimaddr + |
| 7761 | MAILBOX_HBA_EXT_OFFSET, |
| 7762 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7763 | } |
| 7764 | } |
| 7765 | |
| 7766 | writel(HA_MBATT, phba->HAregaddr); |
| 7767 | readl(phba->HAregaddr); /* flush */ |
| 7768 | |
| 7769 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7770 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7771 | } |
| 7772 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7773 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7774 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7775 | |
| 7776 | out_not_finished: |
| 7777 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7778 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7779 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7780 | } |
| 7781 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7782 | } |
| 7783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7784 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7785 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7786 | * @phba: Pointer to HBA context object. |
| 7787 | * |
| 7788 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7789 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7790 | * possible outstanding mailbox command before return. |
| 7791 | * |
| 7792 | * Returns: |
| 7793 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7794 | * the outstanding mailbox command timed out. |
| 7795 | **/ |
| 7796 | static int |
| 7797 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7798 | { |
| 7799 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7800 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7801 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7802 | |
| 7803 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7804 | spin_lock_irq(&phba->hbalock); |
| 7805 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7806 | /* Determine how long we might wait for the active mailbox |
| 7807 | * command to be gracefully completed by firmware. |
| 7808 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7809 | if (phba->sli.mbox_active) |
| 7810 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7811 | phba->sli.mbox_active) * |
| 7812 | 1000) + jiffies; |
| 7813 | spin_unlock_irq(&phba->hbalock); |
| 7814 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7815 | /* Make sure the mailbox is really active */ |
| 7816 | if (timeout) |
| 7817 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 7818 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7819 | /* Wait for the outstnading mailbox command to complete */ |
| 7820 | while (phba->sli.mbox_active) { |
| 7821 | /* Check active mailbox complete status every 2ms */ |
| 7822 | msleep(2); |
| 7823 | if (time_after(jiffies, timeout)) { |
| 7824 | /* Timeout, marked the outstanding cmd not complete */ |
| 7825 | rc = 1; |
| 7826 | break; |
| 7827 | } |
| 7828 | } |
| 7829 | |
| 7830 | /* Can not cleanly block async mailbox command, fails it */ |
| 7831 | if (rc) { |
| 7832 | spin_lock_irq(&phba->hbalock); |
| 7833 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7834 | spin_unlock_irq(&phba->hbalock); |
| 7835 | } |
| 7836 | return rc; |
| 7837 | } |
| 7838 | |
| 7839 | /** |
| 7840 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7841 | * @phba: Pointer to HBA context object. |
| 7842 | * |
| 7843 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7844 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7845 | * that there is no outstanding mailbox command before resuming posting |
| 7846 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7847 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7848 | * mailbox command posting. |
| 7849 | **/ |
| 7850 | static void |
| 7851 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7852 | { |
| 7853 | struct lpfc_sli *psli = &phba->sli; |
| 7854 | |
| 7855 | spin_lock_irq(&phba->hbalock); |
| 7856 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7857 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7858 | spin_unlock_irq(&phba->hbalock); |
| 7859 | return; |
| 7860 | } |
| 7861 | |
| 7862 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7863 | * successful or timeout, after timing-out the outstanding mailbox |
| 7864 | * command shall always be removed, so just unblock posting async |
| 7865 | * mailbox command and resume |
| 7866 | */ |
| 7867 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7868 | spin_unlock_irq(&phba->hbalock); |
| 7869 | |
| 7870 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7871 | lpfc_worker_wake_up(phba); |
| 7872 | } |
| 7873 | |
| 7874 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7875 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7876 | * @phba: Pointer to HBA context object. |
| 7877 | * @mboxq: Pointer to mailbox object. |
| 7878 | * |
| 7879 | * The function waits for the bootstrap mailbox register ready bit from |
| 7880 | * port for twice the regular mailbox command timeout value. |
| 7881 | * |
| 7882 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7883 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7884 | **/ |
| 7885 | static int |
| 7886 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7887 | { |
| 7888 | uint32_t db_ready; |
| 7889 | unsigned long timeout; |
| 7890 | struct lpfc_register bmbx_reg; |
| 7891 | |
| 7892 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7893 | * 1000) + jiffies; |
| 7894 | |
| 7895 | do { |
| 7896 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7897 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7898 | if (!db_ready) |
| 7899 | msleep(2); |
| 7900 | |
| 7901 | if (time_after(jiffies, timeout)) |
| 7902 | return MBXERR_ERROR; |
| 7903 | } while (!db_ready); |
| 7904 | |
| 7905 | return 0; |
| 7906 | } |
| 7907 | |
| 7908 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7909 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7910 | * @phba: Pointer to HBA context object. |
| 7911 | * @mboxq: Pointer to mailbox object. |
| 7912 | * |
| 7913 | * The function posts a mailbox to the port. The mailbox is expected |
| 7914 | * to be comletely filled in and ready for the port to operate on it. |
| 7915 | * This routine executes a synchronous completion operation on the |
| 7916 | * mailbox by polling for its completion. |
| 7917 | * |
| 7918 | * The caller must not be holding any locks when calling this routine. |
| 7919 | * |
| 7920 | * Returns: |
| 7921 | * MBX_SUCCESS - mailbox posted successfully |
| 7922 | * Any of the MBX error values. |
| 7923 | **/ |
| 7924 | static int |
| 7925 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7926 | { |
| 7927 | int rc = MBX_SUCCESS; |
| 7928 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7929 | uint32_t mcqe_status; |
| 7930 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7931 | struct lpfc_sli *psli = &phba->sli; |
| 7932 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7933 | struct lpfc_bmbx_create *mbox_rgn; |
| 7934 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7935 | |
| 7936 | /* |
| 7937 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7938 | * at a time and there is no queueing provided. |
| 7939 | */ |
| 7940 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7941 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7942 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7943 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7944 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7945 | "cannot issue Data: x%x x%x\n", |
| 7946 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7947 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7948 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7949 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7950 | psli->sli_flag, MBX_POLL); |
| 7951 | return MBXERR_ERROR; |
| 7952 | } |
| 7953 | /* The server grabs the token and owns it until release */ |
| 7954 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7955 | phba->sli.mbox_active = mboxq; |
| 7956 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7957 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7958 | /* wait for bootstrap mbox register for readyness */ |
| 7959 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7960 | if (rc) |
| 7961 | goto exit; |
| 7962 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7963 | /* |
| 7964 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7965 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7966 | * the bmbx mailbox region. |
| 7967 | */ |
| 7968 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7969 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7970 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7971 | sizeof(struct lpfc_mqe)); |
| 7972 | |
| 7973 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7974 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7975 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7976 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7977 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7978 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7979 | if (rc) |
| 7980 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7981 | |
| 7982 | /* Post the low mailbox dma address to the port. */ |
| 7983 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7984 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7985 | /* wait for bootstrap mbox register for low address write done */ |
| 7986 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7987 | if (rc) |
| 7988 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7989 | |
| 7990 | /* |
| 7991 | * Read the CQ to ensure the mailbox has completed. |
| 7992 | * If so, update the mailbox status so that the upper layers |
| 7993 | * can complete the request normally. |
| 7994 | */ |
| 7995 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7996 | sizeof(struct lpfc_mqe)); |
| 7997 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7998 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7999 | sizeof(struct lpfc_mcqe)); |
| 8000 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8001 | /* |
| 8002 | * When the CQE status indicates a failure and the mailbox status |
| 8003 | * indicates success then copy the CQE status into the mailbox status |
| 8004 | * (and prefix it with x4000). |
| 8005 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8006 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8007 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8008 | bf_set(lpfc_mqe_status, mb, |
| 8009 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8010 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8011 | } else |
| 8012 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8013 | |
| 8014 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8015 | "(%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] | 8016 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8017 | " 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] | 8018 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8019 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8020 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8021 | bf_get(lpfc_mqe_status, mb), |
| 8022 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8023 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8024 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8025 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8026 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8027 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8028 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8029 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8030 | mboxq->mcqe.trailer); |
| 8031 | exit: |
| 8032 | /* We are holding the token, no needed for lock when release */ |
| 8033 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8034 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8035 | phba->sli.mbox_active = NULL; |
| 8036 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8037 | return rc; |
| 8038 | } |
| 8039 | |
| 8040 | /** |
| 8041 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8042 | * @phba: Pointer to HBA context object. |
| 8043 | * @pmbox: Pointer to mailbox object. |
| 8044 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8045 | * |
| 8046 | * This function is called by discovery code and HBA management code to submit |
| 8047 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8048 | * |
| 8049 | * Return codes the caller owns the mailbox command after the return of the |
| 8050 | * function. |
| 8051 | **/ |
| 8052 | static int |
| 8053 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8054 | uint32_t flag) |
| 8055 | { |
| 8056 | struct lpfc_sli *psli = &phba->sli; |
| 8057 | unsigned long iflags; |
| 8058 | int rc; |
| 8059 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8060 | /* dump from issue mailbox command if setup */ |
| 8061 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8062 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8063 | rc = lpfc_mbox_dev_check(phba); |
| 8064 | if (unlikely(rc)) { |
| 8065 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8066 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8067 | "cannot issue Data: x%x x%x\n", |
| 8068 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8069 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8070 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8071 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8072 | psli->sli_flag, flag); |
| 8073 | goto out_not_finished; |
| 8074 | } |
| 8075 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8076 | /* Detect polling mode and jump to a handler */ |
| 8077 | if (!phba->sli4_hba.intr_enable) { |
| 8078 | if (flag == MBX_POLL) |
| 8079 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8080 | else |
| 8081 | rc = -EIO; |
| 8082 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8083 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8084 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8085 | "(x%x/x%x) failure: " |
| 8086 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8087 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8088 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8089 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8090 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8091 | mboxq), |
| 8092 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8093 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8094 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8095 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8096 | bf_get(lpfc_mcqe_ext_status, |
| 8097 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8098 | psli->sli_flag, flag); |
| 8099 | return rc; |
| 8100 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8101 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8102 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8103 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8104 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8105 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8106 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8107 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8108 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8109 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8110 | /* Try to block the asynchronous mailbox posting */ |
| 8111 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8112 | if (!rc) { |
| 8113 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8114 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8115 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8116 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8117 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8118 | "(%d):2597 Sync Mailbox command " |
| 8119 | "x%x (x%x/x%x) failure: " |
| 8120 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8121 | "Data: x%x x%x\n,", |
| 8122 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8123 | mboxq->u.mb.mbxCommand, |
| 8124 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8125 | mboxq), |
| 8126 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8127 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8128 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8129 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8130 | bf_get(lpfc_mcqe_ext_status, |
| 8131 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8132 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8133 | /* Unblock the async mailbox posting afterward */ |
| 8134 | lpfc_sli4_async_mbox_unblock(phba); |
| 8135 | } |
| 8136 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8137 | } |
| 8138 | |
| 8139 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8140 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8141 | if (rc) { |
| 8142 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8143 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8144 | "cannot issue Data: x%x x%x\n", |
| 8145 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8146 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8147 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8148 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8149 | psli->sli_flag, flag); |
| 8150 | goto out_not_finished; |
| 8151 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8152 | |
| 8153 | /* Put the mailbox command to the driver internal FIFO */ |
| 8154 | psli->slistat.mbox_busy++; |
| 8155 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8156 | lpfc_mbox_put(phba, mboxq); |
| 8157 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8158 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8159 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8160 | "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] | 8161 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8162 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8163 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8164 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8165 | phba->pport->port_state, |
| 8166 | psli->sli_flag, MBX_NOWAIT); |
| 8167 | /* Wake up worker thread to transport mailbox command from head */ |
| 8168 | lpfc_worker_wake_up(phba); |
| 8169 | |
| 8170 | return MBX_BUSY; |
| 8171 | |
| 8172 | out_not_finished: |
| 8173 | return MBX_NOT_FINISHED; |
| 8174 | } |
| 8175 | |
| 8176 | /** |
| 8177 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8178 | * @phba: Pointer to HBA context object. |
| 8179 | * |
| 8180 | * This function is called by worker thread to send a mailbox command to |
| 8181 | * SLI4 HBA firmware. |
| 8182 | * |
| 8183 | **/ |
| 8184 | int |
| 8185 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8186 | { |
| 8187 | struct lpfc_sli *psli = &phba->sli; |
| 8188 | LPFC_MBOXQ_t *mboxq; |
| 8189 | int rc = MBX_SUCCESS; |
| 8190 | unsigned long iflags; |
| 8191 | struct lpfc_mqe *mqe; |
| 8192 | uint32_t mbx_cmnd; |
| 8193 | |
| 8194 | /* Check interrupt mode before post async mailbox command */ |
| 8195 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8196 | return MBX_NOT_FINISHED; |
| 8197 | |
| 8198 | /* Check for mailbox command service token */ |
| 8199 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8200 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8201 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8202 | return MBX_NOT_FINISHED; |
| 8203 | } |
| 8204 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8205 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8206 | return MBX_NOT_FINISHED; |
| 8207 | } |
| 8208 | if (unlikely(phba->sli.mbox_active)) { |
| 8209 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8210 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8211 | "0384 There is pending active mailbox cmd\n"); |
| 8212 | return MBX_NOT_FINISHED; |
| 8213 | } |
| 8214 | /* Take the mailbox command service token */ |
| 8215 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8216 | |
| 8217 | /* Get the next mailbox command from head of queue */ |
| 8218 | mboxq = lpfc_mbox_get(phba); |
| 8219 | |
| 8220 | /* If no more mailbox command waiting for post, we're done */ |
| 8221 | if (!mboxq) { |
| 8222 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8223 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8224 | return MBX_SUCCESS; |
| 8225 | } |
| 8226 | phba->sli.mbox_active = mboxq; |
| 8227 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8228 | |
| 8229 | /* Check device readiness for posting mailbox command */ |
| 8230 | rc = lpfc_mbox_dev_check(phba); |
| 8231 | if (unlikely(rc)) |
| 8232 | /* Driver clean routine will clean up pending mailbox */ |
| 8233 | goto out_not_finished; |
| 8234 | |
| 8235 | /* Prepare the mbox command to be posted */ |
| 8236 | mqe = &mboxq->u.mqe; |
| 8237 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8238 | |
| 8239 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8240 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8241 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8242 | |
| 8243 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8244 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8245 | "x%x x%x\n", |
| 8246 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8247 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8248 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8249 | phba->pport->port_state, psli->sli_flag); |
| 8250 | |
| 8251 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8252 | if (mboxq->vport) { |
| 8253 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8254 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8255 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8256 | mbx_cmnd, mqe->un.mb_words[0], |
| 8257 | mqe->un.mb_words[1]); |
| 8258 | } else { |
| 8259 | lpfc_debugfs_disc_trc(phba->pport, |
| 8260 | LPFC_DISC_TRC_MBOX, |
| 8261 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8262 | mbx_cmnd, mqe->un.mb_words[0], |
| 8263 | mqe->un.mb_words[1]); |
| 8264 | } |
| 8265 | } |
| 8266 | psli->slistat.mbox_cmd++; |
| 8267 | |
| 8268 | /* Post the mailbox command to the port */ |
| 8269 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8270 | if (rc != MBX_SUCCESS) { |
| 8271 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8272 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8273 | "cannot issue Data: x%x x%x\n", |
| 8274 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8275 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8276 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8277 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8278 | psli->sli_flag, MBX_NOWAIT); |
| 8279 | goto out_not_finished; |
| 8280 | } |
| 8281 | |
| 8282 | return rc; |
| 8283 | |
| 8284 | out_not_finished: |
| 8285 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8286 | if (phba->sli.mbox_active) { |
| 8287 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8288 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8289 | /* Release the token */ |
| 8290 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8291 | phba->sli.mbox_active = NULL; |
| 8292 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8293 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8294 | |
| 8295 | return MBX_NOT_FINISHED; |
| 8296 | } |
| 8297 | |
| 8298 | /** |
| 8299 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8300 | * @phba: Pointer to HBA context object. |
| 8301 | * @pmbox: Pointer to mailbox object. |
| 8302 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8303 | * |
| 8304 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8305 | * the API jump table function pointer from the lpfc_hba struct. |
| 8306 | * |
| 8307 | * Return codes the caller owns the mailbox command after the return of the |
| 8308 | * function. |
| 8309 | **/ |
| 8310 | int |
| 8311 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8312 | { |
| 8313 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8314 | } |
| 8315 | |
| 8316 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8317 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8318 | * @phba: The hba struct for which this call is being executed. |
| 8319 | * @dev_grp: The HBA PCI-Device group number. |
| 8320 | * |
| 8321 | * This routine sets up the mbox interface API function jump table in @phba |
| 8322 | * struct. |
| 8323 | * Returns: 0 - success, -ENODEV - failure. |
| 8324 | **/ |
| 8325 | int |
| 8326 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8327 | { |
| 8328 | |
| 8329 | switch (dev_grp) { |
| 8330 | case LPFC_PCI_DEV_LP: |
| 8331 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8332 | phba->lpfc_sli_handle_slow_ring_event = |
| 8333 | lpfc_sli_handle_slow_ring_event_s3; |
| 8334 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8335 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8336 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8337 | break; |
| 8338 | case LPFC_PCI_DEV_OC: |
| 8339 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8340 | phba->lpfc_sli_handle_slow_ring_event = |
| 8341 | lpfc_sli_handle_slow_ring_event_s4; |
| 8342 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8343 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8344 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8345 | break; |
| 8346 | default: |
| 8347 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8348 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8349 | dev_grp); |
| 8350 | return -ENODEV; |
| 8351 | break; |
| 8352 | } |
| 8353 | return 0; |
| 8354 | } |
| 8355 | |
| 8356 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8357 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8358 | * @phba: Pointer to HBA context object. |
| 8359 | * @pring: Pointer to driver SLI ring object. |
| 8360 | * @piocb: Pointer to address of newly added command iocb. |
| 8361 | * |
| 8362 | * This function is called with hbalock held to add a command |
| 8363 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 8364 | * to the ring. |
| 8365 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8366 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8367 | __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] | 8368 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8369 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8370 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8371 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 8372 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8373 | } |
| 8374 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8375 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8376 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8377 | * @phba: Pointer to HBA context object. |
| 8378 | * @pring: Pointer to driver SLI ring object. |
| 8379 | * @piocb: Pointer to address of newly added command iocb. |
| 8380 | * |
| 8381 | * This function is called with hbalock held before a new |
| 8382 | * iocb is submitted to the firmware. This function checks |
| 8383 | * txq to flush the iocbs in txq to Firmware before |
| 8384 | * submitting new iocbs to the Firmware. |
| 8385 | * If there are iocbs in the txq which need to be submitted |
| 8386 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 8387 | * of the txq after dequeuing it from txq. |
| 8388 | * If there is no iocb in the txq then the function will return |
| 8389 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 8390 | * *piocb to find if there are more commands in the txq. |
| 8391 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8392 | static struct lpfc_iocbq * |
| 8393 | 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] | 8394 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8395 | { |
| 8396 | struct lpfc_iocbq * nextiocb; |
| 8397 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8398 | lockdep_assert_held(&phba->hbalock); |
| 8399 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8400 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 8401 | if (!nextiocb) { |
| 8402 | nextiocb = *piocb; |
| 8403 | *piocb = NULL; |
| 8404 | } |
| 8405 | |
| 8406 | return nextiocb; |
| 8407 | } |
| 8408 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8409 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8410 | * __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] | 8411 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8412 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8413 | * @piocb: Pointer to command iocb. |
| 8414 | * @flag: Flag indicating if this command can be put into txq. |
| 8415 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8416 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 8417 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 8418 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 8419 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 8420 | * this function allows only iocbs for posting buffers. This function finds |
| 8421 | * next available slot in the command ring and posts the command to the |
| 8422 | * available slot and writes the port attention register to request HBA start |
| 8423 | * processing new iocb. If there is no slot available in the ring and |
| 8424 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 8425 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8426 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8427 | * This function is called with hbalock held. The function will return success |
| 8428 | * after it successfully submit the iocb to firmware or after adding to the |
| 8429 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8430 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8431 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8432 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8433 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8434 | { |
| 8435 | struct lpfc_iocbq *nextiocb; |
| 8436 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8437 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8438 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8439 | lockdep_assert_held(&phba->hbalock); |
| 8440 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8441 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 8442 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 8443 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 8444 | lpfc_printf_log(phba, KERN_ERR, |
| 8445 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8446 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8447 | piocb->iocb.ulpCommand); |
| 8448 | dump_stack(); |
| 8449 | return IOCB_ERROR; |
| 8450 | } |
| 8451 | |
| 8452 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8453 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 8454 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 8455 | return IOCB_ERROR; |
| 8456 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8457 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8458 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 8459 | return IOCB_ERROR; |
| 8460 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8461 | /* |
| 8462 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 8463 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8464 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8465 | return IOCB_ERROR; |
| 8466 | |
| 8467 | /* |
| 8468 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8469 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8470 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8471 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8472 | goto iocb_busy; |
| 8473 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8474 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8475 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8476 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8477 | * can be issued if the link is not up. |
| 8478 | */ |
| 8479 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8480 | case CMD_GEN_REQUEST64_CR: |
| 8481 | case CMD_GEN_REQUEST64_CX: |
| 8482 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 8483 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8484 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8485 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 8486 | MENLO_TRANSPORT_TYPE)) |
| 8487 | |
| 8488 | goto iocb_busy; |
| 8489 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8490 | case CMD_QUE_RING_BUF_CN: |
| 8491 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8492 | /* |
| 8493 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 8494 | * completion, iocb_cmpl MUST be 0. |
| 8495 | */ |
| 8496 | if (piocb->iocb_cmpl) |
| 8497 | piocb->iocb_cmpl = NULL; |
| 8498 | /*FALLTHROUGH*/ |
| 8499 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8500 | case CMD_CLOSE_XRI_CN: |
| 8501 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8502 | break; |
| 8503 | default: |
| 8504 | goto iocb_busy; |
| 8505 | } |
| 8506 | |
| 8507 | /* |
| 8508 | * For FCP commands, we must be in a state where we can process link |
| 8509 | * attention events. |
| 8510 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8511 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8512 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8513 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8514 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8515 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8516 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 8517 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 8518 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 8519 | |
| 8520 | if (iocb) |
| 8521 | lpfc_sli_update_ring(phba, pring); |
| 8522 | else |
| 8523 | lpfc_sli_update_full_ring(phba, pring); |
| 8524 | |
| 8525 | if (!piocb) |
| 8526 | return IOCB_SUCCESS; |
| 8527 | |
| 8528 | goto out_busy; |
| 8529 | |
| 8530 | iocb_busy: |
| 8531 | pring->stats.iocb_cmd_delay++; |
| 8532 | |
| 8533 | out_busy: |
| 8534 | |
| 8535 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8536 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8537 | return IOCB_SUCCESS; |
| 8538 | } |
| 8539 | |
| 8540 | return IOCB_BUSY; |
| 8541 | } |
| 8542 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8543 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8544 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 8545 | * @phba: Pointer to HBA context object. |
| 8546 | * @piocb: Pointer to command iocb. |
| 8547 | * @sglq: Pointer to the scatter gather queue object. |
| 8548 | * |
| 8549 | * This routine converts the bpl or bde that is in the IOCB |
| 8550 | * to a sgl list for the sli4 hardware. The physical address |
| 8551 | * of the bpl/bde is converted back to a virtual address. |
| 8552 | * If the IOCB contains a BPL then the list of BDE's is |
| 8553 | * converted to sli4_sge's. If the IOCB contains a single |
| 8554 | * BDE then it is converted to a single sli_sge. |
| 8555 | * The IOCB is still in cpu endianess so the contents of |
| 8556 | * the bpl can be used without byte swapping. |
| 8557 | * |
| 8558 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 8559 | **/ |
| 8560 | static uint16_t |
| 8561 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 8562 | struct lpfc_sglq *sglq) |
| 8563 | { |
| 8564 | uint16_t xritag = NO_XRI; |
| 8565 | struct ulp_bde64 *bpl = NULL; |
| 8566 | struct ulp_bde64 bde; |
| 8567 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8568 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8569 | IOCB_t *icmd; |
| 8570 | int numBdes = 0; |
| 8571 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8572 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 8573 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8574 | |
| 8575 | if (!piocbq || !sglq) |
| 8576 | return xritag; |
| 8577 | |
| 8578 | sgl = (struct sli4_sge *)sglq->sgl; |
| 8579 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8580 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 8581 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8582 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 8583 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 8584 | sizeof(struct ulp_bde64); |
| 8585 | /* The addrHigh and addrLow fields within the IOCB |
| 8586 | * have not been byteswapped yet so there is no |
| 8587 | * need to swap them back. |
| 8588 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8589 | if (piocbq->context3) |
| 8590 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 8591 | else |
| 8592 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8593 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8594 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8595 | if (!bpl) |
| 8596 | return xritag; |
| 8597 | |
| 8598 | for (i = 0; i < numBdes; i++) { |
| 8599 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8600 | sgl->addr_hi = bpl->addrHigh; |
| 8601 | sgl->addr_lo = bpl->addrLow; |
| 8602 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8603 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8604 | if ((i+1) == numBdes) |
| 8605 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8606 | else |
| 8607 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8608 | /* swap the size field back to the cpu so we |
| 8609 | * can assign it to the sgl. |
| 8610 | */ |
| 8611 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 8612 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8613 | /* The offsets in the sgl need to be accumulated |
| 8614 | * separately for the request and reply lists. |
| 8615 | * The request is always first, the reply follows. |
| 8616 | */ |
| 8617 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 8618 | /* add up the reply sg entries */ |
| 8619 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 8620 | inbound++; |
| 8621 | /* first inbound? reset the offset */ |
| 8622 | if (inbound == 1) |
| 8623 | offset = 0; |
| 8624 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 8625 | bf_set(lpfc_sli4_sge_type, sgl, |
| 8626 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8627 | offset += bde.tus.f.bdeSize; |
| 8628 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8629 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8630 | bpl++; |
| 8631 | sgl++; |
| 8632 | } |
| 8633 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8634 | /* The addrHigh and addrLow fields of the BDE have not |
| 8635 | * been byteswapped yet so they need to be swapped |
| 8636 | * before putting them in the sgl. |
| 8637 | */ |
| 8638 | sgl->addr_hi = |
| 8639 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8640 | sgl->addr_lo = |
| 8641 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8642 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8643 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8644 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8645 | sgl->sge_len = |
| 8646 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8647 | } |
| 8648 | return sglq->sli4_xritag; |
| 8649 | } |
| 8650 | |
| 8651 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8652 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8653 | * @phba: Pointer to HBA context object. |
| 8654 | * @piocb: Pointer to command iocb. |
| 8655 | * @wqe: Pointer to the work queue entry. |
| 8656 | * |
| 8657 | * This routine converts the iocb command to its Work Queue Entry |
| 8658 | * equivalent. The wqe pointer should not have any fields set when |
| 8659 | * this routine is called because it will memcpy over them. |
| 8660 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8661 | * wqe. |
| 8662 | * |
| 8663 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8664 | **/ |
| 8665 | static int |
| 8666 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 8667 | union lpfc_wqe *wqe) |
| 8668 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8669 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8670 | uint8_t ct = 0; |
| 8671 | uint32_t fip; |
| 8672 | uint32_t abort_tag; |
| 8673 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8674 | uint8_t cmnd; |
| 8675 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8676 | uint16_t abrt_iotag; |
| 8677 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8678 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8679 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8680 | int numBdes, i; |
| 8681 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8682 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8683 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8684 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8685 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8686 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8687 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8688 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8689 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8690 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8691 | command_type = ELS_COMMAND_FIP; |
| 8692 | else |
| 8693 | command_type = ELS_COMMAND_NON_FIP; |
| 8694 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8695 | if (phba->fcp_embed_io) |
| 8696 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8697 | /* Some of the fields are in the right position already */ |
| 8698 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 8699 | if (iocbq->iocb.ulpCommand != CMD_SEND_FRAME) { |
| 8700 | /* The ct field has moved so reset */ |
| 8701 | wqe->generic.wqe_com.word7 = 0; |
| 8702 | wqe->generic.wqe_com.word10 = 0; |
| 8703 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8704 | |
| 8705 | abort_tag = (uint32_t) iocbq->iotag; |
| 8706 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8707 | /* words0-2 bpl convert bde */ |
| 8708 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8709 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8710 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8711 | bpl = (struct ulp_bde64 *) |
| 8712 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8713 | if (!bpl) |
| 8714 | return IOCB_ERROR; |
| 8715 | |
| 8716 | /* Should already be byte swapped. */ |
| 8717 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8718 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8719 | /* swap the size field back to the cpu so we |
| 8720 | * can assign it to the sgl. |
| 8721 | */ |
| 8722 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8723 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8724 | total_len = 0; |
| 8725 | for (i = 0; i < numBdes; i++) { |
| 8726 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8727 | total_len += bde.tus.f.bdeSize; |
| 8728 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8729 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8730 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8731 | |
| 8732 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8733 | cmnd = iocbq->iocb.ulpCommand; |
| 8734 | |
| 8735 | switch (iocbq->iocb.ulpCommand) { |
| 8736 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8737 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8738 | ndlp = iocbq->context_un.ndlp; |
| 8739 | else |
| 8740 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8741 | if (!iocbq->iocb.ulpLe) { |
| 8742 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8743 | "2007 Only Limited Edition cmd Format" |
| 8744 | " supported 0x%x\n", |
| 8745 | iocbq->iocb.ulpCommand); |
| 8746 | return IOCB_ERROR; |
| 8747 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8748 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8749 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8750 | /* Els_reguest64 has a TMO */ |
| 8751 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8752 | iocbq->iocb.ulpTimeout); |
| 8753 | /* Need a VF for word 4 set the vf bit*/ |
| 8754 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8755 | /* And a VFID for word 12 */ |
| 8756 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8757 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8758 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8759 | iocbq->iocb.ulpContext); |
| 8760 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8761 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8762 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8763 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8764 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8765 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8766 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8767 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8768 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8769 | &phba->sli4_hba.sli_intf); |
| 8770 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8771 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8772 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8773 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8774 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8775 | *pcmd == ELS_CMD_PLOGI)) { |
| 8776 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8777 | bf_set(els_req64_sid, &wqe->els_req, |
| 8778 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8779 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8780 | !(phba->fc_topology == |
| 8781 | LPFC_TOPOLOGY_LOOP)) |
| 8782 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8783 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8784 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8785 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8786 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8787 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8788 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8789 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8790 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8791 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8792 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8793 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8794 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8795 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8796 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8797 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8798 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8799 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8800 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8801 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8802 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8803 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8804 | iocbq->iocb.un.ulpWord[3]); |
| 8805 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8806 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8807 | /* The entire sequence is transmitted for this IOCB */ |
| 8808 | xmit_len = total_len; |
| 8809 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8810 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8811 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8812 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8813 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8814 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8815 | /* word4 relative_offset memcpy */ |
| 8816 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8817 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8818 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8819 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8820 | LPFC_WQE_IOD_WRITE); |
| 8821 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8822 | LPFC_WQE_LENLOC_WORD12); |
| 8823 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8824 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8825 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8826 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8827 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8828 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8829 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8830 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8831 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8832 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8833 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8834 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8835 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8836 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8837 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8838 | LPFC_WQE_LENLOC_WORD3); |
| 8839 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8840 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8841 | case CMD_FCP_IWRITE64_CR: |
| 8842 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8843 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8844 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8845 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 8846 | xmit_len + sizeof(struct fcp_rsp)); |
| 8847 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 8848 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8849 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8850 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8851 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8852 | iocbq->iocb.ulpFCP2Rcvy); |
| 8853 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8854 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8855 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8856 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8857 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8858 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8859 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8860 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8861 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8862 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 8863 | if (iocbq->priority) { |
| 8864 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8865 | (iocbq->priority << 1)); |
| 8866 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8867 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8868 | (phba->cfg_XLanePriority << 1)); |
| 8869 | } |
| 8870 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8871 | /* Note, word 10 is already initialized to 0 */ |
| 8872 | |
| 8873 | if (phba->fcp_embed_io) { |
| 8874 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8875 | struct sli4_sge *sgl; |
| 8876 | union lpfc_wqe128 *wqe128; |
| 8877 | struct fcp_cmnd *fcp_cmnd; |
| 8878 | uint32_t *ptr; |
| 8879 | |
| 8880 | /* 128 byte wqe support here */ |
| 8881 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8882 | |
| 8883 | lpfc_cmd = iocbq->context1; |
| 8884 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8885 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8886 | |
| 8887 | /* Word 0-2 - FCP_CMND */ |
| 8888 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8889 | BUFF_TYPE_BDE_IMMED; |
| 8890 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8891 | wqe128->generic.bde.addrHigh = 0; |
| 8892 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8893 | |
| 8894 | bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1); |
| 8895 | |
| 8896 | /* Word 22-29 FCP CMND Payload */ |
| 8897 | ptr = &wqe128->words[22]; |
| 8898 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8899 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8900 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8901 | case CMD_FCP_IREAD64_CR: |
| 8902 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8903 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8904 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 8905 | xmit_len + sizeof(struct fcp_rsp)); |
| 8906 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 8907 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8908 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8909 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8910 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8911 | iocbq->iocb.ulpFCP2Rcvy); |
| 8912 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8913 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8914 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8915 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8916 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8917 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8918 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8919 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8920 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8921 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 8922 | if (iocbq->priority) { |
| 8923 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8924 | (iocbq->priority << 1)); |
| 8925 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8926 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8927 | (phba->cfg_XLanePriority << 1)); |
| 8928 | } |
| 8929 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8930 | /* Note, word 10 is already initialized to 0 */ |
| 8931 | |
| 8932 | if (phba->fcp_embed_io) { |
| 8933 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8934 | struct sli4_sge *sgl; |
| 8935 | union lpfc_wqe128 *wqe128; |
| 8936 | struct fcp_cmnd *fcp_cmnd; |
| 8937 | uint32_t *ptr; |
| 8938 | |
| 8939 | /* 128 byte wqe support here */ |
| 8940 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8941 | |
| 8942 | lpfc_cmd = iocbq->context1; |
| 8943 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8944 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8945 | |
| 8946 | /* Word 0-2 - FCP_CMND */ |
| 8947 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8948 | BUFF_TYPE_BDE_IMMED; |
| 8949 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8950 | wqe128->generic.bde.addrHigh = 0; |
| 8951 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8952 | |
| 8953 | bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1); |
| 8954 | |
| 8955 | /* Word 22-29 FCP CMND Payload */ |
| 8956 | ptr = &wqe128->words[22]; |
| 8957 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8958 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8959 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8960 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8961 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8962 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8963 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 8964 | xmit_len + sizeof(struct fcp_rsp)); |
| 8965 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 8966 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8967 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8968 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8969 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8970 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8971 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8972 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8973 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8974 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8975 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8976 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8977 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8978 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8979 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 8980 | if (iocbq->priority) { |
| 8981 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8982 | (iocbq->priority << 1)); |
| 8983 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8984 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8985 | (phba->cfg_XLanePriority << 1)); |
| 8986 | } |
| 8987 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8988 | /* Note, word 10 is already initialized to 0 */ |
| 8989 | |
| 8990 | if (phba->fcp_embed_io) { |
| 8991 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8992 | struct sli4_sge *sgl; |
| 8993 | union lpfc_wqe128 *wqe128; |
| 8994 | struct fcp_cmnd *fcp_cmnd; |
| 8995 | uint32_t *ptr; |
| 8996 | |
| 8997 | /* 128 byte wqe support here */ |
| 8998 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8999 | |
| 9000 | lpfc_cmd = iocbq->context1; |
| 9001 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 9002 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9003 | |
| 9004 | /* Word 0-2 - FCP_CMND */ |
| 9005 | wqe128->generic.bde.tus.f.bdeFlags = |
| 9006 | BUFF_TYPE_BDE_IMMED; |
| 9007 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9008 | wqe128->generic.bde.addrHigh = 0; |
| 9009 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 9010 | |
| 9011 | bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1); |
| 9012 | |
| 9013 | /* Word 22-29 FCP CMND Payload */ |
| 9014 | ptr = &wqe128->words[22]; |
| 9015 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9016 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9017 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9018 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9019 | /* For this command calculate the xmit length of the |
| 9020 | * request bde. |
| 9021 | */ |
| 9022 | xmit_len = 0; |
| 9023 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9024 | sizeof(struct ulp_bde64); |
| 9025 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9026 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9027 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9028 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9029 | xmit_len += bde.tus.f.bdeSize; |
| 9030 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9031 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9032 | wqe->gen_req.request_payload_len = xmit_len; |
| 9033 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9034 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9035 | /* word6 context tag copied in memcpy */ |
| 9036 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9037 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9038 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9039 | "2015 Invalid CT %x command 0x%x\n", |
| 9040 | ct, iocbq->iocb.ulpCommand); |
| 9041 | return IOCB_ERROR; |
| 9042 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9043 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9044 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9045 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9046 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9047 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9048 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9049 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9050 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9051 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9052 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9053 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9054 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9055 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9056 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9057 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9058 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9059 | /* word4 */ |
| 9060 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9061 | /* word5 iocb=rsvd wge=did */ |
| 9062 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9063 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9064 | |
| 9065 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9066 | &phba->sli4_hba.sli_intf); |
| 9067 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 9068 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9069 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9070 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9071 | iocbq->vport->fc_myDID); |
| 9072 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9073 | bf_set(wqe_els_did, |
| 9074 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9075 | } |
| 9076 | } |
| 9077 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9078 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9079 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9080 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9081 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9082 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9083 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9084 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9085 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9086 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9087 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9088 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9089 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9090 | LPFC_WQE_LENLOC_WORD3); |
| 9091 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9092 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9093 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9094 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9095 | iocbq->context2)->virt); |
| 9096 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9097 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9098 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9099 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9100 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9101 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9102 | phba->vpi_ids[phba->pport->vpi]); |
| 9103 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9104 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9105 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9106 | case CMD_CLOSE_XRI_CN: |
| 9107 | case CMD_ABORT_XRI_CN: |
| 9108 | case CMD_ABORT_XRI_CX: |
| 9109 | /* words 0-2 memcpy should be 0 rserved */ |
| 9110 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9111 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9112 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9113 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9114 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9115 | } else |
| 9116 | fip = 0; |
| 9117 | |
| 9118 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9119 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9120 | * The link is down, or the command was ELS_FIP |
| 9121 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9122 | * on the wire. |
| 9123 | */ |
| 9124 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9125 | else |
| 9126 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9127 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9128 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9129 | wqe->abort_cmd.rsrvd5 = 0; |
| 9130 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9131 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9132 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9133 | /* |
| 9134 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9135 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9136 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9137 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9138 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9139 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9140 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9141 | cmnd = CMD_ABORT_XRI_CX; |
| 9142 | command_type = OTHER_COMMAND; |
| 9143 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9144 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9145 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9146 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9147 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9148 | * we re-construct this WQE here based on information in |
| 9149 | * iocbq from scratch. |
| 9150 | */ |
| 9151 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9152 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9153 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9154 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9155 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9156 | LPFC_ABTS_UNSOL_INT) { |
| 9157 | /* ABTS sent by initiator to CT exchange, the |
| 9158 | * RX_ID field will be filled with the newly |
| 9159 | * allocated responder XRI. |
| 9160 | */ |
| 9161 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9162 | iocbq->sli4_xritag); |
| 9163 | } else { |
| 9164 | /* ABTS sent by responder to CT exchange, the |
| 9165 | * RX_ID field will be filled with the responder |
| 9166 | * RX_ID from ABTS. |
| 9167 | */ |
| 9168 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9169 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9170 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9171 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9172 | 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] | 9173 | |
| 9174 | /* Use CT=VPI */ |
| 9175 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9176 | ndlp->nlp_DID); |
| 9177 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9178 | iocbq->iocb.ulpContext); |
| 9179 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9180 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9181 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9182 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9183 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9184 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9185 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9186 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9187 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9188 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9189 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9190 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9191 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9192 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9193 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9194 | } |
| 9195 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9196 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9197 | case CMD_SEND_FRAME: |
| 9198 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9199 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9200 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9201 | case CMD_XRI_ABORTED_CX: |
| 9202 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9203 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9204 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9205 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9206 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9207 | default: |
| 9208 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9209 | "2014 Invalid command 0x%x\n", |
| 9210 | iocbq->iocb.ulpCommand); |
| 9211 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9212 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9213 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9214 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9215 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9216 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9217 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9218 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9219 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9220 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9221 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9222 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9223 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9224 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9225 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9226 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9227 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9228 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9229 | 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] | 9230 | return 0; |
| 9231 | } |
| 9232 | |
| 9233 | /** |
| 9234 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9235 | * @phba: Pointer to HBA context object. |
| 9236 | * @ring_number: SLI ring number to issue iocb on. |
| 9237 | * @piocb: Pointer to command iocb. |
| 9238 | * @flag: Flag indicating if this command can be put into txq. |
| 9239 | * |
| 9240 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9241 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9242 | * |
| 9243 | * This function is called with hbalock held. The function will return success |
| 9244 | * after it successfully submit the iocb to firmware or after adding to the |
| 9245 | * txq. |
| 9246 | **/ |
| 9247 | static int |
| 9248 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9249 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9250 | { |
| 9251 | struct lpfc_sglq *sglq; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9252 | union lpfc_wqe *wqe; |
| 9253 | union lpfc_wqe128 wqe128; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9254 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9255 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9256 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9257 | /* Get the WQ */ |
| 9258 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9259 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
| 9260 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) |
| 9261 | wq = phba->sli4_hba.fcp_wq[piocb->hba_wqidx]; |
| 9262 | else |
| 9263 | wq = phba->sli4_hba.oas_wq; |
| 9264 | } else { |
| 9265 | wq = phba->sli4_hba.els_wq; |
| 9266 | } |
| 9267 | |
| 9268 | /* Get corresponding ring */ |
| 9269 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9270 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9271 | /* |
| 9272 | * The WQE can be either 64 or 128 bytes, |
| 9273 | * so allocate space on the stack assuming the largest. |
| 9274 | */ |
| 9275 | wqe = (union lpfc_wqe *)&wqe128; |
| 9276 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9277 | lockdep_assert_held(&phba->hbalock); |
| 9278 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9279 | if (piocb->sli4_xritag == NO_XRI) { |
| 9280 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9281 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9282 | sglq = NULL; |
| 9283 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9284 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9285 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9286 | __lpfc_sli_ringtx_put(phba, |
| 9287 | pring, piocb); |
| 9288 | return IOCB_SUCCESS; |
| 9289 | } else { |
| 9290 | return IOCB_BUSY; |
| 9291 | } |
| 9292 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9293 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9294 | if (!sglq) { |
| 9295 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9296 | __lpfc_sli_ringtx_put(phba, |
| 9297 | pring, |
| 9298 | piocb); |
| 9299 | return IOCB_SUCCESS; |
| 9300 | } else |
| 9301 | return IOCB_BUSY; |
| 9302 | } |
| 9303 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9304 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9305 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9306 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9307 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9308 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9309 | /* |
| 9310 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9311 | * sglq is on the active list |
| 9312 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9313 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9314 | if (!sglq) |
| 9315 | return IOCB_ERROR; |
| 9316 | } |
| 9317 | |
| 9318 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9319 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9320 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9321 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9322 | return IOCB_ERROR; |
| 9323 | } |
| 9324 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9325 | if (lpfc_sli4_iocb2wqe(phba, piocb, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9326 | return IOCB_ERROR; |
| 9327 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9328 | if (lpfc_sli4_wq_put(wq, wqe)) |
| 9329 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9330 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9331 | |
| 9332 | return 0; |
| 9333 | } |
| 9334 | |
| 9335 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9336 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9337 | * |
| 9338 | * This routine wraps the actual lockless version for issusing IOCB function |
| 9339 | * pointer from the lpfc_hba struct. |
| 9340 | * |
| 9341 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9342 | * IOCB_ERROR - Error |
| 9343 | * IOCB_SUCCESS - Success |
| 9344 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9345 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9346 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9347 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 9348 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9349 | { |
| 9350 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9351 | } |
| 9352 | |
| 9353 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9354 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9355 | * @phba: The hba struct for which this call is being executed. |
| 9356 | * @dev_grp: The HBA PCI-Device group number. |
| 9357 | * |
| 9358 | * This routine sets up the SLI interface API function jump table in @phba |
| 9359 | * struct. |
| 9360 | * Returns: 0 - success, -ENODEV - failure. |
| 9361 | **/ |
| 9362 | int |
| 9363 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9364 | { |
| 9365 | |
| 9366 | switch (dev_grp) { |
| 9367 | case LPFC_PCI_DEV_LP: |
| 9368 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 9369 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 9370 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9371 | case LPFC_PCI_DEV_OC: |
| 9372 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 9373 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 9374 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9375 | default: |
| 9376 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9377 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 9378 | dev_grp); |
| 9379 | return -ENODEV; |
| 9380 | break; |
| 9381 | } |
| 9382 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 9383 | return 0; |
| 9384 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9385 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9386 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9387 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9388 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9389 | * @piocb: Pointer to command iocb. |
| 9390 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9391 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 9392 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9393 | * Since ABORTS must go on the same WQ of the command they are |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9394 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9395 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9396 | struct lpfc_sli_ring * |
| 9397 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9398 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9399 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9400 | if (!(phba->cfg_fof) || |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9401 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9402 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9403 | return NULL; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9404 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9405 | * for abort iocb hba_wqidx should already |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9406 | * be setup based on what work queue we used. |
| 9407 | */ |
Dick Kennedy | 55d8b65 | 2017-09-29 17:34:35 -0700 | [diff] [blame] | 9408 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9409 | piocb->hba_wqidx = |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9410 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
| 9411 | piocb->context1); |
Dick Kennedy | 55d8b65 | 2017-09-29 17:34:35 -0700 | [diff] [blame] | 9412 | piocb->hba_wqidx = piocb->hba_wqidx % |
| 9413 | phba->cfg_fcp_io_channel; |
| 9414 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9415 | return phba->sli4_hba.fcp_wq[piocb->hba_wqidx]->pring; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9416 | } else { |
| 9417 | if (unlikely(!phba->sli4_hba.oas_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9418 | return NULL; |
| 9419 | piocb->hba_wqidx = 0; |
| 9420 | return phba->sli4_hba.oas_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9421 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9422 | } else { |
| 9423 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 9424 | return NULL; |
| 9425 | piocb->hba_wqidx = 0; |
| 9426 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9427 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9428 | } |
| 9429 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9430 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9431 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9432 | * @phba: Pointer to HBA context object. |
| 9433 | * @pring: Pointer to driver SLI ring object. |
| 9434 | * @piocb: Pointer to command iocb. |
| 9435 | * @flag: Flag indicating if this command can be put into txq. |
| 9436 | * |
| 9437 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 9438 | * function. This function gets the hbalock and calls |
| 9439 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 9440 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 9441 | * functions which do not hold hbalock. |
| 9442 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9443 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9444 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9445 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9446 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9447 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9448 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9449 | struct lpfc_queue *fpeq; |
| 9450 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9451 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9452 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9453 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9454 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9455 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 9456 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9457 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9458 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9459 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9460 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9461 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9462 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9463 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9464 | idx = piocb->hba_wqidx; |
| 9465 | hba_eq_hdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9466 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9467 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9468 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9469 | /* Get associated EQ with this index */ |
| 9470 | fpeq = phba->sli4_hba.hba_eq[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9471 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9472 | /* Turn off interrupts from this EQ */ |
| 9473 | lpfc_sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9474 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9475 | /* |
| 9476 | * Process all the events on FCP EQ |
| 9477 | */ |
| 9478 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 9479 | lpfc_sli4_hba_handle_eqe(phba, |
| 9480 | eqe, idx); |
| 9481 | fpeq->EQ_processed++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9482 | } |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9483 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9484 | /* Always clear and re-arm the EQ */ |
| 9485 | lpfc_sli4_eq_release(fpeq, |
| 9486 | LPFC_QUEUE_REARM); |
| 9487 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9488 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9489 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9490 | } else { |
| 9491 | /* For now, SLI2/3 will still use hbalock */ |
| 9492 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9493 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9494 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9495 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9496 | return rc; |
| 9497 | } |
| 9498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9499 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9500 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9501 | * @phba: Pointer to HBA context object. |
| 9502 | * |
| 9503 | * This function is called while driver attaches with the |
| 9504 | * HBA to setup the extra ring. The extra ring is used |
| 9505 | * only when driver needs to support target mode functionality |
| 9506 | * or IP over FC functionalities. |
| 9507 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9508 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9509 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9510 | static int |
| 9511 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 9512 | { |
| 9513 | struct lpfc_sli *psli; |
| 9514 | struct lpfc_sli_ring *pring; |
| 9515 | |
| 9516 | psli = &phba->sli; |
| 9517 | |
| 9518 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9519 | |
| 9520 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9521 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9522 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9523 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9524 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9525 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9526 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9527 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9528 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9529 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9530 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9531 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9532 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9533 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9534 | |
| 9535 | /* Setup default profile for this ring */ |
| 9536 | pring->iotag_max = 4096; |
| 9537 | pring->num_mask = 1; |
| 9538 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9539 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 9540 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9541 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 9542 | return 0; |
| 9543 | } |
| 9544 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9545 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 9546 | * @phba: Pointer to HBA context object. |
| 9547 | * @iocbq: Pointer to iocb object. |
| 9548 | * |
| 9549 | * The async_event handler calls this routine when it receives |
| 9550 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 9551 | * this event when an Abort Sequence request to an rport fails |
| 9552 | * twice in succession. The abort could be originated by the |
| 9553 | * driver or by the port. The ABTS could have been for an ELS |
| 9554 | * or FCP IO. The port only generates this event when an ABTS |
| 9555 | * fails to complete after one retry. |
| 9556 | */ |
| 9557 | static void |
| 9558 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 9559 | struct lpfc_iocbq *iocbq) |
| 9560 | { |
| 9561 | struct lpfc_nodelist *ndlp = NULL; |
| 9562 | uint16_t rpi = 0, vpi = 0; |
| 9563 | struct lpfc_vport *vport = NULL; |
| 9564 | |
| 9565 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 9566 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 9567 | rpi = iocbq->iocb.ulpContext; |
| 9568 | |
| 9569 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9570 | "3092 Port generated ABTS async event " |
| 9571 | "on vpi %d rpi %d status 0x%x\n", |
| 9572 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 9573 | |
| 9574 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 9575 | if (!vport) |
| 9576 | goto err_exit; |
| 9577 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 9578 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 9579 | goto err_exit; |
| 9580 | |
| 9581 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 9582 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9583 | return; |
| 9584 | |
| 9585 | err_exit: |
| 9586 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9587 | "3095 Event Context not found, no " |
| 9588 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 9589 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 9590 | vpi, rpi); |
| 9591 | } |
| 9592 | |
| 9593 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 9594 | * @phba: pointer to HBA context object. |
| 9595 | * @ndlp: nodelist pointer for the impacted rport. |
| 9596 | * @axri: pointer to the wcqe containing the failed exchange. |
| 9597 | * |
| 9598 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 9599 | * port. The port generates this event when an abort exchange request to an |
| 9600 | * rport fails twice in succession with no reply. The abort could be originated |
| 9601 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 9602 | */ |
| 9603 | void |
| 9604 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 9605 | struct lpfc_nodelist *ndlp, |
| 9606 | struct sli4_wcqe_xri_aborted *axri) |
| 9607 | { |
| 9608 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9609 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9610 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9611 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9612 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9613 | "3115 Node Context not found, driver " |
| 9614 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9615 | return; |
| 9616 | } |
| 9617 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9618 | vport = ndlp->vport; |
| 9619 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9620 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9621 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 9622 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9623 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9624 | bf_get(lpfc_wcqe_xa_status, axri), |
| 9625 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9626 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9627 | /* |
| 9628 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 9629 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 9630 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 9631 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9632 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9633 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 9634 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9635 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9636 | } |
| 9637 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9639 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9640 | * @phba: Pointer to HBA context object. |
| 9641 | * @pring: Pointer to driver SLI ring object. |
| 9642 | * @iocbq: Pointer to iocb object. |
| 9643 | * |
| 9644 | * This function is called by the slow ring event handler |
| 9645 | * function when there is an ASYNC event iocb in the ring. |
| 9646 | * This function is called with no lock held. |
| 9647 | * Currently this function handles only temperature related |
| 9648 | * ASYNC events. The function decodes the temperature sensor |
| 9649 | * event message and posts events for the management applications. |
| 9650 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9651 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9652 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 9653 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 9654 | { |
| 9655 | IOCB_t *icmd; |
| 9656 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9657 | struct temp_event temp_event_data; |
| 9658 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9659 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9660 | |
| 9661 | icmd = &iocbq->iocb; |
| 9662 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9663 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9664 | switch (evt_code) { |
| 9665 | case ASYNC_TEMP_WARN: |
| 9666 | case ASYNC_TEMP_SAFE: |
| 9667 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 9668 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 9669 | if (evt_code == ASYNC_TEMP_WARN) { |
| 9670 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 9671 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9672 | "0347 Adapter is very hot, please take " |
| 9673 | "corrective action. temperature : %d Celsius\n", |
| 9674 | (uint32_t) icmd->ulpContext); |
| 9675 | } else { |
| 9676 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 9677 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9678 | "0340 Adapter temperature is OK now. " |
| 9679 | "temperature : %d Celsius\n", |
| 9680 | (uint32_t) icmd->ulpContext); |
| 9681 | } |
| 9682 | |
| 9683 | /* Send temperature change event to applications */ |
| 9684 | shost = lpfc_shost_from_vport(phba->pport); |
| 9685 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 9686 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 9687 | LPFC_NL_VENDOR_ID); |
| 9688 | break; |
| 9689 | case ASYNC_STATUS_CN: |
| 9690 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 9691 | break; |
| 9692 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9693 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9694 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9695 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 9696 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9697 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 9698 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 9699 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 9700 | "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] | 9701 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9702 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 9703 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 9704 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 9705 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 9706 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9707 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9708 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9709 | } |
| 9710 | |
| 9711 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9712 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9713 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9714 | * @phba: Pointer to HBA context object. |
| 9715 | * |
| 9716 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9717 | * number of iocbs per ring and iotags. This function is |
| 9718 | * called while driver attach to the HBA and before the |
| 9719 | * interrupts are enabled. So there is no need for locking. |
| 9720 | * |
| 9721 | * This function always returns 0. |
| 9722 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9723 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9724 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 9725 | { |
| 9726 | struct lpfc_sli_ring *pring; |
| 9727 | |
| 9728 | pring = phba->sli4_hba.els_wq->pring; |
| 9729 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 9730 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 9731 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9732 | pring->prt[0].type = FC_TYPE_ELS; |
| 9733 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 9734 | lpfc_els_unsol_event; |
| 9735 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 9736 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9737 | pring->prt[1].type = FC_TYPE_ELS; |
| 9738 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 9739 | lpfc_els_unsol_event; |
| 9740 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9741 | /* NameServer Inquiry */ |
| 9742 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 9743 | /* NameServer */ |
| 9744 | pring->prt[2].type = FC_TYPE_CT; |
| 9745 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 9746 | lpfc_ct_unsol_event; |
| 9747 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9748 | /* NameServer response */ |
| 9749 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 9750 | /* NameServer */ |
| 9751 | pring->prt[3].type = FC_TYPE_CT; |
| 9752 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 9753 | lpfc_ct_unsol_event; |
| 9754 | return 0; |
| 9755 | } |
| 9756 | |
| 9757 | /** |
| 9758 | * lpfc_sli_setup - SLI ring setup function |
| 9759 | * @phba: Pointer to HBA context object. |
| 9760 | * |
| 9761 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9762 | * number of iocbs per ring and iotags. This function is |
| 9763 | * called while driver attach to the HBA and before the |
| 9764 | * interrupts are enabled. So there is no need for locking. |
| 9765 | * |
| 9766 | * This function always returns 0. SLI3 only. |
| 9767 | **/ |
| 9768 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9769 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 9770 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9771 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9772 | struct lpfc_sli *psli = &phba->sli; |
| 9773 | struct lpfc_sli_ring *pring; |
| 9774 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9775 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9776 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9777 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9778 | psli->iocbq_lookup = NULL; |
| 9779 | psli->iocbq_lookup_len = 0; |
| 9780 | psli->last_iotag = 0; |
| 9781 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9782 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9783 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9784 | switch (i) { |
| 9785 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 9786 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9787 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 9788 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 9789 | pring->sli.sli3.numCiocb += |
| 9790 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9791 | pring->sli.sli3.numRiocb += |
| 9792 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9793 | pring->sli.sli3.numCiocb += |
| 9794 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9795 | pring->sli.sli3.numRiocb += |
| 9796 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 9797 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9798 | SLI3_IOCB_CMD_SIZE : |
| 9799 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9800 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9801 | SLI3_IOCB_RSP_SIZE : |
| 9802 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9803 | pring->iotag_ctr = 0; |
| 9804 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9805 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9806 | pring->fast_iotag = pring->iotag_max; |
| 9807 | pring->num_mask = 0; |
| 9808 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9809 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9810 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9811 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 9812 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 9813 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9814 | SLI3_IOCB_CMD_SIZE : |
| 9815 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9816 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9817 | SLI3_IOCB_RSP_SIZE : |
| 9818 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9819 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9820 | pring->num_mask = 0; |
| 9821 | break; |
| 9822 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 9823 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9824 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 9825 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 9826 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9827 | SLI3_IOCB_CMD_SIZE : |
| 9828 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9829 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9830 | SLI3_IOCB_RSP_SIZE : |
| 9831 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9832 | pring->fast_iotag = 0; |
| 9833 | pring->iotag_ctr = 0; |
| 9834 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9835 | pring->lpfc_sli_rcv_async_status = |
| 9836 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9837 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9838 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9839 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9840 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9841 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9842 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9843 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9844 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9845 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9846 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9847 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9848 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9849 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9850 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9851 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9852 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9853 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9854 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9855 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9856 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9857 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9858 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9859 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9860 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9861 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9862 | break; |
| 9863 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9864 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 9865 | pring->sli.sli3.sizeCiocb) + |
| 9866 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9867 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9868 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9869 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9870 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 9871 | "SLI2 SLIM Data: x%x x%lx\n", |
| 9872 | phba->brd_no, totiocbsize, |
| 9873 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9874 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9875 | if (phba->cfg_multi_ring_support == 2) |
| 9876 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9877 | |
| 9878 | return 0; |
| 9879 | } |
| 9880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9881 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9882 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9883 | * @phba: Pointer to HBA context object. |
| 9884 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9885 | * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9886 | * ring. This function also initializes ring indices of each ring. |
| 9887 | * This function is called during the initialization of the SLI |
| 9888 | * interface of an HBA. |
| 9889 | * This function is called with no lock held and always returns |
| 9890 | * 1. |
| 9891 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9892 | void |
| 9893 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 9894 | { |
| 9895 | struct lpfc_sli *psli; |
| 9896 | struct lpfc_sli_ring *pring; |
| 9897 | int i; |
| 9898 | |
| 9899 | psli = &phba->sli; |
| 9900 | spin_lock_irq(&phba->hbalock); |
| 9901 | INIT_LIST_HEAD(&psli->mboxq); |
| 9902 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 9903 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9904 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 9905 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
| 9906 | pring->flag = 0; |
| 9907 | pring->ringno = LPFC_FCP_RING; |
| 9908 | INIT_LIST_HEAD(&pring->txq); |
| 9909 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9910 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9911 | spin_lock_init(&pring->ring_lock); |
| 9912 | } |
| 9913 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 9914 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 9915 | pring->flag = 0; |
| 9916 | pring->ringno = LPFC_FCP_RING; |
| 9917 | INIT_LIST_HEAD(&pring->txq); |
| 9918 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9919 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9920 | spin_lock_init(&pring->ring_lock); |
| 9921 | } |
| 9922 | pring = phba->sli4_hba.els_wq->pring; |
| 9923 | pring->flag = 0; |
| 9924 | pring->ringno = LPFC_ELS_RING; |
| 9925 | INIT_LIST_HEAD(&pring->txq); |
| 9926 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9927 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9928 | spin_lock_init(&pring->ring_lock); |
| 9929 | |
| 9930 | if (phba->cfg_nvme_io_channel) { |
| 9931 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 9932 | pring->flag = 0; |
| 9933 | pring->ringno = LPFC_ELS_RING; |
| 9934 | INIT_LIST_HEAD(&pring->txq); |
| 9935 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9936 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9937 | spin_lock_init(&pring->ring_lock); |
| 9938 | } |
| 9939 | |
| 9940 | if (phba->cfg_fof) { |
| 9941 | pring = phba->sli4_hba.oas_wq->pring; |
| 9942 | pring->flag = 0; |
| 9943 | pring->ringno = LPFC_FCP_RING; |
| 9944 | INIT_LIST_HEAD(&pring->txq); |
| 9945 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9946 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9947 | spin_lock_init(&pring->ring_lock); |
| 9948 | } |
| 9949 | |
| 9950 | spin_unlock_irq(&phba->hbalock); |
| 9951 | } |
| 9952 | |
| 9953 | /** |
| 9954 | * lpfc_sli_queue_init - Queue initialization function |
| 9955 | * @phba: Pointer to HBA context object. |
| 9956 | * |
| 9957 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 9958 | * ring. This function also initializes ring indices of each ring. |
| 9959 | * This function is called during the initialization of the SLI |
| 9960 | * interface of an HBA. |
| 9961 | * This function is called with no lock held and always returns |
| 9962 | * 1. |
| 9963 | **/ |
| 9964 | void |
| 9965 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9966 | { |
| 9967 | struct lpfc_sli *psli; |
| 9968 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9969 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9970 | |
| 9971 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9972 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9973 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9974 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9975 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9976 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9977 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9978 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9979 | pring->sli.sli3.next_cmdidx = 0; |
| 9980 | pring->sli.sli3.local_getidx = 0; |
| 9981 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9982 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 9983 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9984 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9985 | pring->flag = 0; |
| 9986 | INIT_LIST_HEAD(&pring->txq); |
| 9987 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9988 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9989 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9990 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9991 | } |
| 9992 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9993 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9994 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 9995 | * @phba: Pointer to HBA context object. |
| 9996 | * |
| 9997 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 9998 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 9999 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10000 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10001 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10002 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10003 | * pending mailbox command queue from the various clients must be stopped; |
| 10004 | * either the HBA is in a state that it will never works on the outstanding |
| 10005 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10006 | * mailbox command has been completed. |
| 10007 | **/ |
| 10008 | static void |
| 10009 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10010 | { |
| 10011 | LIST_HEAD(completions); |
| 10012 | struct lpfc_sli *psli = &phba->sli; |
| 10013 | LPFC_MBOXQ_t *pmb; |
| 10014 | unsigned long iflag; |
| 10015 | |
| 10016 | /* Flush all the mailbox commands in the mbox system */ |
| 10017 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 10018 | /* The pending mailbox command queue */ |
| 10019 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10020 | /* The outstanding active mailbox command */ |
| 10021 | if (psli->mbox_active) { |
| 10022 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10023 | psli->mbox_active = NULL; |
| 10024 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10025 | } |
| 10026 | /* The completed mailbox command queue */ |
| 10027 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10028 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10029 | |
| 10030 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10031 | while (!list_empty(&completions)) { |
| 10032 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10033 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10034 | if (pmb->mbox_cmpl) |
| 10035 | pmb->mbox_cmpl(phba, pmb); |
| 10036 | } |
| 10037 | } |
| 10038 | |
| 10039 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10040 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10041 | * @vport: Pointer to virtual port object. |
| 10042 | * |
| 10043 | * lpfc_sli_host_down is called to clean up the resources |
| 10044 | * associated with a vport before destroying virtual |
| 10045 | * port data structures. |
| 10046 | * This function does following operations: |
| 10047 | * - Free discovery resources associated with this virtual |
| 10048 | * port. |
| 10049 | * - Free iocbs associated with this virtual port in |
| 10050 | * the txq. |
| 10051 | * - Send abort for all iocb commands associated with this |
| 10052 | * vport in txcmplq. |
| 10053 | * |
| 10054 | * This function is called with no lock held and always returns 1. |
| 10055 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10056 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10057 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10058 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10059 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10060 | struct lpfc_hba *phba = vport->phba; |
| 10061 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10062 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10063 | struct lpfc_sli_ring *pring; |
| 10064 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10065 | int i; |
| 10066 | unsigned long flags = 0; |
| 10067 | uint16_t prev_pring_flag; |
| 10068 | |
| 10069 | lpfc_cleanup_discovery_resources(vport); |
| 10070 | |
| 10071 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10072 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10073 | /* |
| 10074 | * Error everything on the txq since these iocbs |
| 10075 | * have not been given to the FW yet. |
| 10076 | * Also issue ABTS for everything on the txcmplq |
| 10077 | */ |
| 10078 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10079 | for (i = 0; i < psli->num_rings; i++) { |
| 10080 | pring = &psli->sli3_ring[i]; |
| 10081 | prev_pring_flag = pring->flag; |
| 10082 | /* Only slow rings */ |
| 10083 | if (pring->ringno == LPFC_ELS_RING) { |
| 10084 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10085 | /* Set the lpfc data pending flag */ |
| 10086 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10087 | } |
| 10088 | list_for_each_entry_safe(iocb, next_iocb, |
| 10089 | &pring->txq, list) { |
| 10090 | if (iocb->vport != vport) |
| 10091 | continue; |
| 10092 | list_move_tail(&iocb->list, &completions); |
| 10093 | } |
| 10094 | list_for_each_entry_safe(iocb, next_iocb, |
| 10095 | &pring->txcmplq, list) { |
| 10096 | if (iocb->vport != vport) |
| 10097 | continue; |
| 10098 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10099 | } |
| 10100 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10101 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10102 | } else { |
| 10103 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10104 | pring = qp->pring; |
| 10105 | if (!pring) |
| 10106 | continue; |
| 10107 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10108 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10109 | /* Set the lpfc data pending flag */ |
| 10110 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10111 | } |
| 10112 | prev_pring_flag = pring->flag; |
| 10113 | spin_lock_irq(&pring->ring_lock); |
| 10114 | list_for_each_entry_safe(iocb, next_iocb, |
| 10115 | &pring->txq, list) { |
| 10116 | if (iocb->vport != vport) |
| 10117 | continue; |
| 10118 | list_move_tail(&iocb->list, &completions); |
| 10119 | } |
| 10120 | spin_unlock_irq(&pring->ring_lock); |
| 10121 | list_for_each_entry_safe(iocb, next_iocb, |
| 10122 | &pring->txcmplq, list) { |
| 10123 | if (iocb->vport != vport) |
| 10124 | continue; |
| 10125 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10126 | } |
| 10127 | pring->flag = prev_pring_flag; |
| 10128 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10129 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10130 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10131 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10132 | /* Cancel all the IOCBs from the completions list */ |
| 10133 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10134 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10135 | return 1; |
| 10136 | } |
| 10137 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10138 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10139 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10140 | * @phba: Pointer to HBA context object. |
| 10141 | * |
| 10142 | * This function cleans up all iocb, buffers, mailbox commands |
| 10143 | * while shutting down the HBA. This function is called with no |
| 10144 | * lock held and always returns 1. |
| 10145 | * This function does the following to cleanup driver resources: |
| 10146 | * - Free discovery resources for each virtual port |
| 10147 | * - Cleanup any pending fabric iocbs |
| 10148 | * - Iterate through the iocb txq and free each entry |
| 10149 | * in the list. |
| 10150 | * - Free up any buffer posted to the HBA |
| 10151 | * - Free mailbox commands in the mailbox queue. |
| 10152 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10153 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10154 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10155 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10156 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10157 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10158 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10159 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10160 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10161 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10162 | int i; |
| 10163 | |
| 10164 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10165 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10166 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10167 | lpfc_hba_down_prep(phba); |
| 10168 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10169 | lpfc_fabric_abort_hba(phba); |
| 10170 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10171 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10172 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10173 | /* |
| 10174 | * Error everything on the txq since these iocbs |
| 10175 | * have not been given to the FW yet. |
| 10176 | */ |
| 10177 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10178 | for (i = 0; i < psli->num_rings; i++) { |
| 10179 | pring = &psli->sli3_ring[i]; |
| 10180 | /* Only slow rings */ |
| 10181 | if (pring->ringno == LPFC_ELS_RING) { |
| 10182 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10183 | /* Set the lpfc data pending flag */ |
| 10184 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10185 | } |
| 10186 | list_splice_init(&pring->txq, &completions); |
| 10187 | } |
| 10188 | } else { |
| 10189 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10190 | pring = qp->pring; |
| 10191 | if (!pring) |
| 10192 | continue; |
| 10193 | spin_lock_irq(&pring->ring_lock); |
| 10194 | list_splice_init(&pring->txq, &completions); |
| 10195 | spin_unlock_irq(&pring->ring_lock); |
| 10196 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10197 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10198 | /* Set the lpfc data pending flag */ |
| 10199 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10200 | } |
| 10201 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10202 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10203 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10204 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10205 | /* Cancel all the IOCBs from the completions list */ |
| 10206 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10207 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10208 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10209 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10210 | list_splice_init(&phba->elsbuf, &completions); |
| 10211 | phba->elsbuf_cnt = 0; |
| 10212 | phba->elsbuf_prev_cnt = 0; |
| 10213 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10214 | |
| 10215 | while (!list_empty(&completions)) { |
| 10216 | list_remove_head(&completions, buf_ptr, |
| 10217 | struct lpfc_dmabuf, list); |
| 10218 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10219 | kfree(buf_ptr); |
| 10220 | } |
| 10221 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10222 | /* Return any active mbox cmds */ |
| 10223 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10224 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10225 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10226 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10227 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10228 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10229 | return 1; |
| 10230 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10231 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10232 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10233 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10234 | * @srcp: Source memory pointer. |
| 10235 | * @destp: Destination memory pointer. |
| 10236 | * @cnt: Number of words required to be copied. |
| 10237 | * |
| 10238 | * This function is used for copying data between driver memory |
| 10239 | * and the SLI memory. This function also changes the endianness |
| 10240 | * of each word if native endianness is different from SLI |
| 10241 | * endianness. This function can be called with or without |
| 10242 | * lock. |
| 10243 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10244 | void |
| 10245 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10246 | { |
| 10247 | uint32_t *src = srcp; |
| 10248 | uint32_t *dest = destp; |
| 10249 | uint32_t ldata; |
| 10250 | int i; |
| 10251 | |
| 10252 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10253 | ldata = *src; |
| 10254 | ldata = le32_to_cpu(ldata); |
| 10255 | *dest = ldata; |
| 10256 | src++; |
| 10257 | dest++; |
| 10258 | } |
| 10259 | } |
| 10260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10261 | |
| 10262 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10263 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10264 | * @srcp: Source memory pointer. |
| 10265 | * @destp: Destination memory pointer. |
| 10266 | * @cnt: Number of words required to be copied. |
| 10267 | * |
| 10268 | * This function is used for copying data between a data structure |
| 10269 | * with big endian representation to local endianness. |
| 10270 | * This function can be called with or without lock. |
| 10271 | **/ |
| 10272 | void |
| 10273 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10274 | { |
| 10275 | uint32_t *src = srcp; |
| 10276 | uint32_t *dest = destp; |
| 10277 | uint32_t ldata; |
| 10278 | int i; |
| 10279 | |
| 10280 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10281 | ldata = *src; |
| 10282 | ldata = be32_to_cpu(ldata); |
| 10283 | *dest = ldata; |
| 10284 | src++; |
| 10285 | dest++; |
| 10286 | } |
| 10287 | } |
| 10288 | |
| 10289 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10290 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10291 | * @phba: Pointer to HBA context object. |
| 10292 | * @pring: Pointer to driver SLI ring object. |
| 10293 | * @mp: Pointer to driver buffer object. |
| 10294 | * |
| 10295 | * This function is called with no lock held. |
| 10296 | * It always return zero after adding the buffer to the postbufq |
| 10297 | * buffer list. |
| 10298 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10299 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10300 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10301 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10302 | { |
| 10303 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10304 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10305 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10306 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10307 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10308 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10309 | return 0; |
| 10310 | } |
| 10311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10313 | * 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] | 10314 | * @phba: Pointer to HBA context object. |
| 10315 | * |
| 10316 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10317 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10318 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10319 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10320 | * The function returns the allocated tag. The function is called with |
| 10321 | * no locks held. |
| 10322 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10323 | uint32_t |
| 10324 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10325 | { |
| 10326 | spin_lock_irq(&phba->hbalock); |
| 10327 | phba->buffer_tag_count++; |
| 10328 | /* |
| 10329 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10330 | * a tag assigned by HBQ. |
| 10331 | */ |
| 10332 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10333 | spin_unlock_irq(&phba->hbalock); |
| 10334 | return phba->buffer_tag_count; |
| 10335 | } |
| 10336 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10337 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10338 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10339 | * @phba: Pointer to HBA context object. |
| 10340 | * @pring: Pointer to driver SLI ring object. |
| 10341 | * @tag: Buffer tag. |
| 10342 | * |
| 10343 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10344 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10345 | * iocb is posted to the response ring with the tag of the buffer. |
| 10346 | * This function searches the pring->postbufq list using the tag |
| 10347 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10348 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10349 | * buffer is returned to the caller else NULL is returned. |
| 10350 | * This function is called with no lock held. |
| 10351 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10352 | struct lpfc_dmabuf * |
| 10353 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10354 | uint32_t tag) |
| 10355 | { |
| 10356 | struct lpfc_dmabuf *mp, *next_mp; |
| 10357 | struct list_head *slp = &pring->postbufq; |
| 10358 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10359 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10360 | spin_lock_irq(&phba->hbalock); |
| 10361 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10362 | if (mp->buffer_tag == tag) { |
| 10363 | list_del_init(&mp->list); |
| 10364 | pring->postbufq_cnt--; |
| 10365 | spin_unlock_irq(&phba->hbalock); |
| 10366 | return mp; |
| 10367 | } |
| 10368 | } |
| 10369 | |
| 10370 | spin_unlock_irq(&phba->hbalock); |
| 10371 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10372 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10373 | "ring %d Data x%lx x%p x%p x%x\n", |
| 10374 | pring->ringno, (unsigned long) tag, |
| 10375 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10376 | |
| 10377 | return NULL; |
| 10378 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10379 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10380 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10381 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10382 | * @phba: Pointer to HBA context object. |
| 10383 | * @pring: Pointer to driver SLI ring object. |
| 10384 | * @phys: DMA address of the buffer. |
| 10385 | * |
| 10386 | * This function searches the buffer list using the dma_address |
| 10387 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 10388 | * corresponding to the dma_address. The function returns the |
| 10389 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 10390 | * This function is called by the ct and els unsolicited event |
| 10391 | * handlers to get the buffer associated with the unsolicited |
| 10392 | * event. |
| 10393 | * |
| 10394 | * This function is called with no lock held. |
| 10395 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10396 | struct lpfc_dmabuf * |
| 10397 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10398 | dma_addr_t phys) |
| 10399 | { |
| 10400 | struct lpfc_dmabuf *mp, *next_mp; |
| 10401 | struct list_head *slp = &pring->postbufq; |
| 10402 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10403 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10404 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10405 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10406 | if (mp->phys == phys) { |
| 10407 | list_del_init(&mp->list); |
| 10408 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10409 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10410 | return mp; |
| 10411 | } |
| 10412 | } |
| 10413 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10414 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10415 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10416 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10417 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10418 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10419 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10420 | return NULL; |
| 10421 | } |
| 10422 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10424 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10425 | * @phba: Pointer to HBA context object. |
| 10426 | * @cmdiocb: Pointer to driver command iocb object. |
| 10427 | * @rspiocb: Pointer to driver response iocb object. |
| 10428 | * |
| 10429 | * This function is the completion handler for the abort iocbs for |
| 10430 | * ELS commands. This function is called from the ELS ring event |
| 10431 | * handler with no lock held. This function frees memory resources |
| 10432 | * associated with the abort iocb. |
| 10433 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10434 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10435 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10436 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10437 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10438 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10439 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10440 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10441 | |
| 10442 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10443 | |
| 10444 | /* |
| 10445 | * Assume that the port already completed and returned, or |
| 10446 | * will return the iocb. Just Log the message. |
| 10447 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10448 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 10449 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 10450 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10451 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10452 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 10453 | if (abort_iotag != 0 && |
| 10454 | abort_iotag <= phba->sli.last_iotag) |
| 10455 | abort_iocb = |
| 10456 | phba->sli.iocbq_lookup[abort_iotag]; |
| 10457 | } else |
| 10458 | /* For sli4 the abort_tag is the XRI, |
| 10459 | * so the abort routine puts the iotag of the iocb |
| 10460 | * being aborted in the context field of the abort |
| 10461 | * IOCB. |
| 10462 | */ |
| 10463 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10464 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10465 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 10466 | "0327 Cannot abort els iocb %p " |
| 10467 | "with tag %x context %x, abort status %x, " |
| 10468 | "abort code %x\n", |
| 10469 | abort_iocb, abort_iotag, abort_context, |
| 10470 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10471 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10472 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10473 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10474 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10475 | return; |
| 10476 | } |
| 10477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10479 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10480 | * @phba: Pointer to HBA context object. |
| 10481 | * @cmdiocb: Pointer to driver command iocb object. |
| 10482 | * @rspiocb: Pointer to driver response iocb object. |
| 10483 | * |
| 10484 | * The function is called from SLI ring event handler with no |
| 10485 | * lock held. This function is the completion handler for ELS commands |
| 10486 | * which are aborted. The function frees memory resources used for |
| 10487 | * the aborted ELS commands. |
| 10488 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10489 | static void |
| 10490 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10491 | struct lpfc_iocbq *rspiocb) |
| 10492 | { |
| 10493 | IOCB_t *irsp = &rspiocb->iocb; |
| 10494 | |
| 10495 | /* ELS cmd tag <ulpIoTag> completes */ |
| 10496 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10497 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10498 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10499 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10500 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10501 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 10502 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 10503 | else |
| 10504 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10505 | return; |
| 10506 | } |
| 10507 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10508 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10509 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10510 | * @phba: Pointer to HBA context object. |
| 10511 | * @pring: Pointer to driver SLI ring object. |
| 10512 | * @cmdiocb: Pointer to driver command iocb object. |
| 10513 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10514 | * This function issues an abort iocb for the provided command iocb down to |
| 10515 | * the port. Other than the case the outstanding command iocb is an abort |
| 10516 | * request, this function issues abort out unconditionally. This function is |
| 10517 | * called with hbalock held. The function returns 0 when it fails due to |
| 10518 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10519 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10520 | static int |
| 10521 | 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] | 10522 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10523 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10524 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10525 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10526 | IOCB_t *icmd = NULL; |
| 10527 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10528 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10529 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10530 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10531 | lockdep_assert_held(&phba->hbalock); |
| 10532 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10533 | /* |
| 10534 | * There are certain command types we don't want to abort. And we |
| 10535 | * don't want to abort commands that are already in the process of |
| 10536 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10537 | */ |
| 10538 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10539 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10540 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10541 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10542 | return 0; |
| 10543 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10544 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10545 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10546 | if (abtsiocbp == NULL) |
| 10547 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10548 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10549 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10550 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10551 | */ |
| 10552 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10553 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10554 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10555 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10556 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10557 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10558 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10559 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 10560 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10561 | else |
| 10562 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10563 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10564 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10565 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10566 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10567 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10568 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 10569 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10570 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 10571 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10572 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10573 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10574 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 10575 | else |
| 10576 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 10577 | |
| 10578 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 10579 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 10580 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10581 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 10582 | "0339 Abort xri x%x, original iotag x%x, " |
| 10583 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10584 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10585 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10586 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10587 | |
| 10588 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10589 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 10590 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10591 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10592 | /* Note: both hbalock and ring_lock need to be set here */ |
| 10593 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10594 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10595 | abtsiocbp, 0); |
| 10596 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 10597 | } else { |
| 10598 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10599 | abtsiocbp, 0); |
| 10600 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10601 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10602 | if (retval) |
| 10603 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10604 | |
| 10605 | /* |
| 10606 | * Caller to this routine should check for IOCB_ERROR |
| 10607 | * and handle it properly. This routine no longer removes |
| 10608 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 10609 | */ |
| 10610 | return retval; |
| 10611 | } |
| 10612 | |
| 10613 | /** |
| 10614 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 10615 | * @phba: Pointer to HBA context object. |
| 10616 | * @pring: Pointer to driver SLI ring object. |
| 10617 | * @cmdiocb: Pointer to driver command iocb object. |
| 10618 | * |
| 10619 | * This function issues an abort iocb for the provided command iocb. In case |
| 10620 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 10621 | * ring. Instead, the callback function shall be changed to those commands |
| 10622 | * so that nothing happens when them finishes. This function is called with |
| 10623 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 10624 | * request. |
| 10625 | **/ |
| 10626 | int |
| 10627 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10628 | struct lpfc_iocbq *cmdiocb) |
| 10629 | { |
| 10630 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10631 | int retval = IOCB_ERROR; |
| 10632 | IOCB_t *icmd = NULL; |
| 10633 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10634 | lockdep_assert_held(&phba->hbalock); |
| 10635 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10636 | /* |
| 10637 | * There are certain command types we don't want to abort. And we |
| 10638 | * don't want to abort commands that are already in the process of |
| 10639 | * being aborted. |
| 10640 | */ |
| 10641 | icmd = &cmdiocb->iocb; |
| 10642 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 10643 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10644 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10645 | return 0; |
| 10646 | |
Dick Kennedy | 27b1313 | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10647 | if (!pring) { |
| 10648 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10649 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10650 | else |
| 10651 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10652 | goto abort_iotag_exit; |
| 10653 | } |
| 10654 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10655 | /* |
| 10656 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 10657 | * the callback so that nothing happens when it finishes. |
| 10658 | */ |
| 10659 | if ((vport->load_flag & FC_UNLOADING) && |
| 10660 | (pring->ringno == LPFC_ELS_RING)) { |
| 10661 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10662 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10663 | else |
| 10664 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10665 | goto abort_iotag_exit; |
| 10666 | } |
| 10667 | |
| 10668 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 10669 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 10670 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10671 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10672 | /* |
| 10673 | * Caller to this routine should check for IOCB_ERROR |
| 10674 | * and handle it properly. This routine no longer removes |
| 10675 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10676 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10677 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10678 | } |
| 10679 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10680 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10681 | * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb |
| 10682 | * @phba: Pointer to HBA context object. |
| 10683 | * @pring: Pointer to driver SLI ring object. |
| 10684 | * @cmdiocb: Pointer to driver command iocb object. |
| 10685 | * |
| 10686 | * This function issues an abort iocb for the provided command iocb down to |
| 10687 | * the port. Other than the case the outstanding command iocb is an abort |
| 10688 | * request, this function issues abort out unconditionally. This function is |
| 10689 | * called with hbalock held. The function returns 0 when it fails due to |
| 10690 | * memory allocation failure or when the command iocb is an abort request. |
| 10691 | **/ |
| 10692 | static int |
| 10693 | lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10694 | struct lpfc_iocbq *cmdiocb) |
| 10695 | { |
| 10696 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10697 | struct lpfc_iocbq *abtsiocbp; |
| 10698 | union lpfc_wqe *abts_wqe; |
| 10699 | int retval; |
| 10700 | |
| 10701 | /* |
| 10702 | * There are certain command types we don't want to abort. And we |
| 10703 | * don't want to abort commands that are already in the process of |
| 10704 | * being aborted. |
| 10705 | */ |
| 10706 | if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 10707 | cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
| 10708 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10709 | return 0; |
| 10710 | |
| 10711 | /* issue ABTS for this io based on iotag */ |
| 10712 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| 10713 | if (abtsiocbp == NULL) |
| 10714 | return 0; |
| 10715 | |
| 10716 | /* This signals the response to set the correct status |
| 10717 | * before calling the completion handler |
| 10718 | */ |
| 10719 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10720 | |
| 10721 | /* Complete prepping the abort wqe and issue to the FW. */ |
| 10722 | abts_wqe = &abtsiocbp->wqe; |
| 10723 | bf_set(abort_cmd_ia, &abts_wqe->abort_cmd, 0); |
| 10724 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); |
| 10725 | |
| 10726 | /* Explicitly set reserved fields to zero.*/ |
| 10727 | abts_wqe->abort_cmd.rsrvd4 = 0; |
| 10728 | abts_wqe->abort_cmd.rsrvd5 = 0; |
| 10729 | |
| 10730 | /* WQE Common - word 6. Context is XRI tag. Set 0. */ |
| 10731 | bf_set(wqe_xri_tag, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10732 | bf_set(wqe_ctxt_tag, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10733 | |
| 10734 | /* word 7 */ |
| 10735 | bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10736 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 10737 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, |
| 10738 | cmdiocb->iocb.ulpClass); |
| 10739 | |
| 10740 | /* word 8 - tell the FW to abort the IO associated with this |
| 10741 | * outstanding exchange ID. |
| 10742 | */ |
| 10743 | abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag; |
| 10744 | |
| 10745 | /* word 9 - this is the iotag for the abts_wqe completion. */ |
| 10746 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, |
| 10747 | abtsiocbp->iotag); |
| 10748 | |
| 10749 | /* word 10 */ |
| 10750 | bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, cmdiocb->hba_wqidx); |
| 10751 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); |
| 10752 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 10753 | |
| 10754 | /* word 11 */ |
| 10755 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 10756 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); |
| 10757 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 10758 | |
| 10759 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10760 | abtsiocbp->iocb_flag |= LPFC_IO_NVME; |
| 10761 | abtsiocbp->vport = vport; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 10762 | abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10763 | retval = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abtsiocbp); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 10764 | if (retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10765 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 10766 | "6147 Failed abts issue_wqe with status x%x " |
| 10767 | "for oxid x%x\n", |
| 10768 | retval, cmdiocb->sli4_xritag); |
| 10769 | lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 10770 | return retval; |
| 10771 | } |
| 10772 | |
| 10773 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 10774 | "6148 Drv Abort NVME Request Issued for " |
| 10775 | "ox_id x%x on reqtag x%x\n", |
| 10776 | cmdiocb->sli4_xritag, |
| 10777 | abtsiocbp->iotag); |
| 10778 | |
| 10779 | return retval; |
| 10780 | } |
| 10781 | |
| 10782 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10783 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 10784 | * @phba: pointer to lpfc HBA data structure. |
| 10785 | * |
| 10786 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 10787 | **/ |
| 10788 | void |
| 10789 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 10790 | { |
| 10791 | struct lpfc_sli *psli = &phba->sli; |
| 10792 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10793 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10794 | int i; |
| 10795 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10796 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10797 | for (i = 0; i < psli->num_rings; i++) { |
| 10798 | pring = &psli->sli3_ring[i]; |
| 10799 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 10800 | } |
| 10801 | return; |
| 10802 | } |
| 10803 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10804 | pring = qp->pring; |
| 10805 | if (!pring) |
| 10806 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10807 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10808 | } |
| 10809 | } |
| 10810 | |
| 10811 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10812 | * 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] | 10813 | * @iocbq: Pointer to driver iocb object. |
| 10814 | * @vport: Pointer to driver virtual port object. |
| 10815 | * @tgt_id: SCSI ID of the target. |
| 10816 | * @lun_id: LUN ID of the scsi device. |
| 10817 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 10818 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10819 | * 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] | 10820 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 10821 | * 0 if the filtering criteria is met for the given iocb and will return |
| 10822 | * 1 if the filtering criteria is not met. |
| 10823 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 10824 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 10825 | * lun_id parameter. |
| 10826 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 10827 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 10828 | * parameters. |
| 10829 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 10830 | * given iocb is for the SCSI host associated with the given vport. |
| 10831 | * This function is called with no locks held. |
| 10832 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10833 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10834 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 10835 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10836 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10837 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10838 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10839 | int rc = 1; |
| 10840 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10841 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 10842 | return rc; |
| 10843 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10844 | if (iocbq->vport != vport) |
| 10845 | return rc; |
| 10846 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10847 | 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] | 10848 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10849 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10850 | return rc; |
| 10851 | |
| 10852 | switch (ctx_cmd) { |
| 10853 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10854 | if ((lpfc_cmd->rdata->pnode) && |
| 10855 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 10856 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10857 | rc = 0; |
| 10858 | break; |
| 10859 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10860 | if ((lpfc_cmd->rdata->pnode) && |
| 10861 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10862 | rc = 0; |
| 10863 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10864 | case LPFC_CTX_HOST: |
| 10865 | rc = 0; |
| 10866 | break; |
| 10867 | default: |
| 10868 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 10869 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10870 | break; |
| 10871 | } |
| 10872 | |
| 10873 | return rc; |
| 10874 | } |
| 10875 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10876 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10877 | * 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] | 10878 | * @vport: Pointer to virtual port. |
| 10879 | * @tgt_id: SCSI ID of the target. |
| 10880 | * @lun_id: LUN ID of the scsi device. |
| 10881 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10882 | * |
| 10883 | * This function returns number of FCP commands pending for the vport. |
| 10884 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 10885 | * commands pending on the vport associated with SCSI device specified |
| 10886 | * by tgt_id and lun_id parameters. |
| 10887 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 10888 | * commands pending on the vport associated with SCSI target specified |
| 10889 | * by tgt_id parameter. |
| 10890 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 10891 | * commands pending on the vport. |
| 10892 | * This function returns the number of iocbs which satisfy the filter. |
| 10893 | * This function is called without any lock held. |
| 10894 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10895 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10896 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 10897 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10898 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10899 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10900 | struct lpfc_iocbq *iocbq; |
| 10901 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10902 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10903 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10904 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 10905 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10906 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10907 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 10908 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10909 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10910 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10911 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10912 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10913 | return sum; |
| 10914 | } |
| 10915 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10917 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10918 | * @phba: Pointer to HBA context object |
| 10919 | * @cmdiocb: Pointer to command iocb object. |
| 10920 | * @rspiocb: Pointer to response iocb object. |
| 10921 | * |
| 10922 | * This function is called when an aborted FCP iocb completes. This |
| 10923 | * function is called by the ring event handler with no lock held. |
| 10924 | * This function frees the iocb. |
| 10925 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10926 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10927 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10928 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10929 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10930 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 10931 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10932 | "original iotag x%x, abort cmd iotag x%x " |
| 10933 | "status 0x%x, reason 0x%x\n", |
| 10934 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 10935 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 10936 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 10937 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10938 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10939 | return; |
| 10940 | } |
| 10941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10942 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10943 | * 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] | 10944 | * @vport: Pointer to virtual port. |
| 10945 | * @pring: Pointer to driver SLI ring object. |
| 10946 | * @tgt_id: SCSI ID of the target. |
| 10947 | * @lun_id: LUN ID of the scsi device. |
| 10948 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10949 | * |
| 10950 | * This function sends an abort command for every SCSI command |
| 10951 | * associated with the given virtual port pending on the ring |
| 10952 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10953 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10954 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10955 | * parameters |
| 10956 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10957 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10958 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10959 | * FCP iocbs associated with virtual port. |
| 10960 | * This function returns number of iocbs it failed to abort. |
| 10961 | * This function is called with no locks held. |
| 10962 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10963 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10964 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10965 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10966 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10967 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10968 | struct lpfc_iocbq *iocbq; |
| 10969 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 10970 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10971 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10972 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10973 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10974 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10975 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10976 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10977 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10978 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10979 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10980 | continue; |
| 10981 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10982 | /* |
| 10983 | * If the iocbq is already being aborted, don't take a second |
| 10984 | * action, but do count it. |
| 10985 | */ |
| 10986 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10987 | continue; |
| 10988 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10989 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10990 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10991 | if (abtsiocb == NULL) { |
| 10992 | errcnt++; |
| 10993 | continue; |
| 10994 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10995 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10996 | /* indicate the IO is being aborted by the driver. */ |
| 10997 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10998 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10999 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11000 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11001 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11002 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11003 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11004 | else |
| 11005 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11006 | abtsiocb->iocb.ulpLe = 1; |
| 11007 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11008 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11009 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11010 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11011 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11012 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11013 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11014 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11015 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11016 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11017 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11018 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11019 | else |
| 11020 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11021 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11022 | /* Setup callback routine and issue the command. */ |
| 11023 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11024 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11025 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11026 | if (!pring_s4) |
| 11027 | continue; |
| 11028 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11029 | abtsiocb, 0); |
| 11030 | } else |
| 11031 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11032 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11033 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11034 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11035 | errcnt++; |
| 11036 | continue; |
| 11037 | } |
| 11038 | } |
| 11039 | |
| 11040 | return errcnt; |
| 11041 | } |
| 11042 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11043 | /** |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11044 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11045 | * @vport: Pointer to virtual port. |
| 11046 | * @pring: Pointer to driver SLI ring object. |
| 11047 | * @tgt_id: SCSI ID of the target. |
| 11048 | * @lun_id: LUN ID of the scsi device. |
| 11049 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11050 | * |
| 11051 | * This function sends an abort command for every SCSI command |
| 11052 | * associated with the given virtual port pending on the ring |
| 11053 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11054 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11055 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11056 | * parameters |
| 11057 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11058 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11059 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11060 | * FCP iocbs associated with virtual port. |
| 11061 | * This function returns number of iocbs it aborted . |
| 11062 | * This function is called with no locks held right after a taskmgmt |
| 11063 | * command is sent. |
| 11064 | **/ |
| 11065 | int |
| 11066 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11067 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11068 | { |
| 11069 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11070 | struct lpfc_scsi_buf *lpfc_cmd; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11071 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11072 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11073 | struct lpfc_iocbq *iocbq; |
| 11074 | IOCB_t *icmd; |
| 11075 | int sum, i, ret_val; |
| 11076 | unsigned long iflags; |
| 11077 | struct lpfc_sli_ring *pring_s4; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11078 | |
| 11079 | spin_lock_irq(&phba->hbalock); |
| 11080 | |
| 11081 | /* all I/Os are in process of being flushed */ |
| 11082 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
| 11083 | spin_unlock_irq(&phba->hbalock); |
| 11084 | return 0; |
| 11085 | } |
| 11086 | sum = 0; |
| 11087 | |
| 11088 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11089 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11090 | |
| 11091 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11092 | cmd) != 0) |
| 11093 | continue; |
| 11094 | |
| 11095 | /* |
| 11096 | * If the iocbq is already being aborted, don't take a second |
| 11097 | * action, but do count it. |
| 11098 | */ |
| 11099 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11100 | continue; |
| 11101 | |
| 11102 | /* issue ABTS for this IOCB based on iotag */ |
| 11103 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 11104 | if (abtsiocbq == NULL) |
| 11105 | continue; |
| 11106 | |
| 11107 | icmd = &iocbq->iocb; |
| 11108 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11109 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11110 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11111 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11112 | iocbq->sli4_xritag; |
| 11113 | else |
| 11114 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11115 | abtsiocbq->iocb.ulpLe = 1; |
| 11116 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11117 | abtsiocbq->vport = vport; |
| 11118 | |
| 11119 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11120 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11121 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11122 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11123 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11124 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11125 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11126 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 11127 | ndlp = lpfc_cmd->rdata->pnode; |
| 11128 | |
| 11129 | if (lpfc_is_link_up(phba) && |
| 11130 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11131 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11132 | else |
| 11133 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11134 | |
| 11135 | /* Setup callback routine and issue the command. */ |
| 11136 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11137 | |
| 11138 | /* |
| 11139 | * Indicate the IO is being aborted by the driver and set |
| 11140 | * the caller's flag into the aborted IO. |
| 11141 | */ |
| 11142 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11143 | |
| 11144 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11145 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11146 | if (pring_s4 == NULL) |
| 11147 | continue; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11148 | /* Note: both hbalock and ring_lock must be set here */ |
| 11149 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 11150 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11151 | abtsiocbq, 0); |
| 11152 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 11153 | } else { |
| 11154 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11155 | abtsiocbq, 0); |
| 11156 | } |
| 11157 | |
| 11158 | |
| 11159 | if (ret_val == IOCB_ERROR) |
| 11160 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11161 | else |
| 11162 | sum++; |
| 11163 | } |
| 11164 | spin_unlock_irq(&phba->hbalock); |
| 11165 | return sum; |
| 11166 | } |
| 11167 | |
| 11168 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11169 | * 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] | 11170 | * @phba: Pointer to HBA context object. |
| 11171 | * @cmdiocbq: Pointer to command iocb. |
| 11172 | * @rspiocbq: Pointer to response iocb. |
| 11173 | * |
| 11174 | * This function is the completion handler for iocbs issued using |
| 11175 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11176 | * ring event handler function without any lock held. This function |
| 11177 | * can be called from both worker thread context and interrupt |
| 11178 | * context. This function also can be called from other thread which |
| 11179 | * cleans up the SLI layer objects. |
| 11180 | * This function copy the contents of the response iocb to the |
| 11181 | * response iocb memory object provided by the caller of |
| 11182 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11183 | * sleeps for the iocb completion. |
| 11184 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11185 | static void |
| 11186 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11187 | struct lpfc_iocbq *cmdiocbq, |
| 11188 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11189 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11190 | wait_queue_head_t *pdone_q; |
| 11191 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11192 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11193 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11194 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11195 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11196 | |
| 11197 | /* |
| 11198 | * A time out has occurred for the iocb. If a time out |
| 11199 | * completion handler has been supplied, call it. Otherwise, |
| 11200 | * just free the iocbq. |
| 11201 | */ |
| 11202 | |
| 11203 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11204 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11205 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11206 | if (cmdiocbq->iocb_cmpl) |
| 11207 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11208 | else |
| 11209 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11210 | return; |
| 11211 | } |
| 11212 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11213 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11214 | if (cmdiocbq->context2 && rspiocbq) |
| 11215 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11216 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11217 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11218 | /* Set the exchange busy flag for task management commands */ |
| 11219 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11220 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 11221 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 11222 | cur_iocbq); |
| 11223 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11224 | } |
| 11225 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11226 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11227 | if (pdone_q) |
| 11228 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11229 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11230 | return; |
| 11231 | } |
| 11232 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11233 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11234 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11235 | * @phba: Pointer to HBA context object.. |
| 11236 | * @piocbq: Pointer to command iocb. |
| 11237 | * @flag: Flag to test. |
| 11238 | * |
| 11239 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11240 | * see if the passed in flag is set. |
| 11241 | * Returns: |
| 11242 | * 1 if flag is set. |
| 11243 | * 0 if flag is not set. |
| 11244 | **/ |
| 11245 | static int |
| 11246 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11247 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11248 | { |
| 11249 | unsigned long iflags; |
| 11250 | int ret; |
| 11251 | |
| 11252 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11253 | ret = piocbq->iocb_flag & flag; |
| 11254 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11255 | return ret; |
| 11256 | |
| 11257 | } |
| 11258 | |
| 11259 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11260 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11261 | * @phba: Pointer to HBA context object.. |
| 11262 | * @pring: Pointer to sli ring. |
| 11263 | * @piocb: Pointer to command iocb. |
| 11264 | * @prspiocbq: Pointer to response iocb. |
| 11265 | * @timeout: Timeout in number of seconds. |
| 11266 | * |
| 11267 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11268 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11269 | * to handle iocbs which time out. If the field is NULL, the |
| 11270 | * function shall free the iocbq structure. If more clean up is |
| 11271 | * needed, the caller is expected to provide a completion function |
| 11272 | * that will provide the needed clean up. If the iocb command is |
| 11273 | * not completed within timeout seconds, the function will either |
| 11274 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11275 | * completion function set in the iocb_cmpl field and then return |
| 11276 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11277 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11278 | * The function waits for the iocb completion using an |
| 11279 | * non-interruptible wait. |
| 11280 | * This function will sleep while waiting for iocb completion. |
| 11281 | * So, this function should not be called from any context which |
| 11282 | * does not allow sleeping. Due to the same reason, this function |
| 11283 | * cannot be called with interrupt disabled. |
| 11284 | * This function assumes that the iocb completions occur while |
| 11285 | * this function sleep. So, this function cannot be called from |
| 11286 | * the thread which process iocb completion for this ring. |
| 11287 | * This function clears the iocb_flag of the iocb object before |
| 11288 | * issuing the iocb and the iocb completion handler sets this |
| 11289 | * flag and wakes this thread when the iocb completes. |
| 11290 | * The contents of the response iocb will be copied to prspiocbq |
| 11291 | * by the completion handler when the command completes. |
| 11292 | * This function returns IOCB_SUCCESS when success. |
| 11293 | * This function is called with no lock held. |
| 11294 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11295 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11296 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11297 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11298 | struct lpfc_iocbq *piocb, |
| 11299 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11300 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11301 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11302 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11303 | long timeleft, timeout_req = 0; |
| 11304 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11305 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11306 | struct lpfc_iocbq *iocb; |
| 11307 | int txq_cnt = 0; |
| 11308 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11309 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11310 | unsigned long iflags; |
| 11311 | bool iocb_completed = true; |
| 11312 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11313 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11314 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11315 | else |
| 11316 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11317 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11318 | * If the caller has provided a response iocbq buffer, then context2 |
| 11319 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11320 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11321 | if (prspiocbq) { |
| 11322 | if (piocb->context2) |
| 11323 | return IOCB_ERROR; |
| 11324 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11325 | } |
| 11326 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11327 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11328 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11329 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11330 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11331 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11332 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11333 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11334 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11335 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11336 | writel(creg_val, phba->HCregaddr); |
| 11337 | readl(phba->HCregaddr); /* flush */ |
| 11338 | } |
| 11339 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11340 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11341 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11342 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11343 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11344 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11345 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11346 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11347 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11348 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11349 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11350 | /* |
| 11351 | * IOCB timed out. Inform the wake iocb wait |
| 11352 | * completion function and set local status |
| 11353 | */ |
| 11354 | |
| 11355 | iocb_completed = false; |
| 11356 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11357 | } |
| 11358 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11359 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11360 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11361 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11362 | /* Note: we are not indicating if the IOCB has a success |
| 11363 | * status or not - that's for the caller to check. |
| 11364 | * IOCB_SUCCESS means just that the command was sent and |
| 11365 | * completed. Not that it completed successfully. |
| 11366 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11367 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11368 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11369 | "0338 IOCB wait timeout error - no " |
| 11370 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11371 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11372 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11373 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11374 | "0330 IOCB wake NOT set, " |
| 11375 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11376 | timeout, (timeleft / jiffies)); |
| 11377 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11378 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11379 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11380 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11381 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11382 | txq_cnt++; |
| 11383 | } |
| 11384 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11385 | txcmplq_cnt++; |
| 11386 | } |
| 11387 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11388 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11389 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11390 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11391 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11392 | } else { |
| 11393 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11394 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11395 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11396 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11397 | } |
| 11398 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11399 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11400 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11401 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11402 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 11403 | writel(creg_val, phba->HCregaddr); |
| 11404 | readl(phba->HCregaddr); /* flush */ |
| 11405 | } |
| 11406 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11407 | if (prspiocbq) |
| 11408 | piocb->context2 = NULL; |
| 11409 | |
| 11410 | piocb->context_un.wait_queue = NULL; |
| 11411 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11412 | return retval; |
| 11413 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11414 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11415 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11416 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11417 | * @phba: Pointer to HBA context object. |
| 11418 | * @pmboxq: Pointer to driver mailbox object. |
| 11419 | * @timeout: Timeout in number of seconds. |
| 11420 | * |
| 11421 | * This function issues the mailbox to firmware and waits for the |
| 11422 | * mailbox command to complete. If the mailbox command is not |
| 11423 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 11424 | * The function waits for the mailbox completion using an |
| 11425 | * interruptible wait. If the thread is woken up due to a |
| 11426 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 11427 | * should not free the mailbox resources, if this function returns |
| 11428 | * MBX_TIMEOUT. |
| 11429 | * This function will sleep while waiting for mailbox completion. |
| 11430 | * So, this function should not be called from any context which |
| 11431 | * does not allow sleeping. Due to the same reason, this function |
| 11432 | * cannot be called with interrupt disabled. |
| 11433 | * This function assumes that the mailbox completion occurs while |
| 11434 | * this function sleep. So, this function cannot be called from |
| 11435 | * the worker thread which processes mailbox completion. |
| 11436 | * This function is called in the context of HBA management |
| 11437 | * applications. |
| 11438 | * This function returns MBX_SUCCESS when successful. |
| 11439 | * This function is called with no lock held. |
| 11440 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11441 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11442 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11443 | uint32_t timeout) |
| 11444 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11445 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11446 | MAILBOX_t *mb = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11447 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11448 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11449 | |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11450 | /* The caller might set context1 for extended buffer */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11451 | if (pmboxq->context1) |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11452 | mb = (MAILBOX_t *)pmboxq->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11453 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11454 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11455 | /* setup wake call as IOCB callback */ |
| 11456 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 11457 | /* setup context field to pass wait_queue pointer to wake function */ |
| 11458 | pmboxq->context1 = &done_q; |
| 11459 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11460 | /* now issue the command */ |
| 11461 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11462 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11463 | wait_event_interruptible_timeout(done_q, |
| 11464 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11465 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11466 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11467 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11468 | /* restore the possible extended buffer for free resource */ |
| 11469 | pmboxq->context1 = (uint8_t *)mb; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11470 | /* |
| 11471 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 11472 | * else do not free the resources. |
| 11473 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11474 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11475 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11476 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11477 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11478 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 11479 | } |
| 11480 | spin_unlock_irqrestore(&phba->hbalock, flag); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11481 | } else { |
| 11482 | /* restore the possible extended buffer for free resource */ |
| 11483 | pmboxq->context1 = (uint8_t *)mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11484 | } |
| 11485 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11486 | return retval; |
| 11487 | } |
| 11488 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11489 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11490 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11491 | * @phba: Pointer to HBA context. |
| 11492 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11493 | * This function is called to shutdown the driver's mailbox sub-system. |
| 11494 | * It first marks the mailbox sub-system is in a block state to prevent |
| 11495 | * the asynchronous mailbox command from issued off the pending mailbox |
| 11496 | * command queue. If the mailbox command sub-system shutdown is due to |
| 11497 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 11498 | * the mailbox sub-system flush routine to forcefully bring down the |
| 11499 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 11500 | * as with offline or HBA function reset), this routine will wait for the |
| 11501 | * outstanding mailbox command to complete before invoking the mailbox |
| 11502 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11503 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11504 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11505 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11506 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11507 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11508 | unsigned long timeout; |
| 11509 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11510 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 11511 | /* delay 100ms for port state */ |
| 11512 | msleep(100); |
| 11513 | lpfc_sli_mbox_sys_flush(phba); |
| 11514 | return; |
| 11515 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11516 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 11517 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11518 | spin_lock_irq(&phba->hbalock); |
| 11519 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11520 | |
| 11521 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11522 | /* Determine how long we might wait for the active mailbox |
| 11523 | * command to be gracefully completed by firmware. |
| 11524 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11525 | if (phba->sli.mbox_active) |
| 11526 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 11527 | phba->sli.mbox_active) * |
| 11528 | 1000) + jiffies; |
| 11529 | spin_unlock_irq(&phba->hbalock); |
| 11530 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11531 | while (phba->sli.mbox_active) { |
| 11532 | /* Check active mailbox complete status every 2ms */ |
| 11533 | msleep(2); |
| 11534 | if (time_after(jiffies, timeout)) |
| 11535 | /* Timeout, let the mailbox flush routine to |
| 11536 | * forcefully release active mailbox command |
| 11537 | */ |
| 11538 | break; |
| 11539 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 11540 | } else |
| 11541 | spin_unlock_irq(&phba->hbalock); |
| 11542 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11543 | lpfc_sli_mbox_sys_flush(phba); |
| 11544 | } |
| 11545 | |
| 11546 | /** |
| 11547 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 11548 | * @phba: Pointer to HBA context. |
| 11549 | * |
| 11550 | * This function is called to read the SLI3 device error attention registers |
| 11551 | * for possible error attention events. The caller must hold the hostlock |
| 11552 | * with spin_lock_irq(). |
| 11553 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11554 | * 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] | 11555 | * Register and returns 0 otherwise. |
| 11556 | **/ |
| 11557 | static int |
| 11558 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 11559 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11560 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11561 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11562 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11563 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11564 | goto unplug_err; |
| 11565 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11566 | if (ha_copy & HA_ERATT) { |
| 11567 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11568 | if (lpfc_sli_read_hs(phba)) |
| 11569 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11570 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11571 | /* Check if there is a deferred error condition is active */ |
| 11572 | if ((HS_FFER1 & phba->work_hs) && |
| 11573 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11574 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11575 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11576 | /* Clear all interrupt enable conditions */ |
| 11577 | writel(0, phba->HCregaddr); |
| 11578 | readl(phba->HCregaddr); |
| 11579 | } |
| 11580 | |
| 11581 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11582 | phba->work_ha |= HA_ERATT; |
| 11583 | /* Indicate polling handles this ERATT */ |
| 11584 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11585 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11586 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11587 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11588 | |
| 11589 | unplug_err: |
| 11590 | /* Set the driver HS work bitmap */ |
| 11591 | phba->work_hs |= UNPLUG_ERR; |
| 11592 | /* Set the driver HA work bitmap */ |
| 11593 | phba->work_ha |= HA_ERATT; |
| 11594 | /* Indicate polling handles this ERATT */ |
| 11595 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11596 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11597 | } |
| 11598 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11599 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11600 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 11601 | * @phba: Pointer to HBA context. |
| 11602 | * |
| 11603 | * This function is called to read the SLI4 device error attention registers |
| 11604 | * for possible error attention events. The caller must hold the hostlock |
| 11605 | * with spin_lock_irq(). |
| 11606 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11607 | * 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] | 11608 | * Register and returns 0 otherwise. |
| 11609 | **/ |
| 11610 | static int |
| 11611 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 11612 | { |
| 11613 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11614 | uint32_t if_type, portsmphr; |
| 11615 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11616 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11617 | /* |
| 11618 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11619 | * registers for error attention. This can be changed later. |
| 11620 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11621 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 11622 | switch (if_type) { |
| 11623 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11624 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 11625 | &uerr_sta_lo) || |
| 11626 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 11627 | &uerr_sta_hi)) { |
| 11628 | phba->work_hs |= UNPLUG_ERR; |
| 11629 | phba->work_ha |= HA_ERATT; |
| 11630 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11631 | return 1; |
| 11632 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11633 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 11634 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 11635 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11636 | "1423 HBA Unrecoverable error: " |
| 11637 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 11638 | "ue_mask_lo_reg=0x%x, " |
| 11639 | "ue_mask_hi_reg=0x%x\n", |
| 11640 | uerr_sta_lo, uerr_sta_hi, |
| 11641 | phba->sli4_hba.ue_mask_lo, |
| 11642 | phba->sli4_hba.ue_mask_hi); |
| 11643 | phba->work_status[0] = uerr_sta_lo; |
| 11644 | phba->work_status[1] = uerr_sta_hi; |
| 11645 | phba->work_ha |= HA_ERATT; |
| 11646 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11647 | return 1; |
| 11648 | } |
| 11649 | break; |
| 11650 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11651 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 11652 | &portstat_reg.word0) || |
| 11653 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 11654 | &portsmphr)){ |
| 11655 | phba->work_hs |= UNPLUG_ERR; |
| 11656 | phba->work_ha |= HA_ERATT; |
| 11657 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11658 | return 1; |
| 11659 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11660 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 11661 | phba->work_status[0] = |
| 11662 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 11663 | phba->work_status[1] = |
| 11664 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 11665 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11666 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11667 | "port status reg 0x%x, " |
| 11668 | "port smphr reg 0x%x, " |
| 11669 | "error 1=0x%x, error 2=0x%x\n", |
| 11670 | portstat_reg.word0, |
| 11671 | portsmphr, |
| 11672 | phba->work_status[0], |
| 11673 | phba->work_status[1]); |
| 11674 | phba->work_ha |= HA_ERATT; |
| 11675 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11676 | return 1; |
| 11677 | } |
| 11678 | break; |
| 11679 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 11680 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11681 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11682 | "2886 HBA Error Attention on unsupported " |
| 11683 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11684 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11685 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11686 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11687 | return 0; |
| 11688 | } |
| 11689 | |
| 11690 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11691 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11692 | * @phba: Pointer to HBA context. |
| 11693 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11694 | * 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] | 11695 | * error attention register bit for error attention events. |
| 11696 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11697 | * 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] | 11698 | * Register and returns 0 otherwise. |
| 11699 | **/ |
| 11700 | int |
| 11701 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 11702 | { |
| 11703 | uint32_t ha_copy; |
| 11704 | |
| 11705 | /* If somebody is waiting to handle an eratt, don't process it |
| 11706 | * here. The brdkill function will do this. |
| 11707 | */ |
| 11708 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11709 | return 0; |
| 11710 | |
| 11711 | /* Check if interrupt handler handles this ERATT */ |
| 11712 | spin_lock_irq(&phba->hbalock); |
| 11713 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 11714 | /* Interrupt handler has handled ERATT */ |
| 11715 | spin_unlock_irq(&phba->hbalock); |
| 11716 | return 0; |
| 11717 | } |
| 11718 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11719 | /* |
| 11720 | * If there is deferred error attention, do not check for error |
| 11721 | * attention |
| 11722 | */ |
| 11723 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 11724 | spin_unlock_irq(&phba->hbalock); |
| 11725 | return 0; |
| 11726 | } |
| 11727 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11728 | /* If PCI channel is offline, don't process it */ |
| 11729 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11730 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11731 | return 0; |
| 11732 | } |
| 11733 | |
| 11734 | switch (phba->sli_rev) { |
| 11735 | case LPFC_SLI_REV2: |
| 11736 | case LPFC_SLI_REV3: |
| 11737 | /* Read chip Host Attention (HA) register */ |
| 11738 | ha_copy = lpfc_sli_eratt_read(phba); |
| 11739 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11740 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11741 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11742 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 11743 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11744 | default: |
| 11745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11746 | "0299 Invalid SLI revision (%d)\n", |
| 11747 | phba->sli_rev); |
| 11748 | ha_copy = 0; |
| 11749 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11750 | } |
| 11751 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11752 | |
| 11753 | return ha_copy; |
| 11754 | } |
| 11755 | |
| 11756 | /** |
| 11757 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 11758 | * @phba: Pointer to HBA context. |
| 11759 | * |
| 11760 | * This inline routine checks whether a device or its PCI slot is in a state |
| 11761 | * that the interrupt should be handled. |
| 11762 | * |
| 11763 | * This function returns 0 if the device or the PCI slot is in a state that |
| 11764 | * interrupt should be handled, otherwise -EIO. |
| 11765 | */ |
| 11766 | static inline int |
| 11767 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 11768 | { |
| 11769 | /* If the pci channel is offline, ignore all the interrupts */ |
| 11770 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 11771 | return -EIO; |
| 11772 | |
| 11773 | /* Update device level interrupt statistics */ |
| 11774 | phba->sli.slistat.sli_intr++; |
| 11775 | |
| 11776 | /* Ignore all interrupts during initialization. */ |
| 11777 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 11778 | return -EIO; |
| 11779 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11780 | return 0; |
| 11781 | } |
| 11782 | |
| 11783 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11784 | * 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] | 11785 | * @irq: Interrupt number. |
| 11786 | * @dev_id: The device context pointer. |
| 11787 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11788 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11789 | * service routine when device with SLI-3 interface spec is enabled with |
| 11790 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11791 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11792 | * interrupt mode, this function is called as part of the device-level |
| 11793 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 11794 | * is undergoing initialization, the interrupt handler will not process |
| 11795 | * the interrupt. The link attention and ELS ring attention events are |
| 11796 | * handled by the worker thread. The interrupt handler signals the worker |
| 11797 | * thread and returns for these events. This function is called without |
| 11798 | * 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] | 11799 | * structures. |
| 11800 | * |
| 11801 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11802 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11803 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11804 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11805 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11806 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11807 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11808 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11809 | uint32_t work_ha_copy; |
| 11810 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11811 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11812 | uint32_t control; |
| 11813 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11814 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11815 | struct lpfc_vport *vport; |
| 11816 | struct lpfc_nodelist *ndlp; |
| 11817 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11818 | LPFC_MBOXQ_t *pmb; |
| 11819 | int rc; |
| 11820 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11821 | /* |
| 11822 | * Get the driver's phba structure from the dev_id and |
| 11823 | * assume the HBA is not interrupting. |
| 11824 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11825 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11826 | |
| 11827 | if (unlikely(!phba)) |
| 11828 | return IRQ_NONE; |
| 11829 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11830 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11831 | * Stuff needs to be attented to when this function is invoked as an |
| 11832 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11833 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11834 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11835 | /* Check device state for handling interrupt */ |
| 11836 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11837 | return IRQ_NONE; |
| 11838 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11839 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11840 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11841 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11842 | /* If somebody is waiting to handle an eratt don't process it |
| 11843 | * here. The brdkill function will do this. |
| 11844 | */ |
| 11845 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11846 | ha_copy &= ~HA_ERATT; |
| 11847 | /* Check the need for handling ERATT in interrupt handler */ |
| 11848 | if (ha_copy & HA_ERATT) { |
| 11849 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11850 | /* ERATT polling has handled ERATT */ |
| 11851 | ha_copy &= ~HA_ERATT; |
| 11852 | else |
| 11853 | /* Indicate interrupt handler handles ERATT */ |
| 11854 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11855 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11856 | |
| 11857 | /* |
| 11858 | * If there is deferred error attention, do not check for any |
| 11859 | * interrupt. |
| 11860 | */ |
| 11861 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11862 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11863 | return IRQ_NONE; |
| 11864 | } |
| 11865 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11866 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11867 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 11868 | goto unplug_error; |
| 11869 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11870 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 11871 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11872 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11873 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 11874 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11875 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11876 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11877 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11878 | } else |
| 11879 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11880 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11881 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 11882 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11883 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11884 | if (work_ha_copy & HA_LATT) { |
| 11885 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 11886 | /* |
| 11887 | * Turn off Link Attention interrupts |
| 11888 | * until CLEAR_LA done |
| 11889 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11890 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11891 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11892 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11893 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11894 | control &= ~HC_LAINT_ENA; |
| 11895 | writel(control, phba->HCregaddr); |
| 11896 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11897 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11898 | } |
| 11899 | else |
| 11900 | work_ha_copy &= ~HA_LATT; |
| 11901 | } |
| 11902 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11903 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11904 | /* |
| 11905 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 11906 | * the only slow ring. |
| 11907 | */ |
| 11908 | status = (work_ha_copy & |
| 11909 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11910 | status >>= (4*LPFC_ELS_RING); |
| 11911 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11912 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11913 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11914 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11915 | |
| 11916 | lpfc_debugfs_slow_ring_trc(phba, |
| 11917 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 11918 | control, status, |
| 11919 | (uint32_t)phba->sli.slistat.sli_intr); |
| 11920 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11921 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11922 | lpfc_debugfs_slow_ring_trc(phba, |
| 11923 | "ISR Disable ring:" |
| 11924 | "pwork:x%x hawork:x%x wait:x%x", |
| 11925 | phba->work_ha, work_ha_copy, |
| 11926 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11927 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11928 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11929 | control &= |
| 11930 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11931 | writel(control, phba->HCregaddr); |
| 11932 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11933 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11934 | else { |
| 11935 | lpfc_debugfs_slow_ring_trc(phba, |
| 11936 | "ISR slow ring: pwork:" |
| 11937 | "x%x hawork:x%x wait:x%x", |
| 11938 | phba->work_ha, work_ha_copy, |
| 11939 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11940 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11941 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11942 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11943 | } |
| 11944 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11945 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11946 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11947 | if (lpfc_sli_read_hs(phba)) |
| 11948 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11949 | /* |
| 11950 | * Check if there is a deferred error condition |
| 11951 | * is active |
| 11952 | */ |
| 11953 | if ((HS_FFER1 & phba->work_hs) && |
| 11954 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11955 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 11956 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11957 | phba->hba_flag |= DEFER_ERATT; |
| 11958 | /* Clear all interrupt enable conditions */ |
| 11959 | writel(0, phba->HCregaddr); |
| 11960 | readl(phba->HCregaddr); |
| 11961 | } |
| 11962 | } |
| 11963 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11964 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11965 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11966 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11967 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11968 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11969 | |
| 11970 | /* First check out the status word */ |
| 11971 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 11972 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11973 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11974 | /* |
| 11975 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 11976 | * mbxStatus <status> |
| 11977 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11978 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11979 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11980 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11981 | "Interrupt mbxCommand x%x " |
| 11982 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11983 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11984 | pmbox->mbxCommand, |
| 11985 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11986 | /* clear mailbox attention bit */ |
| 11987 | work_ha_copy &= ~HA_MBATT; |
| 11988 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 11989 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11990 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11991 | phba->last_completion_time = jiffies; |
| 11992 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11993 | if (pmb->mbox_cmpl) { |
| 11994 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 11995 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 11996 | if (pmb->out_ext_byte_len && |
| 11997 | pmb->context2) |
| 11998 | lpfc_sli_pcimem_bcopy( |
| 11999 | phba->mbox_ext, |
| 12000 | pmb->context2, |
| 12001 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12002 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12003 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12004 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12005 | |
| 12006 | lpfc_debugfs_disc_trc(vport, |
| 12007 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12008 | "MBOX dflt rpi: : " |
| 12009 | "status:x%x rpi:x%x", |
| 12010 | (uint32_t)pmbox->mbxStatus, |
| 12011 | pmbox->un.varWords[0], 0); |
| 12012 | |
| 12013 | if (!pmbox->mbxStatus) { |
| 12014 | mp = (struct lpfc_dmabuf *) |
| 12015 | (pmb->context1); |
| 12016 | ndlp = (struct lpfc_nodelist *) |
| 12017 | pmb->context2; |
| 12018 | |
| 12019 | /* Reg_LOGIN of dflt RPI was |
| 12020 | * successful. new lets get |
| 12021 | * rid of the RPI using the |
| 12022 | * same mbox buffer. |
| 12023 | */ |
| 12024 | lpfc_unreg_login(phba, |
| 12025 | vport->vpi, |
| 12026 | pmbox->un.varWords[0], |
| 12027 | pmb); |
| 12028 | pmb->mbox_cmpl = |
| 12029 | lpfc_mbx_cmpl_dflt_rpi; |
| 12030 | pmb->context1 = mp; |
| 12031 | pmb->context2 = ndlp; |
| 12032 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12033 | rc = lpfc_sli_issue_mbox(phba, |
| 12034 | pmb, |
| 12035 | MBX_NOWAIT); |
| 12036 | if (rc != MBX_BUSY) |
| 12037 | lpfc_printf_log(phba, |
| 12038 | KERN_ERR, |
| 12039 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12040 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12041 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12042 | if (rc != MBX_NOT_FINISHED) |
| 12043 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12044 | } |
| 12045 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12046 | spin_lock_irqsave( |
| 12047 | &phba->pport->work_port_lock, |
| 12048 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12049 | phba->pport->work_port_events &= |
| 12050 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12051 | spin_unlock_irqrestore( |
| 12052 | &phba->pport->work_port_lock, |
| 12053 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12054 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12055 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12056 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12057 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12058 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12059 | if ((work_ha_copy & HA_MBATT) && |
| 12060 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12061 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12062 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12063 | do { |
| 12064 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12065 | MBX_NOWAIT); |
| 12066 | } while (rc == MBX_NOT_FINISHED); |
| 12067 | if (rc != MBX_SUCCESS) |
| 12068 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12069 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12070 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12071 | } |
| 12072 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12073 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12074 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12075 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12076 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12077 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12078 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12079 | unplug_error: |
| 12080 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12081 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12082 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12083 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12084 | |
| 12085 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12086 | * 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] | 12087 | * @irq: Interrupt number. |
| 12088 | * @dev_id: The device context pointer. |
| 12089 | * |
| 12090 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12091 | * service routine when device with SLI-3 interface spec is enabled with |
| 12092 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12093 | * ring event in the HBA. However, when the device is enabled with either |
| 12094 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12095 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12096 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12097 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12098 | * the intrrupt context. This function is called without any lock held. |
| 12099 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12100 | * |
| 12101 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12102 | * returns IRQ_NONE. |
| 12103 | **/ |
| 12104 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12105 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12106 | { |
| 12107 | struct lpfc_hba *phba; |
| 12108 | uint32_t ha_copy; |
| 12109 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12110 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12111 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12112 | |
| 12113 | /* Get the driver's phba structure from the dev_id and |
| 12114 | * assume the HBA is not interrupting. |
| 12115 | */ |
| 12116 | phba = (struct lpfc_hba *) dev_id; |
| 12117 | |
| 12118 | if (unlikely(!phba)) |
| 12119 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12120 | |
| 12121 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12122 | * Stuff needs to be attented to when this function is invoked as an |
| 12123 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12124 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12125 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12126 | /* Check device state for handling interrupt */ |
| 12127 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12128 | return IRQ_NONE; |
| 12129 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12130 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12131 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12132 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12133 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12134 | /* |
| 12135 | * If there is deferred error attention, do not check for |
| 12136 | * any interrupt. |
| 12137 | */ |
| 12138 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12139 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12140 | return IRQ_NONE; |
| 12141 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12142 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12143 | phba->HAregaddr); |
| 12144 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12145 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12146 | } else |
| 12147 | ha_copy = phba->ha_copy; |
| 12148 | |
| 12149 | /* |
| 12150 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12151 | */ |
| 12152 | ha_copy &= ~(phba->work_ha_mask); |
| 12153 | |
| 12154 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12155 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12156 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12157 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12158 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12159 | |
| 12160 | if (phba->cfg_multi_ring_support == 2) { |
| 12161 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12162 | * Process all events on extra ring. Take the optimized path |
| 12163 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12164 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12165 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12166 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12167 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12168 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12169 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12170 | status); |
| 12171 | } |
| 12172 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12173 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12174 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12175 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12176 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12177 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12178 | * @irq: Interrupt number. |
| 12179 | * @dev_id: The device context pointer. |
| 12180 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12181 | * This function is the HBA device-level interrupt handler to device with |
| 12182 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12183 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12184 | * requires driver attention. This function invokes the slow-path interrupt |
| 12185 | * attention handling function and fast-path interrupt attention handling |
| 12186 | * function in turn to process the relevant HBA attention events. This |
| 12187 | * function is called without any lock held. It gets the hbalock to access |
| 12188 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12189 | * |
| 12190 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12191 | * returns IRQ_NONE. |
| 12192 | **/ |
| 12193 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12194 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12195 | { |
| 12196 | struct lpfc_hba *phba; |
| 12197 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12198 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12199 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12200 | |
| 12201 | /* |
| 12202 | * Get the driver's phba structure from the dev_id and |
| 12203 | * assume the HBA is not interrupting. |
| 12204 | */ |
| 12205 | phba = (struct lpfc_hba *) dev_id; |
| 12206 | |
| 12207 | if (unlikely(!phba)) |
| 12208 | return IRQ_NONE; |
| 12209 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12210 | /* Check device state for handling interrupt */ |
| 12211 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12212 | return IRQ_NONE; |
| 12213 | |
| 12214 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12215 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12216 | spin_unlock(&phba->hbalock); |
| 12217 | return IRQ_HANDLED; |
| 12218 | } |
| 12219 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12220 | if (unlikely(!phba->ha_copy)) { |
| 12221 | spin_unlock(&phba->hbalock); |
| 12222 | return IRQ_NONE; |
| 12223 | } else if (phba->ha_copy & HA_ERATT) { |
| 12224 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12225 | /* ERATT polling has handled ERATT */ |
| 12226 | phba->ha_copy &= ~HA_ERATT; |
| 12227 | else |
| 12228 | /* Indicate interrupt handler handles ERATT */ |
| 12229 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12230 | } |
| 12231 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12232 | /* |
| 12233 | * If there is deferred error attention, do not check for any interrupt. |
| 12234 | */ |
| 12235 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12236 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12237 | return IRQ_NONE; |
| 12238 | } |
| 12239 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12240 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12241 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12242 | spin_unlock(&phba->hbalock); |
| 12243 | return IRQ_HANDLED; |
| 12244 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12245 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12246 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12247 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12248 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12249 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12250 | readl(phba->HAregaddr); /* flush */ |
| 12251 | spin_unlock(&phba->hbalock); |
| 12252 | |
| 12253 | /* |
| 12254 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12255 | */ |
| 12256 | |
| 12257 | /* status of events with mailbox and link attention */ |
| 12258 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12259 | |
| 12260 | /* status of events with ELS ring */ |
| 12261 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12262 | status2 >>= (4*LPFC_ELS_RING); |
| 12263 | |
| 12264 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12265 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12266 | else |
| 12267 | sp_irq_rc = IRQ_NONE; |
| 12268 | |
| 12269 | /* |
| 12270 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12271 | */ |
| 12272 | |
| 12273 | /* status of events with FCP ring */ |
| 12274 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12275 | status1 >>= (4*LPFC_FCP_RING); |
| 12276 | |
| 12277 | /* status of events with extra ring */ |
| 12278 | if (phba->cfg_multi_ring_support == 2) { |
| 12279 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12280 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12281 | } else |
| 12282 | status2 = 0; |
| 12283 | |
| 12284 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12285 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12286 | else |
| 12287 | fp_irq_rc = IRQ_NONE; |
| 12288 | |
| 12289 | /* Return device-level interrupt handling status */ |
| 12290 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12291 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12292 | |
| 12293 | /** |
| 12294 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 12295 | * @phba: pointer to lpfc hba data structure. |
| 12296 | * |
| 12297 | * This routine is invoked by the worker thread to process all the pending |
| 12298 | * SLI4 FCP abort XRI events. |
| 12299 | **/ |
| 12300 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12301 | { |
| 12302 | struct lpfc_cq_event *cq_event; |
| 12303 | |
| 12304 | /* First, declare the fcp xri abort event has been handled */ |
| 12305 | spin_lock_irq(&phba->hbalock); |
| 12306 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 12307 | spin_unlock_irq(&phba->hbalock); |
| 12308 | /* Now, handle all the fcp xri abort events */ |
| 12309 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 12310 | /* Get the first event from the head of the event queue */ |
| 12311 | spin_lock_irq(&phba->hbalock); |
| 12312 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 12313 | cq_event, struct lpfc_cq_event, list); |
| 12314 | spin_unlock_irq(&phba->hbalock); |
| 12315 | /* Notify aborted XRI for FCP work queue */ |
| 12316 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12317 | /* Free the event processed back to the free pool */ |
| 12318 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12319 | } |
| 12320 | } |
| 12321 | |
| 12322 | /** |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12323 | * lpfc_sli4_nvme_xri_abort_event_proc - Process nvme xri abort event |
| 12324 | * @phba: pointer to lpfc hba data structure. |
| 12325 | * |
| 12326 | * This routine is invoked by the worker thread to process all the pending |
| 12327 | * SLI4 NVME abort XRI events. |
| 12328 | **/ |
| 12329 | void lpfc_sli4_nvme_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12330 | { |
| 12331 | struct lpfc_cq_event *cq_event; |
| 12332 | |
| 12333 | /* First, declare the fcp xri abort event has been handled */ |
| 12334 | spin_lock_irq(&phba->hbalock); |
| 12335 | phba->hba_flag &= ~NVME_XRI_ABORT_EVENT; |
| 12336 | spin_unlock_irq(&phba->hbalock); |
| 12337 | /* Now, handle all the fcp xri abort events */ |
| 12338 | while (!list_empty(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue)) { |
| 12339 | /* Get the first event from the head of the event queue */ |
| 12340 | spin_lock_irq(&phba->hbalock); |
| 12341 | list_remove_head(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue, |
| 12342 | cq_event, struct lpfc_cq_event, list); |
| 12343 | spin_unlock_irq(&phba->hbalock); |
| 12344 | /* Notify aborted XRI for NVME work queue */ |
| 12345 | if (phba->nvmet_support) { |
| 12346 | lpfc_sli4_nvmet_xri_aborted(phba, |
| 12347 | &cq_event->cqe.wcqe_axri); |
| 12348 | } else { |
| 12349 | lpfc_sli4_nvme_xri_aborted(phba, |
| 12350 | &cq_event->cqe.wcqe_axri); |
| 12351 | } |
| 12352 | /* Free the event processed back to the free pool */ |
| 12353 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12354 | } |
| 12355 | } |
| 12356 | |
| 12357 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12358 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12359 | * @phba: pointer to lpfc hba data structure. |
| 12360 | * |
| 12361 | * This routine is invoked by the worker thread to process all the pending |
| 12362 | * SLI4 els abort xri events. |
| 12363 | **/ |
| 12364 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12365 | { |
| 12366 | struct lpfc_cq_event *cq_event; |
| 12367 | |
| 12368 | /* First, declare the els xri abort event has been handled */ |
| 12369 | spin_lock_irq(&phba->hbalock); |
| 12370 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12371 | spin_unlock_irq(&phba->hbalock); |
| 12372 | /* Now, handle all the els xri abort events */ |
| 12373 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12374 | /* Get the first event from the head of the event queue */ |
| 12375 | spin_lock_irq(&phba->hbalock); |
| 12376 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12377 | cq_event, struct lpfc_cq_event, list); |
| 12378 | spin_unlock_irq(&phba->hbalock); |
| 12379 | /* Notify aborted XRI for ELS work queue */ |
| 12380 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12381 | /* Free the event processed back to the free pool */ |
| 12382 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12383 | } |
| 12384 | } |
| 12385 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12386 | /** |
| 12387 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12388 | * @phba: pointer to lpfc hba data structure |
| 12389 | * @pIocbIn: pointer to the rspiocbq |
| 12390 | * @pIocbOut: pointer to the cmdiocbq |
| 12391 | * @wcqe: pointer to the complete wcqe |
| 12392 | * |
| 12393 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12394 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12395 | * completion status information from the complete wcqe. |
| 12396 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12397 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12398 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12399 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12400 | struct lpfc_iocbq *pIocbOut, |
| 12401 | struct lpfc_wcqe_complete *wcqe) |
| 12402 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12403 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12404 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12405 | uint32_t status, max_response; |
| 12406 | struct lpfc_dmabuf *dmabuf; |
| 12407 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12408 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12409 | |
| 12410 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12411 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12412 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12413 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12414 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12415 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12416 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12417 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12418 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12419 | wcqe->total_data_placed; |
| 12420 | else |
| 12421 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12422 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12423 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12424 | switch (pIocbOut->iocb.ulpCommand) { |
| 12425 | case CMD_ELS_REQUEST64_CR: |
| 12426 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12427 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12428 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12429 | max_response = bde.tus.f.bdeSize; |
| 12430 | break; |
| 12431 | case CMD_GEN_REQUEST64_CR: |
| 12432 | max_response = 0; |
| 12433 | if (!pIocbOut->context3) |
| 12434 | break; |
| 12435 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12436 | sizeof(struct ulp_bde64); |
| 12437 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12438 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12439 | for (i = 0; i < numBdes; i++) { |
| 12440 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12441 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12442 | max_response += bde.tus.f.bdeSize; |
| 12443 | } |
| 12444 | break; |
| 12445 | default: |
| 12446 | max_response = wcqe->total_data_placed; |
| 12447 | break; |
| 12448 | } |
| 12449 | if (max_response < wcqe->total_data_placed) |
| 12450 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12451 | else |
| 12452 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12453 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12454 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12455 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12456 | /* Convert BG errors for completion status */ |
| 12457 | if (status == CQE_STATUS_DI_ERROR) { |
| 12458 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 12459 | |
| 12460 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 12461 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 12462 | else |
| 12463 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 12464 | |
| 12465 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 12466 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 12467 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12468 | BGS_GUARD_ERR_MASK; |
| 12469 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 12470 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12471 | BGS_APPTAG_ERR_MASK; |
| 12472 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 12473 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12474 | BGS_REFTAG_ERR_MASK; |
| 12475 | |
| 12476 | /* Check to see if there was any good data before the error */ |
| 12477 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 12478 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12479 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 12480 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 12481 | wcqe->total_data_placed; |
| 12482 | } |
| 12483 | |
| 12484 | /* |
| 12485 | * Set ALL the error bits to indicate we don't know what |
| 12486 | * type of error it is. |
| 12487 | */ |
| 12488 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 12489 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12490 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 12491 | BGS_GUARD_ERR_MASK); |
| 12492 | } |
| 12493 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12494 | /* Pick up HBA exchange busy condition */ |
| 12495 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 12496 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12497 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 12498 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12499 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12500 | } |
| 12501 | |
| 12502 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12503 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 12504 | * @phba: Pointer to HBA context object. |
| 12505 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12506 | * |
| 12507 | * This routine handles an ELS work-queue completion event and construct |
| 12508 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 12509 | * discovery engine to handle. |
| 12510 | * |
| 12511 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 12512 | **/ |
| 12513 | static struct lpfc_iocbq * |
| 12514 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 12515 | struct lpfc_iocbq *irspiocbq) |
| 12516 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12517 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12518 | struct lpfc_iocbq *cmdiocbq; |
| 12519 | struct lpfc_wcqe_complete *wcqe; |
| 12520 | unsigned long iflags; |
| 12521 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12522 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 27b1313 | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 12523 | if (unlikely(!pring)) |
| 12524 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12525 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12526 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12527 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12528 | pring->stats.iocb_event++; |
| 12529 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 12530 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 12531 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12532 | if (unlikely(!cmdiocbq)) { |
Dick Kennedy | 6d69765 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12533 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12534 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12535 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 6d69765 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12536 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 12537 | wcqe->word0, wcqe->total_data_placed, |
| 12538 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12539 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 12540 | return NULL; |
| 12541 | } |
| 12542 | |
Dick Kennedy | 6d69765 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12543 | /* Put the iocb back on the txcmplq */ |
| 12544 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 12545 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 12546 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12547 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12548 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12549 | |
| 12550 | return irspiocbq; |
| 12551 | } |
| 12552 | |
| 12553 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12554 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 12555 | * @phba: Pointer to HBA context object. |
| 12556 | * @cqe: Pointer to mailbox completion queue entry. |
| 12557 | * |
| 12558 | * This routine process a mailbox completion queue entry with asynchrous |
| 12559 | * event. |
| 12560 | * |
| 12561 | * Return: true if work posted to worker thread, otherwise false. |
| 12562 | **/ |
| 12563 | static bool |
| 12564 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 12565 | { |
| 12566 | struct lpfc_cq_event *cq_event; |
| 12567 | unsigned long iflags; |
| 12568 | |
| 12569 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12570 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 12571 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 12572 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 12573 | |
| 12574 | /* Allocate a new internal CQ_EVENT entry */ |
| 12575 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12576 | if (!cq_event) { |
| 12577 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12578 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 12579 | return false; |
| 12580 | } |
| 12581 | |
| 12582 | /* Move the CQE into an asynchronous event entry */ |
| 12583 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 12584 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12585 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 12586 | /* Set the async event flag */ |
| 12587 | phba->hba_flag |= ASYNC_EVENT; |
| 12588 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12589 | |
| 12590 | return true; |
| 12591 | } |
| 12592 | |
| 12593 | /** |
| 12594 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 12595 | * @phba: Pointer to HBA context object. |
| 12596 | * @cqe: Pointer to mailbox completion queue entry. |
| 12597 | * |
| 12598 | * This routine process a mailbox completion queue entry with mailbox |
| 12599 | * completion event. |
| 12600 | * |
| 12601 | * Return: true if work posted to worker thread, otherwise false. |
| 12602 | **/ |
| 12603 | static bool |
| 12604 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 12605 | { |
| 12606 | uint32_t mcqe_status; |
| 12607 | MAILBOX_t *mbox, *pmbox; |
| 12608 | struct lpfc_mqe *mqe; |
| 12609 | struct lpfc_vport *vport; |
| 12610 | struct lpfc_nodelist *ndlp; |
| 12611 | struct lpfc_dmabuf *mp; |
| 12612 | unsigned long iflags; |
| 12613 | LPFC_MBOXQ_t *pmb; |
| 12614 | bool workposted = false; |
| 12615 | int rc; |
| 12616 | |
| 12617 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 12618 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 12619 | goto out_no_mqe_complete; |
| 12620 | |
| 12621 | /* Get the reference to the active mbox command */ |
| 12622 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12623 | pmb = phba->sli.mbox_active; |
| 12624 | if (unlikely(!pmb)) { |
| 12625 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 12626 | "1832 No pending MBOX command to handle\n"); |
| 12627 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12628 | goto out_no_mqe_complete; |
| 12629 | } |
| 12630 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12631 | mqe = &pmb->u.mqe; |
| 12632 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 12633 | mbox = phba->mbox; |
| 12634 | vport = pmb->vport; |
| 12635 | |
| 12636 | /* Reset heartbeat timer */ |
| 12637 | phba->last_completion_time = jiffies; |
| 12638 | del_timer(&phba->sli.mbox_tmo); |
| 12639 | |
| 12640 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 12641 | if (pmb->mbox_cmpl && mbox) |
| 12642 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12643 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12644 | /* |
| 12645 | * For mcqe errors, conditionally move a modified error code to |
| 12646 | * the mbox so that the error will not be missed. |
| 12647 | */ |
| 12648 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 12649 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 12650 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 12651 | bf_set(lpfc_mqe_status, mqe, |
| 12652 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 12653 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12654 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12655 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12656 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 12657 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 12658 | mcqe_status, |
| 12659 | pmbox->un.varWords[0], 0); |
| 12660 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 12661 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 12662 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 12663 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 12664 | * RID of the PPI using the same mbox buffer. |
| 12665 | */ |
| 12666 | lpfc_unreg_login(phba, vport->vpi, |
| 12667 | pmbox->un.varWords[0], pmb); |
| 12668 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 12669 | pmb->context1 = mp; |
| 12670 | pmb->context2 = ndlp; |
| 12671 | pmb->vport = vport; |
| 12672 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 12673 | if (rc != MBX_BUSY) |
| 12674 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12675 | LOG_SLI, "0385 rc should " |
| 12676 | "have been MBX_BUSY\n"); |
| 12677 | if (rc != MBX_NOT_FINISHED) |
| 12678 | goto send_current_mbox; |
| 12679 | } |
| 12680 | } |
| 12681 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 12682 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 12683 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 12684 | |
| 12685 | /* There is mailbox completion work to do */ |
| 12686 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12687 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 12688 | phba->work_ha |= HA_MBATT; |
| 12689 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12690 | workposted = true; |
| 12691 | |
| 12692 | send_current_mbox: |
| 12693 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12694 | /* Release the mailbox command posting token */ |
| 12695 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 12696 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 12697 | phba->sli.mbox_active = NULL; |
| 12698 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12699 | /* Wake up worker thread to post the next pending mailbox command */ |
| 12700 | lpfc_worker_wake_up(phba); |
| 12701 | out_no_mqe_complete: |
| 12702 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 12703 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 12704 | return workposted; |
| 12705 | } |
| 12706 | |
| 12707 | /** |
| 12708 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 12709 | * @phba: Pointer to HBA context object. |
| 12710 | * @cqe: Pointer to mailbox completion queue entry. |
| 12711 | * |
| 12712 | * This routine process a mailbox completion queue entry, it invokes the |
| 12713 | * proper mailbox complete handling or asynchrous event handling routine |
| 12714 | * according to the MCQE's async bit. |
| 12715 | * |
| 12716 | * Return: true if work posted to worker thread, otherwise false. |
| 12717 | **/ |
| 12718 | static bool |
| 12719 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 12720 | { |
| 12721 | struct lpfc_mcqe mcqe; |
| 12722 | bool workposted; |
| 12723 | |
| 12724 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 12725 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 12726 | |
| 12727 | /* Invoke the proper event handling routine */ |
| 12728 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 12729 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 12730 | else |
| 12731 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 12732 | return workposted; |
| 12733 | } |
| 12734 | |
| 12735 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12736 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 12737 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12738 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12739 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12740 | * |
| 12741 | * This routine handles an ELS work-queue completion event. |
| 12742 | * |
| 12743 | * Return: true if work posted to worker thread, otherwise false. |
| 12744 | **/ |
| 12745 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12746 | 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] | 12747 | struct lpfc_wcqe_complete *wcqe) |
| 12748 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12749 | struct lpfc_iocbq *irspiocbq; |
| 12750 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12751 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12752 | int txq_cnt = 0; |
| 12753 | int txcmplq_cnt = 0; |
| 12754 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12755 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12756 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12757 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 12758 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12759 | if (!list_empty(&pring->txq)) |
| 12760 | txq_cnt++; |
| 12761 | if (!list_empty(&pring->txcmplq)) |
| 12762 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12763 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12764 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 12765 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12766 | txq_cnt, phba->iocb_cnt, |
| 12767 | fcp_txcmplq_cnt, |
| 12768 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12769 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12770 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12771 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12772 | /* Save off the slow-path queue event for work thread to process */ |
| 12773 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12774 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12775 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12776 | &phba->sli4_hba.sp_queue_event); |
| 12777 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12778 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12779 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12780 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12781 | } |
| 12782 | |
| 12783 | /** |
| 12784 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 12785 | * @phba: Pointer to HBA context object. |
| 12786 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12787 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 12788 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12789 | * proper WQ release routine to the slow-path WQ. |
| 12790 | **/ |
| 12791 | static void |
| 12792 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 12793 | struct lpfc_wcqe_release *wcqe) |
| 12794 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12795 | /* sanity check on queue memory */ |
| 12796 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 12797 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12798 | /* Check for the slow-path ELS work queue */ |
| 12799 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 12800 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 12801 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12802 | else |
| 12803 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12804 | "2579 Slow-path wqe consume event carries " |
| 12805 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 12806 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 12807 | phba->sli4_hba.els_wq->queue_id); |
| 12808 | } |
| 12809 | |
| 12810 | /** |
| 12811 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 12812 | * @phba: Pointer to HBA context object. |
| 12813 | * @cq: Pointer to a WQ completion queue. |
| 12814 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12815 | * |
| 12816 | * This routine handles an XRI abort event. |
| 12817 | * |
| 12818 | * Return: true if work posted to worker thread, otherwise false. |
| 12819 | **/ |
| 12820 | static bool |
| 12821 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 12822 | struct lpfc_queue *cq, |
| 12823 | struct sli4_wcqe_xri_aborted *wcqe) |
| 12824 | { |
| 12825 | bool workposted = false; |
| 12826 | struct lpfc_cq_event *cq_event; |
| 12827 | unsigned long iflags; |
| 12828 | |
| 12829 | /* Allocate a new internal CQ_EVENT entry */ |
| 12830 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12831 | if (!cq_event) { |
| 12832 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12833 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 12834 | return false; |
| 12835 | } |
| 12836 | |
| 12837 | /* Move the CQE into the proper xri abort event list */ |
| 12838 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 12839 | switch (cq->subtype) { |
| 12840 | case LPFC_FCP: |
| 12841 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12842 | list_add_tail(&cq_event->list, |
| 12843 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 12844 | /* Set the fcp xri abort event flag */ |
| 12845 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 12846 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12847 | workposted = true; |
| 12848 | break; |
| 12849 | case LPFC_ELS: |
| 12850 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12851 | list_add_tail(&cq_event->list, |
| 12852 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 12853 | /* Set the els xri abort event flag */ |
| 12854 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 12855 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12856 | workposted = true; |
| 12857 | break; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12858 | case LPFC_NVME: |
| 12859 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12860 | list_add_tail(&cq_event->list, |
| 12861 | &phba->sli4_hba.sp_nvme_xri_aborted_work_queue); |
| 12862 | /* Set the nvme xri abort event flag */ |
| 12863 | phba->hba_flag |= NVME_XRI_ABORT_EVENT; |
| 12864 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12865 | workposted = true; |
| 12866 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12867 | default: |
| 12868 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12869 | "0603 Invalid CQ subtype %d: " |
| 12870 | "%08x %08x %08x %08x\n", |
| 12871 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 12872 | wcqe->word2, wcqe->word3); |
| 12873 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12874 | workposted = false; |
| 12875 | break; |
| 12876 | } |
| 12877 | return workposted; |
| 12878 | } |
| 12879 | |
| 12880 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12881 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12882 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12883 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12884 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12885 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12886 | * |
| 12887 | * Return: true if work posted to worker thread, otherwise false. |
| 12888 | **/ |
| 12889 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12890 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 12891 | { |
| 12892 | bool workposted = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12893 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12894 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 12895 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12896 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12897 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12898 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12899 | unsigned long iflags; |
| 12900 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12901 | /* sanity check on queue memory */ |
| 12902 | if (unlikely(!hrq) || unlikely(!drq)) |
| 12903 | return workposted; |
| 12904 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12905 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 12906 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 12907 | else |
| 12908 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 12909 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12910 | goto out; |
| 12911 | |
| 12912 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 12913 | switch (status) { |
| 12914 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 12915 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12916 | "2537 Receive Frame Truncated!!\n"); |
| 12917 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 12918 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12919 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12920 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 12921 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12922 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12923 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12924 | goto out; |
| 12925 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12926 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12927 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12928 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12929 | |
| 12930 | /* If a NVME LS event (type 0x28), treat it as Fast path */ |
| 12931 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 12932 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12933 | /* save off the frame for the word thread to process */ |
| 12934 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12935 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12936 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12937 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12938 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12939 | workposted = true; |
| 12940 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12941 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12942 | if (phba->nvmet_support) { |
| 12943 | tgtp = phba->targetport->private; |
| 12944 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 12945 | "6402 RQE Error x%x, posted %d err_cnt " |
| 12946 | "%d: %x %x %x\n", |
| 12947 | status, hrq->RQ_buf_posted, |
| 12948 | hrq->RQ_no_posted_buf, |
| 12949 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 12950 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 12951 | atomic_read(&tgtp->xmt_fcp_release)); |
| 12952 | } |
| 12953 | /* fallthrough */ |
| 12954 | |
| 12955 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12956 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12957 | /* Post more buffers if possible */ |
| 12958 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12959 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 12960 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12961 | workposted = true; |
| 12962 | break; |
| 12963 | } |
| 12964 | out: |
| 12965 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12966 | } |
| 12967 | |
| 12968 | /** |
| 12969 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 12970 | * @phba: Pointer to HBA context object. |
| 12971 | * @cq: Pointer to the completion queue. |
| 12972 | * @wcqe: Pointer to a completion queue entry. |
| 12973 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12974 | * 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] | 12975 | * entry. |
| 12976 | * |
| 12977 | * Return: true if work posted to worker thread, otherwise false. |
| 12978 | **/ |
| 12979 | static bool |
| 12980 | 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] | 12981 | struct lpfc_cqe *cqe) |
| 12982 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12983 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12984 | bool workposted = false; |
| 12985 | |
| 12986 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12987 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12988 | |
| 12989 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12990 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12991 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12992 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12993 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12994 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12995 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12996 | break; |
| 12997 | case CQE_CODE_RELEASE_WQE: |
| 12998 | /* Process the WQ release event */ |
| 12999 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13000 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13001 | break; |
| 13002 | case CQE_CODE_XRI_ABORTED: |
| 13003 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13004 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13005 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13006 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13007 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13008 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13009 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13010 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13011 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13012 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13013 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13014 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13015 | default: |
| 13016 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13017 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13018 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13019 | break; |
| 13020 | } |
| 13021 | return workposted; |
| 13022 | } |
| 13023 | |
| 13024 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13025 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13026 | * @phba: Pointer to HBA context object. |
| 13027 | * @eqe: Pointer to fast-path event queue entry. |
| 13028 | * |
| 13029 | * This routine process a event queue entry from the slow-path event queue. |
| 13030 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13031 | * completion event on a completion queue, if not, an error shall be logged |
| 13032 | * and just return. Otherwise, it will get to the corresponding completion |
| 13033 | * queue and process all the entries on that completion queue, rearm the |
| 13034 | * completion queue, and then return. |
| 13035 | * |
| 13036 | **/ |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13037 | static int |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13038 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13039 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13040 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13041 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13042 | struct lpfc_cqe *cqe; |
| 13043 | bool workposted = false; |
| 13044 | int ecount = 0; |
| 13045 | uint16_t cqid; |
| 13046 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13047 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13048 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13049 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13050 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13051 | if (childq->queue_id == cqid) { |
| 13052 | cq = childq; |
| 13053 | break; |
| 13054 | } |
| 13055 | } |
| 13056 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13057 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13058 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13059 | "0365 Slow-path CQ identifier " |
| 13060 | "(%d) does not exist\n", cqid); |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13061 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13062 | } |
| 13063 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13064 | /* Save EQ associated with this CQ */ |
| 13065 | cq->assoc_qp = speq; |
| 13066 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13067 | /* Process all the entries to the CQ */ |
| 13068 | switch (cq->type) { |
| 13069 | case LPFC_MCQ: |
| 13070 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 13071 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13072 | if (!(++ecount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13073 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13074 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13075 | } |
| 13076 | break; |
| 13077 | case LPFC_WCQ: |
| 13078 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13079 | if ((cq->subtype == LPFC_FCP) || |
| 13080 | (cq->subtype == LPFC_NVME)) |
| 13081 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13082 | cqe); |
| 13083 | else |
| 13084 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 13085 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13086 | if (!(++ecount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13087 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13088 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13089 | |
| 13090 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13091 | if (ecount > cq->CQ_max_cqe) |
| 13092 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13093 | break; |
| 13094 | default: |
| 13095 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13096 | "0370 Invalid completion queue type (%d)\n", |
| 13097 | cq->type); |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13098 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13099 | } |
| 13100 | |
| 13101 | /* Catch the no cq entry condition, log an error */ |
| 13102 | if (unlikely(ecount == 0)) |
| 13103 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13104 | "0371 No entry from the CQ: identifier " |
| 13105 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 13106 | |
| 13107 | /* In any case, flash and re-arm the RCQ */ |
| 13108 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 13109 | |
| 13110 | /* wake up worker thread if there are works to be done */ |
| 13111 | if (workposted) |
| 13112 | lpfc_worker_wake_up(phba); |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13113 | |
| 13114 | return ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13115 | } |
| 13116 | |
| 13117 | /** |
| 13118 | * 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] | 13119 | * @phba: Pointer to HBA context object. |
| 13120 | * @cq: Pointer to associated CQ |
| 13121 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13122 | * |
| 13123 | * This routine process a fast-path work queue completion entry from fast-path |
| 13124 | * event queue for FCP command response completion. |
| 13125 | **/ |
| 13126 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13127 | 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] | 13128 | struct lpfc_wcqe_complete *wcqe) |
| 13129 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13130 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13131 | struct lpfc_iocbq *cmdiocbq; |
| 13132 | struct lpfc_iocbq irspiocbq; |
| 13133 | unsigned long iflags; |
| 13134 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13135 | /* Check for response status */ |
| 13136 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13137 | /* If resource errors reported from HBA, reduce queue |
| 13138 | * depth of the SCSI device. |
| 13139 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13140 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13141 | IOSTAT_LOCAL_REJECT)) && |
| 13142 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13143 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13144 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13145 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13146 | /* Log the error status */ |
| 13147 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13148 | "0373 FCP complete error: status=x%x, " |
| 13149 | "hw_status=x%x, total_data_specified=%d, " |
| 13150 | "parameter=x%x, word3=x%x\n", |
| 13151 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13152 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 13153 | wcqe->total_data_placed, wcqe->parameter, |
| 13154 | wcqe->word3); |
| 13155 | } |
| 13156 | |
| 13157 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13158 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13159 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13160 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13161 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13162 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13163 | if (unlikely(!cmdiocbq)) { |
| 13164 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13165 | "0374 FCP complete with no corresponding " |
| 13166 | "cmdiocb: iotag (%d)\n", |
| 13167 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13168 | return; |
| 13169 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13170 | |
| 13171 | if (cq->assoc_qp) |
| 13172 | cmdiocbq->isr_timestamp = |
| 13173 | cq->assoc_qp->isr_timestamp; |
| 13174 | |
| 13175 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13176 | if (cmdiocbq->wqe_cmpl) { |
| 13177 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13178 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13179 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13180 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13181 | } |
| 13182 | |
| 13183 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13184 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13185 | return; |
| 13186 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13187 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13188 | "0375 FCP cmdiocb not callback function " |
| 13189 | "iotag: (%d)\n", |
| 13190 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13191 | return; |
| 13192 | } |
| 13193 | |
| 13194 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13195 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13196 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13197 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13198 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13199 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13200 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13201 | } |
| 13202 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13203 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13204 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13205 | } |
| 13206 | |
| 13207 | /** |
| 13208 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13209 | * @phba: Pointer to HBA context object. |
| 13210 | * @cq: Pointer to completion queue. |
| 13211 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13212 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13213 | * This routine handles an fast-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13214 | * proper WQ release routine to the slow-path WQ. |
| 13215 | **/ |
| 13216 | static void |
| 13217 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13218 | struct lpfc_wcqe_release *wcqe) |
| 13219 | { |
| 13220 | struct lpfc_queue *childwq; |
| 13221 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13222 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13223 | |
| 13224 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13225 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13226 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13227 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13228 | lpfc_sli4_wq_release(childwq, |
| 13229 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13230 | wqid_matched = true; |
| 13231 | break; |
| 13232 | } |
| 13233 | } |
| 13234 | /* Report warning log message if no match found */ |
| 13235 | if (wqid_matched != true) |
| 13236 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13237 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13238 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13239 | } |
| 13240 | |
| 13241 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13242 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13243 | * @phba: Pointer to HBA context object. |
| 13244 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13245 | * |
| 13246 | * This routine process a receive-queue completion queue entry. |
| 13247 | * |
| 13248 | * Return: true if work posted to worker thread, otherwise false. |
| 13249 | **/ |
| 13250 | static bool |
| 13251 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13252 | struct lpfc_rcqe *rcqe) |
| 13253 | { |
| 13254 | bool workposted = false; |
| 13255 | struct lpfc_queue *hrq; |
| 13256 | struct lpfc_queue *drq; |
| 13257 | struct rqb_dmabuf *dma_buf; |
| 13258 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13259 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13260 | uint32_t status, rq_id; |
| 13261 | unsigned long iflags; |
| 13262 | uint32_t fctl, idx; |
| 13263 | |
| 13264 | if ((phba->nvmet_support == 0) || |
| 13265 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13266 | return workposted; |
| 13267 | |
| 13268 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13269 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13270 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13271 | |
| 13272 | /* sanity check on queue memory */ |
| 13273 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13274 | return workposted; |
| 13275 | |
| 13276 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13277 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13278 | else |
| 13279 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13280 | |
| 13281 | if ((phba->nvmet_support == 0) || |
| 13282 | (rq_id != hrq->queue_id)) |
| 13283 | return workposted; |
| 13284 | |
| 13285 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13286 | switch (status) { |
| 13287 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13288 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13289 | "6126 Receive Frame Truncated!!\n"); |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 13290 | /* Drop thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13291 | case FC_STATUS_RQ_SUCCESS: |
| 13292 | lpfc_sli4_rq_release(hrq, drq); |
| 13293 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13294 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13295 | if (!dma_buf) { |
| 13296 | hrq->RQ_no_buf_found++; |
| 13297 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13298 | goto out; |
| 13299 | } |
| 13300 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13301 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13302 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13303 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13304 | |
| 13305 | /* Just some basic sanity checks on FCP Command frame */ |
| 13306 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 13307 | fc_hdr->fh_f_ctl[1] << 8 | |
| 13308 | fc_hdr->fh_f_ctl[2]); |
| 13309 | if (((fctl & |
| 13310 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 13311 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 13312 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 13313 | goto drop; |
| 13314 | |
| 13315 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
| 13316 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13317 | lpfc_nvmet_unsol_fcp_event( |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 13318 | phba, idx, dma_buf, |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13319 | cq->assoc_qp->isr_timestamp); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13320 | return false; |
| 13321 | } |
| 13322 | drop: |
| 13323 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
| 13324 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13325 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13326 | if (phba->nvmet_support) { |
| 13327 | tgtp = phba->targetport->private; |
| 13328 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13329 | "6401 RQE Error x%x, posted %d err_cnt " |
| 13330 | "%d: %x %x %x\n", |
| 13331 | status, hrq->RQ_buf_posted, |
| 13332 | hrq->RQ_no_posted_buf, |
| 13333 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13334 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13335 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13336 | } |
| 13337 | /* fallthrough */ |
| 13338 | |
| 13339 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13340 | hrq->RQ_no_posted_buf++; |
| 13341 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13342 | break; |
| 13343 | } |
| 13344 | out: |
| 13345 | return workposted; |
| 13346 | } |
| 13347 | |
| 13348 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13349 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13350 | * @cq: Pointer to the completion queue. |
| 13351 | * @eqe: Pointer to fast-path completion queue entry. |
| 13352 | * |
| 13353 | * This routine process a fast-path work queue completion entry from fast-path |
| 13354 | * event queue for FCP command response completion. |
| 13355 | **/ |
| 13356 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13357 | lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13358 | struct lpfc_cqe *cqe) |
| 13359 | { |
| 13360 | struct lpfc_wcqe_release wcqe; |
| 13361 | bool workposted = false; |
| 13362 | |
| 13363 | /* Copy the work queue CQE and convert endian order if needed */ |
| 13364 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 13365 | |
| 13366 | /* Check and process for different type of WCQE and dispatch */ |
| 13367 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 13368 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13369 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13370 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13371 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 13372 | phba->last_completion_time = jiffies; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13373 | if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME)) |
| 13374 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
| 13375 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13376 | if (cq->subtype == LPFC_NVME_LS) |
| 13377 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13378 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13379 | break; |
| 13380 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13381 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13382 | /* Process the WQ release event */ |
| 13383 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 13384 | (struct lpfc_wcqe_release *)&wcqe); |
| 13385 | break; |
| 13386 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13387 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13388 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13389 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13390 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 13391 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 13392 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13393 | case CQE_CODE_RECEIVE_V1: |
| 13394 | case CQE_CODE_RECEIVE: |
| 13395 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13396 | if (cq->subtype == LPFC_NVMET) { |
| 13397 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 13398 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 13399 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13400 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13401 | default: |
| 13402 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13403 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13404 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 13405 | break; |
| 13406 | } |
| 13407 | return workposted; |
| 13408 | } |
| 13409 | |
| 13410 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13411 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13412 | * @phba: Pointer to HBA context object. |
| 13413 | * @eqe: Pointer to fast-path event queue entry. |
| 13414 | * |
| 13415 | * This routine process a event queue entry from the fast-path event queue. |
| 13416 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13417 | * completion event on a completion queue, if not, an error shall be logged |
| 13418 | * and just return. Otherwise, it will get to the corresponding completion |
| 13419 | * queue and process all the entries on the completion queue, rearm the |
| 13420 | * completion queue, and then return. |
| 13421 | **/ |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13422 | static int |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13423 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13424 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13425 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13426 | struct lpfc_queue *cq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13427 | struct lpfc_cqe *cqe; |
| 13428 | bool workposted = false; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13429 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13430 | int ecount = 0; |
| 13431 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13432 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13433 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13434 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13435 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13436 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 13437 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13438 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13439 | } |
| 13440 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13441 | /* Get the reference to the corresponding CQ */ |
| 13442 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 13443 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13444 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 13445 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13446 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 13447 | /* Process NVMET unsol rcv */ |
| 13448 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 13449 | goto process_cq; |
| 13450 | } |
| 13451 | } |
| 13452 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13453 | if (phba->sli4_hba.nvme_cq_map && |
| 13454 | (cqid == phba->sli4_hba.nvme_cq_map[qidx])) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 13455 | /* Process NVME / NVMET command completion */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13456 | cq = phba->sli4_hba.nvme_cq[qidx]; |
| 13457 | goto process_cq; |
| 13458 | } |
| 13459 | |
| 13460 | if (phba->sli4_hba.fcp_cq_map && |
| 13461 | (cqid == phba->sli4_hba.fcp_cq_map[qidx])) { |
| 13462 | /* Process FCP command completion */ |
| 13463 | cq = phba->sli4_hba.fcp_cq[qidx]; |
| 13464 | goto process_cq; |
| 13465 | } |
| 13466 | |
| 13467 | if (phba->sli4_hba.nvmels_cq && |
| 13468 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 13469 | /* Process NVME unsol rcv */ |
| 13470 | cq = phba->sli4_hba.nvmels_cq; |
| 13471 | } |
| 13472 | |
| 13473 | /* Otherwise this is a Slow path event */ |
| 13474 | if (cq == NULL) { |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13475 | ecount = lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 13476 | phba->sli4_hba.hba_eq[qidx]); |
| 13477 | return ecount; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13478 | } |
| 13479 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13480 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13481 | if (unlikely(cqid != cq->queue_id)) { |
| 13482 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13483 | "0368 Miss-matched fast-path completion " |
| 13484 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 13485 | cqid, cq->queue_id); |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13486 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13487 | } |
| 13488 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13489 | /* Save EQ associated with this CQ */ |
| 13490 | cq->assoc_qp = phba->sli4_hba.hba_eq[qidx]; |
| 13491 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13492 | /* Process all the entries to the CQ */ |
| 13493 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13494 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13495 | if (!(++ecount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13496 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13497 | } |
| 13498 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13499 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13500 | if (ecount > cq->CQ_max_cqe) |
| 13501 | cq->CQ_max_cqe = ecount; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 13502 | cq->assoc_qp->EQ_cqe_cnt += ecount; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13503 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13504 | /* Catch the no cq entry condition */ |
| 13505 | if (unlikely(ecount == 0)) |
| 13506 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13507 | "0369 No entry from fast-path completion " |
| 13508 | "queue fcpcqid=%d\n", cq->queue_id); |
| 13509 | |
| 13510 | /* In any case, flash and re-arm the CQ */ |
| 13511 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 13512 | |
| 13513 | /* wake up worker thread if there are works to be done */ |
| 13514 | if (workposted) |
| 13515 | lpfc_worker_wake_up(phba); |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13516 | |
| 13517 | return ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13518 | } |
| 13519 | |
| 13520 | static void |
| 13521 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13522 | { |
| 13523 | struct lpfc_eqe *eqe; |
| 13524 | |
| 13525 | /* walk all the EQ entries and drop on the floor */ |
| 13526 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 13527 | ; |
| 13528 | |
| 13529 | /* Clear and re-arm the EQ */ |
| 13530 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 13531 | } |
| 13532 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13533 | |
| 13534 | /** |
| 13535 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 13536 | * entry |
| 13537 | * @phba: Pointer to HBA context object. |
| 13538 | * @eqe: Pointer to fast-path event queue entry. |
| 13539 | * |
| 13540 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 13541 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 13542 | * is for a completion event on a completion queue, if not, an error shall be |
| 13543 | * logged and just return. Otherwise, it will get to the corresponding |
| 13544 | * completion queue and process all the entries on the completion queue, rearm |
| 13545 | * the completion queue, and then return. |
| 13546 | **/ |
| 13547 | static void |
| 13548 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 13549 | { |
| 13550 | struct lpfc_queue *cq; |
| 13551 | struct lpfc_cqe *cqe; |
| 13552 | bool workposted = false; |
| 13553 | uint16_t cqid; |
| 13554 | int ecount = 0; |
| 13555 | |
| 13556 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 13557 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13558 | "9147 Not a valid completion " |
| 13559 | "event: majorcode=x%x, minorcode=x%x\n", |
| 13560 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 13561 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 13562 | return; |
| 13563 | } |
| 13564 | |
| 13565 | /* Get the reference to the corresponding CQ */ |
| 13566 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 13567 | |
| 13568 | /* Next check for OAS */ |
| 13569 | cq = phba->sli4_hba.oas_cq; |
| 13570 | if (unlikely(!cq)) { |
| 13571 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13572 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13573 | "9148 OAS completion queue " |
| 13574 | "does not exist\n"); |
| 13575 | return; |
| 13576 | } |
| 13577 | |
| 13578 | if (unlikely(cqid != cq->queue_id)) { |
| 13579 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13580 | "9149 Miss-matched fast-path compl " |
| 13581 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 13582 | cqid, cq->queue_id); |
| 13583 | return; |
| 13584 | } |
| 13585 | |
James Smart | d41b65b | 2017-06-15 22:56:41 -0700 | [diff] [blame] | 13586 | /* Save EQ associated with this CQ */ |
| 13587 | cq->assoc_qp = phba->sli4_hba.fof_eq; |
| 13588 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13589 | /* Process all the entries to the OAS CQ */ |
| 13590 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13591 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13592 | if (!(++ecount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13593 | break; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13594 | } |
| 13595 | |
| 13596 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13597 | if (ecount > cq->CQ_max_cqe) |
| 13598 | cq->CQ_max_cqe = ecount; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 13599 | cq->assoc_qp->EQ_cqe_cnt += ecount; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13600 | |
| 13601 | /* Catch the no cq entry condition */ |
| 13602 | if (unlikely(ecount == 0)) |
| 13603 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13604 | "9153 No entry from fast-path completion " |
| 13605 | "queue fcpcqid=%d\n", cq->queue_id); |
| 13606 | |
| 13607 | /* In any case, flash and re-arm the CQ */ |
| 13608 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 13609 | |
| 13610 | /* wake up worker thread if there are works to be done */ |
| 13611 | if (workposted) |
| 13612 | lpfc_worker_wake_up(phba); |
| 13613 | } |
| 13614 | |
| 13615 | /** |
| 13616 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 13617 | * @irq: Interrupt number. |
| 13618 | * @dev_id: The device context pointer. |
| 13619 | * |
| 13620 | * This function is directly called from the PCI layer as an interrupt |
| 13621 | * service routine when device with SLI-4 interface spec is enabled with |
| 13622 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 13623 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 13624 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13625 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13626 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13627 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 13628 | * the intrrupt context. This function is called without any lock held. |
| 13629 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 13630 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 13631 | * equal to that of CQ index. |
| 13632 | * |
| 13633 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13634 | * returns IRQ_NONE. |
| 13635 | **/ |
| 13636 | irqreturn_t |
| 13637 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 13638 | { |
| 13639 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13640 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13641 | struct lpfc_queue *eq; |
| 13642 | struct lpfc_eqe *eqe; |
| 13643 | unsigned long iflag; |
| 13644 | int ecount = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13645 | |
| 13646 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13647 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 13648 | phba = hba_eq_hdl->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13649 | |
| 13650 | if (unlikely(!phba)) |
| 13651 | return IRQ_NONE; |
| 13652 | |
| 13653 | /* Get to the EQ struct associated with this vector */ |
| 13654 | eq = phba->sli4_hba.fof_eq; |
| 13655 | if (unlikely(!eq)) |
| 13656 | return IRQ_NONE; |
| 13657 | |
| 13658 | /* Check device state for handling interrupt */ |
| 13659 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13660 | /* Check again for link_state with lock held */ |
| 13661 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 13662 | if (phba->link_state < LPFC_LINK_DOWN) |
| 13663 | /* Flush, clear interrupt, and rearm the EQ */ |
| 13664 | lpfc_sli4_eq_flush(phba, eq); |
| 13665 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 13666 | return IRQ_NONE; |
| 13667 | } |
| 13668 | |
| 13669 | /* |
| 13670 | * Process all the event on FCP fast-path EQ |
| 13671 | */ |
| 13672 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 13673 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 13674 | if (!(++ecount % eq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13675 | break; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13676 | eq->EQ_processed++; |
| 13677 | } |
| 13678 | |
| 13679 | /* Track the max number of EQEs processed in 1 intr */ |
| 13680 | if (ecount > eq->EQ_max_eqe) |
| 13681 | eq->EQ_max_eqe = ecount; |
| 13682 | |
| 13683 | |
| 13684 | if (unlikely(ecount == 0)) { |
| 13685 | eq->EQ_no_entry++; |
| 13686 | |
| 13687 | if (phba->intr_type == MSIX) |
| 13688 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 13689 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13690 | "9145 MSI-X interrupt with no EQE\n"); |
| 13691 | else { |
| 13692 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13693 | "9146 ISR interrupt with no EQE\n"); |
| 13694 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 13695 | return IRQ_NONE; |
| 13696 | } |
| 13697 | } |
| 13698 | /* Always clear and re-arm the fast-path EQ */ |
| 13699 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 13700 | return IRQ_HANDLED; |
| 13701 | } |
| 13702 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13703 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13704 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13705 | * @irq: Interrupt number. |
| 13706 | * @dev_id: The device context pointer. |
| 13707 | * |
| 13708 | * This function is directly called from the PCI layer as an interrupt |
| 13709 | * service routine when device with SLI-4 interface spec is enabled with |
| 13710 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 13711 | * ring event in the HBA. However, when the device is enabled with either |
| 13712 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13713 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13714 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13715 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 13716 | * the intrrupt context. This function is called without any lock held. |
| 13717 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 13718 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 13719 | * equal to that of FCP CQ index. |
| 13720 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13721 | * The link attention and ELS ring attention events are handled |
| 13722 | * by the worker thread. The interrupt handler signals the worker thread |
| 13723 | * and returns for these events. This function is called without any lock |
| 13724 | * held. It gets the hbalock to access and update SLI data structures. |
| 13725 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13726 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13727 | * returns IRQ_NONE. |
| 13728 | **/ |
| 13729 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13730 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13731 | { |
| 13732 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13733 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13734 | struct lpfc_queue *fpeq; |
| 13735 | struct lpfc_eqe *eqe; |
| 13736 | unsigned long iflag; |
| 13737 | int ecount = 0; |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13738 | int ccount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13739 | int hba_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13740 | |
| 13741 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13742 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 13743 | phba = hba_eq_hdl->phba; |
| 13744 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13745 | |
| 13746 | if (unlikely(!phba)) |
| 13747 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13748 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13749 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13750 | |
| 13751 | /* Get to the EQ struct associated with this vector */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13752 | fpeq = phba->sli4_hba.hba_eq[hba_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13753 | if (unlikely(!fpeq)) |
| 13754 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13755 | |
James Smart | bd2cdd5 | 2017-02-12 13:52:33 -0800 | [diff] [blame] | 13756 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13757 | if (phba->ktime_on) |
| 13758 | fpeq->isr_timestamp = ktime_get_ns(); |
| 13759 | #endif |
| 13760 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13761 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13762 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13763 | lpfc_sli4_eq_clr_intr(fpeq); |
| 13764 | else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13765 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13766 | return IRQ_NONE; |
| 13767 | } |
| 13768 | } |
| 13769 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13770 | /* Check device state for handling interrupt */ |
| 13771 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 13772 | /* Check again for link_state with lock held */ |
| 13773 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 13774 | if (phba->link_state < LPFC_LINK_DOWN) |
| 13775 | /* Flush, clear interrupt, and rearm the EQ */ |
| 13776 | lpfc_sli4_eq_flush(phba, fpeq); |
| 13777 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13778 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13779 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13780 | return IRQ_NONE; |
| 13781 | } |
| 13782 | |
| 13783 | /* |
| 13784 | * Process all the event on FCP fast-path EQ |
| 13785 | */ |
| 13786 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 13787 | if (eqe == NULL) |
| 13788 | break; |
| 13789 | |
Dick Kennedy | e3e2863 | 2017-08-23 16:55:41 -0700 | [diff] [blame] | 13790 | ccount += lpfc_sli4_hba_handle_eqe(phba, eqe, hba_eqidx); |
| 13791 | if (!(++ecount % fpeq->entry_repost) || |
| 13792 | ccount > LPFC_MAX_ISR_CQE) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13793 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13794 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13795 | } |
| 13796 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13797 | /* Track the max number of EQEs processed in 1 intr */ |
| 13798 | if (ecount > fpeq->EQ_max_eqe) |
| 13799 | fpeq->EQ_max_eqe = ecount; |
| 13800 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13801 | /* Always clear and re-arm the fast-path EQ */ |
| 13802 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 13803 | |
| 13804 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13805 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13806 | |
| 13807 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13808 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13809 | return IRQ_NONE; |
| 13810 | } |
| 13811 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13812 | if (phba->intr_type == MSIX) |
| 13813 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 13814 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13815 | "0358 MSI-X interrupt with no EQE\n"); |
| 13816 | else |
| 13817 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 13818 | return IRQ_NONE; |
| 13819 | } |
| 13820 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13821 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13822 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
| 13823 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13824 | return IRQ_HANDLED; |
| 13825 | } /* lpfc_sli4_fp_intr_handler */ |
| 13826 | |
| 13827 | /** |
| 13828 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 13829 | * @irq: Interrupt number. |
| 13830 | * @dev_id: The device context pointer. |
| 13831 | * |
| 13832 | * This function is the device-level interrupt handler to device with SLI-4 |
| 13833 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 13834 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 13835 | * driver attention. This function invokes the slow-path interrupt attention |
| 13836 | * handling function and fast-path interrupt attention handling function in |
| 13837 | * turn to process the relevant HBA attention events. This function is called |
| 13838 | * without any lock held. It gets the hbalock to access and update SLI data |
| 13839 | * structures. |
| 13840 | * |
| 13841 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 13842 | * returns IRQ_NONE. |
| 13843 | **/ |
| 13844 | irqreturn_t |
| 13845 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 13846 | { |
| 13847 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13848 | irqreturn_t hba_irq_rc; |
| 13849 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13850 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13851 | |
| 13852 | /* Get the driver's phba structure from the dev_id */ |
| 13853 | phba = (struct lpfc_hba *)dev_id; |
| 13854 | |
| 13855 | if (unlikely(!phba)) |
| 13856 | return IRQ_NONE; |
| 13857 | |
| 13858 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13859 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 13860 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13861 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13862 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13863 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13864 | if (hba_irq_rc == IRQ_HANDLED) |
| 13865 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13866 | } |
| 13867 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13868 | if (phba->cfg_fof) { |
| 13869 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13870 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13871 | if (hba_irq_rc == IRQ_HANDLED) |
| 13872 | hba_handled |= true; |
| 13873 | } |
| 13874 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13875 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13876 | } /* lpfc_sli4_intr_handler */ |
| 13877 | |
| 13878 | /** |
| 13879 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 13880 | * @queue: The queue structure to free. |
| 13881 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 13882 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13883 | * the host resident queue. This function must be called after destroying the |
| 13884 | * queue on the HBA. |
| 13885 | **/ |
| 13886 | void |
| 13887 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 13888 | { |
| 13889 | struct lpfc_dmabuf *dmabuf; |
| 13890 | |
| 13891 | if (!queue) |
| 13892 | return; |
| 13893 | |
| 13894 | while (!list_empty(&queue->page_list)) { |
| 13895 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 13896 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13897 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13898 | dmabuf->virt, dmabuf->phys); |
| 13899 | kfree(dmabuf); |
| 13900 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13901 | if (queue->rqbp) { |
| 13902 | lpfc_free_rq_buffer(queue->phba, queue); |
| 13903 | kfree(queue->rqbp); |
| 13904 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 13905 | |
| 13906 | if (!list_empty(&queue->wq_list)) |
| 13907 | list_del(&queue->wq_list); |
| 13908 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13909 | kfree(queue); |
| 13910 | return; |
| 13911 | } |
| 13912 | |
| 13913 | /** |
| 13914 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 13915 | * @phba: The HBA that this queue is being created on. |
| 13916 | * @entry_size: The size of each queue entry for this queue. |
| 13917 | * @entry count: The number of entries that this queue will handle. |
| 13918 | * |
| 13919 | * This function allocates a queue structure and the DMAable memory used for |
| 13920 | * the host resident queue. This function must be called before creating the |
| 13921 | * queue on the HBA. |
| 13922 | **/ |
| 13923 | struct lpfc_queue * |
| 13924 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 13925 | uint32_t entry_count) |
| 13926 | { |
| 13927 | struct lpfc_queue *queue; |
| 13928 | struct lpfc_dmabuf *dmabuf; |
| 13929 | int x, total_qe_count; |
| 13930 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13931 | 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] | 13932 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13933 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13934 | hw_page_size = SLI4_PAGE_SIZE; |
| 13935 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13936 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 13937 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 13938 | if (!queue) |
| 13939 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13940 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 13941 | hw_page_size))/hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13942 | |
| 13943 | /* If needed, Adjust page count to match the max the adapter supports */ |
Ewan D. Milne | 0840feb | 2018-12-13 15:25:16 -0500 | [diff] [blame] | 13944 | if (phba->sli4_hba.pc_sli4_params.wqpcnt && |
| 13945 | (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13946 | queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 13947 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13948 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13949 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13950 | INIT_LIST_HEAD(&queue->page_list); |
| 13951 | INIT_LIST_HEAD(&queue->child_list); |
| 13952 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 13953 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 13954 | if (!dmabuf) |
| 13955 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 13956 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 13957 | hw_page_size, &dmabuf->phys, |
| 13958 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13959 | if (!dmabuf->virt) { |
| 13960 | kfree(dmabuf); |
| 13961 | goto out_fail; |
| 13962 | } |
| 13963 | dmabuf->buffer_tag = x; |
| 13964 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 13965 | /* initialize queue's entry array */ |
| 13966 | dma_pointer = dmabuf->virt; |
| 13967 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13968 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13969 | total_qe_count++, dma_pointer += entry_size) { |
| 13970 | queue->qe[total_qe_count].address = dma_pointer; |
| 13971 | } |
| 13972 | } |
| 13973 | queue->entry_size = entry_size; |
| 13974 | queue->entry_count = entry_count; |
| 13975 | queue->phba = phba; |
| 13976 | |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 13977 | /* entry_repost will be set during q creation */ |
| 13978 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13979 | return queue; |
| 13980 | out_fail: |
| 13981 | lpfc_sli4_queue_free(queue); |
| 13982 | return NULL; |
| 13983 | } |
| 13984 | |
| 13985 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13986 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 13987 | * @phba: HBA structure that indicates port to create a queue on. |
| 13988 | * @pci_barset: PCI BAR set flag. |
| 13989 | * |
| 13990 | * This function shall perform iomap of the specified PCI BAR address to host |
| 13991 | * memory address if not already done so and return it. The returned host |
| 13992 | * memory address can be NULL. |
| 13993 | */ |
| 13994 | static void __iomem * |
| 13995 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 13996 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13997 | if (!phba->pcidev) |
| 13998 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13999 | |
| 14000 | switch (pci_barset) { |
| 14001 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14002 | return phba->pci_bar0_memmap_p; |
| 14003 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14004 | return phba->pci_bar2_memmap_p; |
| 14005 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14006 | return phba->pci_bar4_memmap_p; |
| 14007 | default: |
| 14008 | break; |
| 14009 | } |
| 14010 | return NULL; |
| 14011 | } |
| 14012 | |
| 14013 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14014 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14015 | * @phba: HBA structure that indicates port to create a queue on. |
| 14016 | * @startq: The starting FCP EQ to modify |
| 14017 | * |
| 14018 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 14019 | * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be |
| 14020 | * updated in one mailbox command. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14021 | * |
| 14022 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 14023 | * is used to get the starting FCP EQ to change. |
| 14024 | * This function is asynchronous and will wait for the mailbox |
| 14025 | * command to finish before continuing. |
| 14026 | * |
| 14027 | * On success this function will return a zero. If unable to allocate enough |
| 14028 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14029 | * fails this function will return -ENXIO. |
| 14030 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14031 | int |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14032 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
| 14033 | uint32_t numq, uint32_t imax) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14034 | { |
| 14035 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14036 | LPFC_MBOXQ_t *mbox; |
| 14037 | struct lpfc_queue *eq; |
| 14038 | int cnt, rc, length, status = 0; |
| 14039 | uint32_t shdr_status, shdr_add_status; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14040 | uint32_t result, val; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14041 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14042 | union lpfc_sli4_cfg_shdr *shdr; |
| 14043 | uint16_t dmult; |
| 14044 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14045 | if (startq >= phba->io_channel_irqs) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14046 | return 0; |
| 14047 | |
| 14048 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14049 | if (!mbox) |
| 14050 | return -ENOMEM; |
| 14051 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14052 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14053 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14054 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14055 | length, LPFC_SLI4_MBX_EMBED); |
| 14056 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14057 | |
| 14058 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14059 | result = imax / phba->io_channel_irqs; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14060 | if (result > LPFC_DMULT_CONST || result == 0) |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14061 | dmult = 0; |
| 14062 | else |
| 14063 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14064 | if (dmult > LPFC_DMULT_MAX) |
| 14065 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14066 | |
| 14067 | cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14068 | for (qidx = startq; qidx < phba->io_channel_irqs; qidx++) { |
| 14069 | eq = phba->sli4_hba.hba_eq[qidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14070 | if (!eq) |
| 14071 | continue; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14072 | eq->q_mode = imax; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14073 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14074 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14075 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 14076 | cnt++; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14077 | |
| 14078 | /* q_mode is only used for auto_imax */ |
| 14079 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14080 | /* Use EQ Delay Register method for q_mode */ |
| 14081 | |
| 14082 | /* Convert for EQ Delay register */ |
| 14083 | val = phba->cfg_fcp_imax; |
| 14084 | if (val) { |
| 14085 | /* First, interrupts per sec per EQ */ |
| 14086 | val = phba->cfg_fcp_imax / |
| 14087 | phba->io_channel_irqs; |
| 14088 | |
| 14089 | /* us delay between each interrupt */ |
| 14090 | val = LPFC_SEC_TO_USEC / val; |
| 14091 | } |
| 14092 | eq->q_mode = val; |
| 14093 | } else { |
| 14094 | eq->q_mode = imax; |
| 14095 | } |
| 14096 | |
| 14097 | if (cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14098 | break; |
| 14099 | } |
| 14100 | eq_delay->u.request.num_eq = cnt; |
| 14101 | |
| 14102 | mbox->vport = phba->pport; |
| 14103 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14104 | mbox->context1 = NULL; |
| 14105 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14106 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14107 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14108 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14109 | if (shdr_status || shdr_add_status || rc) { |
| 14110 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14111 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14112 | "status x%x add_status x%x, mbx status x%x\n", |
| 14113 | shdr_status, shdr_add_status, rc); |
| 14114 | status = -ENXIO; |
| 14115 | } |
| 14116 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14117 | return status; |
| 14118 | } |
| 14119 | |
| 14120 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14121 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14122 | * @phba: HBA structure that indicates port to create a queue on. |
| 14123 | * @eq: The queue structure to use to create the event queue. |
| 14124 | * @imax: The maximum interrupt per second limit. |
| 14125 | * |
| 14126 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14127 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14128 | * |
| 14129 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14130 | * is used to get the entry count and entry size that are necessary to |
| 14131 | * determine the number of pages to allocate and use for this queue. This |
| 14132 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14133 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14134 | * command to finish before continuing. |
| 14135 | * |
| 14136 | * 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] | 14137 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14138 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14139 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14140 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14141 | 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] | 14142 | { |
| 14143 | struct lpfc_mbx_eq_create *eq_create; |
| 14144 | LPFC_MBOXQ_t *mbox; |
| 14145 | int rc, length, status = 0; |
| 14146 | struct lpfc_dmabuf *dmabuf; |
| 14147 | uint32_t shdr_status, shdr_add_status; |
| 14148 | union lpfc_sli4_cfg_shdr *shdr; |
| 14149 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14150 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14151 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14152 | /* sanity check on queue memory */ |
| 14153 | if (!eq) |
| 14154 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14155 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14156 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14157 | |
| 14158 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14159 | if (!mbox) |
| 14160 | return -ENOMEM; |
| 14161 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14162 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14163 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14164 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14165 | length, LPFC_SLI4_MBX_EMBED); |
| 14166 | eq_create = &mbox->u.mqe.un.eq_create; |
| 14167 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14168 | eq->page_count); |
| 14169 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14170 | LPFC_EQE_SIZE); |
| 14171 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14172 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14173 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14174 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14175 | dmult); |
| 14176 | switch (eq->entry_count) { |
| 14177 | default: |
| 14178 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14179 | "0360 Unsupported EQ count. (%d)\n", |
| 14180 | eq->entry_count); |
| 14181 | if (eq->entry_count < 256) |
| 14182 | return -EINVAL; |
| 14183 | /* otherwise default to smallest count (drop through) */ |
| 14184 | case 256: |
| 14185 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14186 | LPFC_EQ_CNT_256); |
| 14187 | break; |
| 14188 | case 512: |
| 14189 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14190 | LPFC_EQ_CNT_512); |
| 14191 | break; |
| 14192 | case 1024: |
| 14193 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14194 | LPFC_EQ_CNT_1024); |
| 14195 | break; |
| 14196 | case 2048: |
| 14197 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14198 | LPFC_EQ_CNT_2048); |
| 14199 | break; |
| 14200 | case 4096: |
| 14201 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14202 | LPFC_EQ_CNT_4096); |
| 14203 | break; |
| 14204 | } |
| 14205 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14206 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14207 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14208 | putPaddrLow(dmabuf->phys); |
| 14209 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14210 | putPaddrHigh(dmabuf->phys); |
| 14211 | } |
| 14212 | mbox->vport = phba->pport; |
| 14213 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14214 | mbox->context1 = NULL; |
| 14215 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14216 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 14217 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14218 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14219 | if (shdr_status || shdr_add_status || rc) { |
| 14220 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14221 | "2500 EQ_CREATE mailbox failed with " |
| 14222 | "status x%x add_status x%x, mbx status x%x\n", |
| 14223 | shdr_status, shdr_add_status, rc); |
| 14224 | status = -ENXIO; |
| 14225 | } |
| 14226 | eq->type = LPFC_EQ; |
| 14227 | eq->subtype = LPFC_NONE; |
| 14228 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14229 | if (eq->queue_id == 0xFFFF) |
| 14230 | status = -ENXIO; |
| 14231 | eq->host_index = 0; |
| 14232 | eq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14233 | eq->entry_repost = LPFC_EQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14234 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14235 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14236 | return status; |
| 14237 | } |
| 14238 | |
| 14239 | /** |
| 14240 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14241 | * @phba: HBA structure that indicates port to create a queue on. |
| 14242 | * @cq: The queue structure to use to create the completion queue. |
| 14243 | * @eq: The event queue to bind this completion queue to. |
| 14244 | * |
| 14245 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14246 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14247 | * |
| 14248 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14249 | * is used to get the entry count and entry size that are necessary to |
| 14250 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14251 | * is used to indicate which event queue to bind this completion queue to. This |
| 14252 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14253 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14254 | * command to finish before continuing. |
| 14255 | * |
| 14256 | * 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] | 14257 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14258 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14259 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14260 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14261 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14262 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14263 | { |
| 14264 | struct lpfc_mbx_cq_create *cq_create; |
| 14265 | struct lpfc_dmabuf *dmabuf; |
| 14266 | LPFC_MBOXQ_t *mbox; |
| 14267 | int rc, length, status = 0; |
| 14268 | uint32_t shdr_status, shdr_add_status; |
| 14269 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14270 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14271 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14272 | /* sanity check on queue memory */ |
| 14273 | if (!cq || !eq) |
| 14274 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14275 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14276 | hw_page_size = SLI4_PAGE_SIZE; |
| 14277 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14278 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14279 | if (!mbox) |
| 14280 | return -ENOMEM; |
| 14281 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14282 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14283 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14284 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14285 | length, LPFC_SLI4_MBX_EMBED); |
| 14286 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14287 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14288 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14289 | cq->page_count); |
| 14290 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14291 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14292 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14293 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14294 | 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] | 14295 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 14296 | 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] | 14297 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14298 | eq->queue_id); |
| 14299 | } else { |
| 14300 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14301 | eq->queue_id); |
| 14302 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14303 | switch (cq->entry_count) { |
| 14304 | default: |
| 14305 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14306 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14307 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14308 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14309 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14310 | if (cq->entry_count < 256) { |
| 14311 | status = -EINVAL; |
| 14312 | goto out; |
| 14313 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14314 | /* otherwise default to smallest count (drop through) */ |
| 14315 | case 256: |
| 14316 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14317 | LPFC_CQ_CNT_256); |
| 14318 | break; |
| 14319 | case 512: |
| 14320 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14321 | LPFC_CQ_CNT_512); |
| 14322 | break; |
| 14323 | case 1024: |
| 14324 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14325 | LPFC_CQ_CNT_1024); |
| 14326 | break; |
| 14327 | } |
| 14328 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14329 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14330 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14331 | putPaddrLow(dmabuf->phys); |
| 14332 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14333 | putPaddrHigh(dmabuf->phys); |
| 14334 | } |
| 14335 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14336 | |
| 14337 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14338 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14339 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14340 | if (shdr_status || shdr_add_status || rc) { |
| 14341 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14342 | "2501 CQ_CREATE mailbox failed with " |
| 14343 | "status x%x add_status x%x, mbx status x%x\n", |
| 14344 | shdr_status, shdr_add_status, rc); |
| 14345 | status = -ENXIO; |
| 14346 | goto out; |
| 14347 | } |
| 14348 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 14349 | if (cq->queue_id == 0xFFFF) { |
| 14350 | status = -ENXIO; |
| 14351 | goto out; |
| 14352 | } |
| 14353 | /* link the cq onto the parent eq child list */ |
| 14354 | list_add_tail(&cq->list, &eq->child_list); |
| 14355 | /* Set up completion queue's type and subtype */ |
| 14356 | cq->type = type; |
| 14357 | cq->subtype = subtype; |
| 14358 | 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] | 14359 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14360 | cq->host_index = 0; |
| 14361 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14362 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14363 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14364 | out: |
| 14365 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14366 | return status; |
| 14367 | } |
| 14368 | |
| 14369 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14370 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 14371 | * @phba: HBA structure that indicates port to create a queue on. |
| 14372 | * @cqp: The queue structure array to use to create the completion queues. |
| 14373 | * @eqp: The event queue array to bind these completion queues to. |
| 14374 | * |
| 14375 | * This function creates a set of completion queue, s to support MRQ |
| 14376 | * as detailed in @cqp, on a port, |
| 14377 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 14378 | * |
| 14379 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14380 | * is used to get the entry count and entry size that are necessary to |
| 14381 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14382 | * is used to indicate which event queue to bind this completion queue to. This |
| 14383 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 14384 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14385 | * command to finish before continuing. |
| 14386 | * |
| 14387 | * On success this function will return a zero. If unable to allocate enough |
| 14388 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14389 | * fails this function will return -ENXIO. |
| 14390 | **/ |
| 14391 | int |
| 14392 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
| 14393 | struct lpfc_queue **eqp, uint32_t type, uint32_t subtype) |
| 14394 | { |
| 14395 | struct lpfc_queue *cq; |
| 14396 | struct lpfc_queue *eq; |
| 14397 | struct lpfc_mbx_cq_create_set *cq_set; |
| 14398 | struct lpfc_dmabuf *dmabuf; |
| 14399 | LPFC_MBOXQ_t *mbox; |
| 14400 | int rc, length, alloclen, status = 0; |
| 14401 | int cnt, idx, numcq, page_idx = 0; |
| 14402 | uint32_t shdr_status, shdr_add_status; |
| 14403 | union lpfc_sli4_cfg_shdr *shdr; |
| 14404 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14405 | |
| 14406 | /* sanity check on queue memory */ |
| 14407 | numcq = phba->cfg_nvmet_mrq; |
| 14408 | if (!cqp || !eqp || !numcq) |
| 14409 | return -ENODEV; |
| 14410 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14411 | hw_page_size = SLI4_PAGE_SIZE; |
| 14412 | |
| 14413 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14414 | if (!mbox) |
| 14415 | return -ENOMEM; |
| 14416 | |
| 14417 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 14418 | length += ((numcq * cqp[0]->page_count) * |
| 14419 | sizeof(struct dma_address)); |
| 14420 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14421 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 14422 | LPFC_SLI4_MBX_NEMBED); |
| 14423 | if (alloclen < length) { |
| 14424 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14425 | "3098 Allocated DMA memory size (%d) is " |
| 14426 | "less than the requested DMA memory size " |
| 14427 | "(%d)\n", alloclen, length); |
| 14428 | status = -ENOMEM; |
| 14429 | goto out; |
| 14430 | } |
| 14431 | cq_set = mbox->sge_array->addr[0]; |
| 14432 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 14433 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 14434 | |
| 14435 | for (idx = 0; idx < numcq; idx++) { |
| 14436 | cq = cqp[idx]; |
| 14437 | eq = eqp[idx]; |
| 14438 | if (!cq || !eq) { |
| 14439 | status = -ENOMEM; |
| 14440 | goto out; |
| 14441 | } |
| 14442 | |
| 14443 | switch (idx) { |
| 14444 | case 0: |
| 14445 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 14446 | &cq_set->u.request, |
| 14447 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 14448 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 14449 | &cq_set->u.request, cq->page_count); |
| 14450 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 14451 | &cq_set->u.request, 1); |
| 14452 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 14453 | &cq_set->u.request, 1); |
| 14454 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 14455 | &cq_set->u.request, 0); |
| 14456 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 14457 | &cq_set->u.request, numcq); |
| 14458 | switch (cq->entry_count) { |
| 14459 | default: |
| 14460 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14461 | "3118 Bad CQ count. (%d)\n", |
| 14462 | cq->entry_count); |
| 14463 | if (cq->entry_count < 256) { |
| 14464 | status = -EINVAL; |
| 14465 | goto out; |
| 14466 | } |
| 14467 | /* otherwise default to smallest (drop thru) */ |
| 14468 | case 256: |
| 14469 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14470 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 14471 | break; |
| 14472 | case 512: |
| 14473 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14474 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 14475 | break; |
| 14476 | case 1024: |
| 14477 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14478 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 14479 | break; |
| 14480 | } |
| 14481 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 14482 | &cq_set->u.request, eq->queue_id); |
| 14483 | break; |
| 14484 | case 1: |
| 14485 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 14486 | &cq_set->u.request, eq->queue_id); |
| 14487 | break; |
| 14488 | case 2: |
| 14489 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 14490 | &cq_set->u.request, eq->queue_id); |
| 14491 | break; |
| 14492 | case 3: |
| 14493 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 14494 | &cq_set->u.request, eq->queue_id); |
| 14495 | break; |
| 14496 | case 4: |
| 14497 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 14498 | &cq_set->u.request, eq->queue_id); |
| 14499 | break; |
| 14500 | case 5: |
| 14501 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 14502 | &cq_set->u.request, eq->queue_id); |
| 14503 | break; |
| 14504 | case 6: |
| 14505 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 14506 | &cq_set->u.request, eq->queue_id); |
| 14507 | break; |
| 14508 | case 7: |
| 14509 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 14510 | &cq_set->u.request, eq->queue_id); |
| 14511 | break; |
| 14512 | case 8: |
| 14513 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 14514 | &cq_set->u.request, eq->queue_id); |
| 14515 | break; |
| 14516 | case 9: |
| 14517 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 14518 | &cq_set->u.request, eq->queue_id); |
| 14519 | break; |
| 14520 | case 10: |
| 14521 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 14522 | &cq_set->u.request, eq->queue_id); |
| 14523 | break; |
| 14524 | case 11: |
| 14525 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 14526 | &cq_set->u.request, eq->queue_id); |
| 14527 | break; |
| 14528 | case 12: |
| 14529 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 14530 | &cq_set->u.request, eq->queue_id); |
| 14531 | break; |
| 14532 | case 13: |
| 14533 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 14534 | &cq_set->u.request, eq->queue_id); |
| 14535 | break; |
| 14536 | case 14: |
| 14537 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 14538 | &cq_set->u.request, eq->queue_id); |
| 14539 | break; |
| 14540 | case 15: |
| 14541 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 14542 | &cq_set->u.request, eq->queue_id); |
| 14543 | break; |
| 14544 | } |
| 14545 | |
| 14546 | /* link the cq onto the parent eq child list */ |
| 14547 | list_add_tail(&cq->list, &eq->child_list); |
| 14548 | /* Set up completion queue's type and subtype */ |
| 14549 | cq->type = type; |
| 14550 | cq->subtype = subtype; |
| 14551 | cq->assoc_qid = eq->queue_id; |
| 14552 | cq->host_index = 0; |
| 14553 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14554 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14555 | |
| 14556 | rc = 0; |
| 14557 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 14558 | memset(dmabuf->virt, 0, hw_page_size); |
| 14559 | cnt = page_idx + dmabuf->buffer_tag; |
| 14560 | cq_set->u.request.page[cnt].addr_lo = |
| 14561 | putPaddrLow(dmabuf->phys); |
| 14562 | cq_set->u.request.page[cnt].addr_hi = |
| 14563 | putPaddrHigh(dmabuf->phys); |
| 14564 | rc++; |
| 14565 | } |
| 14566 | page_idx += rc; |
| 14567 | } |
| 14568 | |
| 14569 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14570 | |
| 14571 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14572 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14573 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14574 | if (shdr_status || shdr_add_status || rc) { |
| 14575 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14576 | "3119 CQ_CREATE_SET mailbox failed with " |
| 14577 | "status x%x add_status x%x, mbx status x%x\n", |
| 14578 | shdr_status, shdr_add_status, rc); |
| 14579 | status = -ENXIO; |
| 14580 | goto out; |
| 14581 | } |
| 14582 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 14583 | if (rc == 0xFFFF) { |
| 14584 | status = -ENXIO; |
| 14585 | goto out; |
| 14586 | } |
| 14587 | |
| 14588 | for (idx = 0; idx < numcq; idx++) { |
| 14589 | cq = cqp[idx]; |
| 14590 | cq->queue_id = rc + idx; |
| 14591 | } |
| 14592 | |
| 14593 | out: |
| 14594 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14595 | return status; |
| 14596 | } |
| 14597 | |
| 14598 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14599 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14600 | * @phba: HBA structure that indicates port to create a queue on. |
| 14601 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14602 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 14603 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14604 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14605 | * This function provides failback (fb) functionality when the |
| 14606 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 14607 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14608 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14609 | * This routine cannot fail as all attributes were previously accessed and |
| 14610 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14611 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14612 | static void |
| 14613 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 14614 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14615 | { |
| 14616 | struct lpfc_mbx_mq_create *mq_create; |
| 14617 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14618 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14619 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14620 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 14621 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14622 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14623 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 14624 | length, LPFC_SLI4_MBX_EMBED); |
| 14625 | mq_create = &mbox->u.mqe.un.mq_create; |
| 14626 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14627 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14628 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14629 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14630 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 14631 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14632 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14633 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14634 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14635 | break; |
| 14636 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14637 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14638 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14639 | break; |
| 14640 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14641 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14642 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14643 | break; |
| 14644 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14645 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14646 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14647 | break; |
| 14648 | } |
| 14649 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 14650 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14651 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14652 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14653 | putPaddrHigh(dmabuf->phys); |
| 14654 | } |
| 14655 | } |
| 14656 | |
| 14657 | /** |
| 14658 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 14659 | * @phba: HBA structure that indicates port to create a queue on. |
| 14660 | * @mq: The queue structure to use to create the mailbox queue. |
| 14661 | * @cq: The completion queue to associate with this cq. |
| 14662 | * @subtype: The queue's subtype. |
| 14663 | * |
| 14664 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 14665 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 14666 | * |
| 14667 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14668 | * is used to get the entry count and entry size that are necessary to |
| 14669 | * determine the number of pages to allocate and use for this queue. This |
| 14670 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 14671 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 14672 | * command to finish before continuing. |
| 14673 | * |
| 14674 | * 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] | 14675 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14676 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14677 | **/ |
| 14678 | int32_t |
| 14679 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 14680 | struct lpfc_queue *cq, uint32_t subtype) |
| 14681 | { |
| 14682 | struct lpfc_mbx_mq_create *mq_create; |
| 14683 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 14684 | struct lpfc_dmabuf *dmabuf; |
| 14685 | LPFC_MBOXQ_t *mbox; |
| 14686 | int rc, length, status = 0; |
| 14687 | uint32_t shdr_status, shdr_add_status; |
| 14688 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14689 | 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] | 14690 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14691 | /* sanity check on queue memory */ |
| 14692 | if (!mq || !cq) |
| 14693 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14694 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14695 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14696 | |
| 14697 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14698 | if (!mbox) |
| 14699 | return -ENOMEM; |
| 14700 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 14701 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14702 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14703 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 14704 | length, LPFC_SLI4_MBX_EMBED); |
| 14705 | |
| 14706 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14707 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 14708 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 14709 | &mq_create_ext->u.request, mq->page_count); |
| 14710 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 14711 | &mq_create_ext->u.request, 1); |
| 14712 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14713 | &mq_create_ext->u.request, 1); |
| 14714 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 14715 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 14716 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 14717 | &mq_create_ext->u.request, 1); |
| 14718 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 14719 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14720 | 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] | 14721 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14722 | phba->sli4_hba.pc_sli4_params.mqv); |
| 14723 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 14724 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 14725 | cq->queue_id); |
| 14726 | else |
| 14727 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 14728 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14729 | switch (mq->entry_count) { |
| 14730 | default: |
| 14731 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14732 | "0362 Unsupported MQ count. (%d)\n", |
| 14733 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14734 | if (mq->entry_count < 16) { |
| 14735 | status = -EINVAL; |
| 14736 | goto out; |
| 14737 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14738 | /* otherwise default to smallest count (drop through) */ |
| 14739 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14740 | bf_set(lpfc_mq_context_ring_size, |
| 14741 | &mq_create_ext->u.request.context, |
| 14742 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14743 | break; |
| 14744 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14745 | bf_set(lpfc_mq_context_ring_size, |
| 14746 | &mq_create_ext->u.request.context, |
| 14747 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14748 | break; |
| 14749 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14750 | bf_set(lpfc_mq_context_ring_size, |
| 14751 | &mq_create_ext->u.request.context, |
| 14752 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14753 | break; |
| 14754 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14755 | bf_set(lpfc_mq_context_ring_size, |
| 14756 | &mq_create_ext->u.request.context, |
| 14757 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14758 | break; |
| 14759 | } |
| 14760 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14761 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14762 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14763 | putPaddrLow(dmabuf->phys); |
| 14764 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14765 | putPaddrHigh(dmabuf->phys); |
| 14766 | } |
| 14767 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14768 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 14769 | &mq_create_ext->u.response); |
| 14770 | if (rc != MBX_SUCCESS) { |
| 14771 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 14772 | "2795 MQ_CREATE_EXT failed with " |
| 14773 | "status x%x. Failback to MQ_CREATE.\n", |
| 14774 | rc); |
| 14775 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 14776 | mq_create = &mbox->u.mqe.un.mq_create; |
| 14777 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14778 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 14779 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 14780 | &mq_create->u.response); |
| 14781 | } |
| 14782 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14783 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14784 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14785 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14786 | if (shdr_status || shdr_add_status || rc) { |
| 14787 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14788 | "2502 MQ_CREATE mailbox failed with " |
| 14789 | "status x%x add_status x%x, mbx status x%x\n", |
| 14790 | shdr_status, shdr_add_status, rc); |
| 14791 | status = -ENXIO; |
| 14792 | goto out; |
| 14793 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14794 | if (mq->queue_id == 0xFFFF) { |
| 14795 | status = -ENXIO; |
| 14796 | goto out; |
| 14797 | } |
| 14798 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 14799 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14800 | mq->subtype = subtype; |
| 14801 | mq->host_index = 0; |
| 14802 | mq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14803 | mq->entry_repost = LPFC_MQ_REPOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14804 | |
| 14805 | /* link the mq onto the parent cq child list */ |
| 14806 | list_add_tail(&mq->list, &cq->child_list); |
| 14807 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14808 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14809 | return status; |
| 14810 | } |
| 14811 | |
| 14812 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14813 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 14814 | * @phba: HBA structure that indicates port to create a queue on. |
| 14815 | * @wq: The queue structure to use to create the work queue. |
| 14816 | * @cq: The completion queue to bind this work queue to. |
| 14817 | * @subtype: The subtype of the work queue indicating its functionality. |
| 14818 | * |
| 14819 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 14820 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 14821 | * |
| 14822 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 14823 | * is used to get the entry count and entry size that are necessary to |
| 14824 | * determine the number of pages to allocate and use for this queue. The @cq |
| 14825 | * is used to indicate which completion queue to bind this work queue to. This |
| 14826 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 14827 | * work queue. This function is asynchronous and will wait for the mailbox |
| 14828 | * command to finish before continuing. |
| 14829 | * |
| 14830 | * 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] | 14831 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14832 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14833 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14834 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14835 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 14836 | struct lpfc_queue *cq, uint32_t subtype) |
| 14837 | { |
| 14838 | struct lpfc_mbx_wq_create *wq_create; |
| 14839 | struct lpfc_dmabuf *dmabuf; |
| 14840 | LPFC_MBOXQ_t *mbox; |
| 14841 | int rc, length, status = 0; |
| 14842 | uint32_t shdr_status, shdr_add_status; |
| 14843 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14844 | 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] | 14845 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14846 | void __iomem *bar_memmap_p; |
| 14847 | uint32_t db_offset; |
| 14848 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14849 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14850 | /* sanity check on queue memory */ |
| 14851 | if (!wq || !cq) |
| 14852 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14853 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14854 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14855 | |
| 14856 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14857 | if (!mbox) |
| 14858 | return -ENOMEM; |
| 14859 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 14860 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14861 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14862 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 14863 | length, LPFC_SLI4_MBX_EMBED); |
| 14864 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14865 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14866 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 14867 | wq->page_count); |
| 14868 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 14869 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14870 | |
| 14871 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14872 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14873 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14874 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14875 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
| 14876 | case LPFC_Q_CREATE_VERSION_0: |
| 14877 | switch (wq->entry_size) { |
| 14878 | default: |
| 14879 | case 64: |
| 14880 | /* Nothing to do, version 0 ONLY supports 64 byte */ |
| 14881 | page = wq_create->u.request.page; |
| 14882 | break; |
| 14883 | case 128: |
| 14884 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 14885 | LPFC_WQ_SZ128_SUPPORT)) { |
| 14886 | status = -ERANGE; |
| 14887 | goto out; |
| 14888 | } |
| 14889 | /* If we get here the HBA MUST also support V1 and |
| 14890 | * we MUST use it |
| 14891 | */ |
| 14892 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14893 | LPFC_Q_CREATE_VERSION_1); |
| 14894 | |
| 14895 | bf_set(lpfc_mbx_wq_create_wqe_count, |
| 14896 | &wq_create->u.request_1, wq->entry_count); |
| 14897 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14898 | &wq_create->u.request_1, |
| 14899 | LPFC_WQ_WQE_SIZE_128); |
| 14900 | bf_set(lpfc_mbx_wq_create_page_size, |
| 14901 | &wq_create->u.request_1, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 14902 | LPFC_WQ_PAGE_SIZE_4096); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14903 | page = wq_create->u.request_1.page; |
| 14904 | break; |
| 14905 | } |
| 14906 | break; |
| 14907 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14908 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 14909 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 14910 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14911 | LPFC_Q_CREATE_VERSION_1); |
| 14912 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14913 | switch (wq->entry_size) { |
| 14914 | default: |
| 14915 | case 64: |
| 14916 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14917 | &wq_create->u.request_1, |
| 14918 | LPFC_WQ_WQE_SIZE_64); |
| 14919 | break; |
| 14920 | case 128: |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14921 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 14922 | LPFC_WQ_SZ128_SUPPORT)) { |
| 14923 | status = -ERANGE; |
| 14924 | goto out; |
| 14925 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14926 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14927 | &wq_create->u.request_1, |
| 14928 | LPFC_WQ_WQE_SIZE_128); |
| 14929 | break; |
| 14930 | } |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 14931 | bf_set(lpfc_mbx_wq_create_page_size, |
| 14932 | &wq_create->u.request_1, |
| 14933 | LPFC_WQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14934 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14935 | break; |
| 14936 | default: |
| 14937 | status = -ERANGE; |
| 14938 | goto out; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14939 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14940 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14941 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14942 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14943 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 14944 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14945 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14946 | |
| 14947 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 14948 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 14949 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14950 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14951 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14952 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14953 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14954 | if (shdr_status || shdr_add_status || rc) { |
| 14955 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14956 | "2503 WQ_CREATE mailbox failed with " |
| 14957 | "status x%x add_status x%x, mbx status x%x\n", |
| 14958 | shdr_status, shdr_add_status, rc); |
| 14959 | status = -ENXIO; |
| 14960 | goto out; |
| 14961 | } |
| 14962 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 14963 | if (wq->queue_id == 0xFFFF) { |
| 14964 | status = -ENXIO; |
| 14965 | goto out; |
| 14966 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14967 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 14968 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 14969 | &wq_create->u.response); |
| 14970 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 14971 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 14972 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14973 | "3265 WQ[%d] doorbell format not " |
| 14974 | "supported: x%x\n", wq->queue_id, |
| 14975 | wq->db_format); |
| 14976 | status = -EINVAL; |
| 14977 | goto out; |
| 14978 | } |
| 14979 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 14980 | &wq_create->u.response); |
| 14981 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 14982 | if (!bar_memmap_p) { |
| 14983 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14984 | "3263 WQ[%d] failed to memmap pci " |
| 14985 | "barset:x%x\n", wq->queue_id, |
| 14986 | pci_barset); |
| 14987 | status = -ENOMEM; |
| 14988 | goto out; |
| 14989 | } |
| 14990 | db_offset = wq_create->u.response.doorbell_offset; |
| 14991 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 14992 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 14993 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14994 | "3252 WQ[%d] doorbell offset not " |
| 14995 | "supported: x%x\n", wq->queue_id, |
| 14996 | db_offset); |
| 14997 | status = -EINVAL; |
| 14998 | goto out; |
| 14999 | } |
| 15000 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15001 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15002 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15003 | "format:x%x\n", wq->queue_id, pci_barset, |
| 15004 | db_offset, wq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15005 | } else { |
| 15006 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15007 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 15008 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15009 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15010 | if (wq->pring == NULL) { |
| 15011 | status = -ENOMEM; |
| 15012 | goto out; |
| 15013 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15014 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15015 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15016 | wq->subtype = subtype; |
| 15017 | wq->host_index = 0; |
| 15018 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 15019 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15020 | |
| 15021 | /* link the wq onto the parent cq child list */ |
| 15022 | list_add_tail(&wq->list, &cq->child_list); |
| 15023 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15024 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15025 | return status; |
| 15026 | } |
| 15027 | |
| 15028 | /** |
| 15029 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15030 | * @phba: HBA structure that indicates port to create a queue on. |
| 15031 | * @hrq: The queue structure to use to create the header receive queue. |
| 15032 | * @drq: The queue structure to use to create the data receive queue. |
| 15033 | * @cq: The completion queue to bind this work queue to. |
| 15034 | * |
| 15035 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15036 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15037 | * to the HBA. |
| 15038 | * |
| 15039 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15040 | * struct is used to get the entry count that is necessary to determine the |
| 15041 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15042 | * completion queue to bind received buffers that are posted to these queues to. |
| 15043 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15044 | * receive queue pair. This function is asynchronous and will wait for the |
| 15045 | * mailbox command to finish before continuing. |
| 15046 | * |
| 15047 | * 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] | 15048 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15049 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15050 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15051 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15052 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15053 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15054 | { |
| 15055 | struct lpfc_mbx_rq_create *rq_create; |
| 15056 | struct lpfc_dmabuf *dmabuf; |
| 15057 | LPFC_MBOXQ_t *mbox; |
| 15058 | int rc, length, status = 0; |
| 15059 | uint32_t shdr_status, shdr_add_status; |
| 15060 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15061 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15062 | void __iomem *bar_memmap_p; |
| 15063 | uint32_t db_offset; |
| 15064 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15065 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15066 | /* sanity check on queue memory */ |
| 15067 | if (!hrq || !drq || !cq) |
| 15068 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15069 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15070 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15071 | |
| 15072 | if (hrq->entry_count != drq->entry_count) |
| 15073 | return -EINVAL; |
| 15074 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15075 | if (!mbox) |
| 15076 | return -ENOMEM; |
| 15077 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15078 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15079 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15080 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15081 | length, LPFC_SLI4_MBX_EMBED); |
| 15082 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15083 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15084 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15085 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15086 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15087 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15088 | &rq_create->u.request.context, |
| 15089 | hrq->entry_count); |
| 15090 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15091 | bf_set(lpfc_rq_context_rqe_size, |
| 15092 | &rq_create->u.request.context, |
| 15093 | LPFC_RQE_SIZE_8); |
| 15094 | bf_set(lpfc_rq_context_page_size, |
| 15095 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15096 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15097 | } else { |
| 15098 | switch (hrq->entry_count) { |
| 15099 | default: |
| 15100 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15101 | "2535 Unsupported RQ count. (%d)\n", |
| 15102 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15103 | if (hrq->entry_count < 512) { |
| 15104 | status = -EINVAL; |
| 15105 | goto out; |
| 15106 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15107 | /* otherwise default to smallest count (drop through) */ |
| 15108 | case 512: |
| 15109 | bf_set(lpfc_rq_context_rqe_count, |
| 15110 | &rq_create->u.request.context, |
| 15111 | LPFC_RQ_RING_SIZE_512); |
| 15112 | break; |
| 15113 | case 1024: |
| 15114 | bf_set(lpfc_rq_context_rqe_count, |
| 15115 | &rq_create->u.request.context, |
| 15116 | LPFC_RQ_RING_SIZE_1024); |
| 15117 | break; |
| 15118 | case 2048: |
| 15119 | bf_set(lpfc_rq_context_rqe_count, |
| 15120 | &rq_create->u.request.context, |
| 15121 | LPFC_RQ_RING_SIZE_2048); |
| 15122 | break; |
| 15123 | case 4096: |
| 15124 | bf_set(lpfc_rq_context_rqe_count, |
| 15125 | &rq_create->u.request.context, |
| 15126 | LPFC_RQ_RING_SIZE_4096); |
| 15127 | break; |
| 15128 | } |
| 15129 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15130 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15131 | } |
| 15132 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15133 | cq->queue_id); |
| 15134 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15135 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15136 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15137 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15138 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15139 | putPaddrLow(dmabuf->phys); |
| 15140 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15141 | putPaddrHigh(dmabuf->phys); |
| 15142 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15143 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15144 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15145 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15146 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15147 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15148 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15149 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15150 | if (shdr_status || shdr_add_status || rc) { |
| 15151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15152 | "2504 RQ_CREATE mailbox failed with " |
| 15153 | "status x%x add_status x%x, mbx status x%x\n", |
| 15154 | shdr_status, shdr_add_status, rc); |
| 15155 | status = -ENXIO; |
| 15156 | goto out; |
| 15157 | } |
| 15158 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15159 | if (hrq->queue_id == 0xFFFF) { |
| 15160 | status = -ENXIO; |
| 15161 | goto out; |
| 15162 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15163 | |
| 15164 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15165 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15166 | &rq_create->u.response); |
| 15167 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15168 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15170 | "3262 RQ [%d] doorbell format not " |
| 15171 | "supported: x%x\n", hrq->queue_id, |
| 15172 | hrq->db_format); |
| 15173 | status = -EINVAL; |
| 15174 | goto out; |
| 15175 | } |
| 15176 | |
| 15177 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15178 | &rq_create->u.response); |
| 15179 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15180 | if (!bar_memmap_p) { |
| 15181 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15182 | "3269 RQ[%d] failed to memmap pci " |
| 15183 | "barset:x%x\n", hrq->queue_id, |
| 15184 | pci_barset); |
| 15185 | status = -ENOMEM; |
| 15186 | goto out; |
| 15187 | } |
| 15188 | |
| 15189 | db_offset = rq_create->u.response.doorbell_offset; |
| 15190 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15191 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15192 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15193 | "3270 RQ[%d] doorbell offset not " |
| 15194 | "supported: x%x\n", hrq->queue_id, |
| 15195 | db_offset); |
| 15196 | status = -EINVAL; |
| 15197 | goto out; |
| 15198 | } |
| 15199 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15200 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15201 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15202 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15203 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15204 | } else { |
| 15205 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15206 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15207 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15208 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15209 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15210 | hrq->subtype = subtype; |
| 15211 | hrq->host_index = 0; |
| 15212 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15213 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15214 | |
| 15215 | /* now create the data queue */ |
| 15216 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15217 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15218 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15219 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15220 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15221 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15222 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15223 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15224 | if (subtype == LPFC_NVMET) |
| 15225 | rq_create->u.request.context.buffer_size = |
| 15226 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15227 | else |
| 15228 | rq_create->u.request.context.buffer_size = |
| 15229 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15230 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15231 | LPFC_RQE_SIZE_8); |
| 15232 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15233 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15234 | } else { |
| 15235 | switch (drq->entry_count) { |
| 15236 | default: |
| 15237 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15238 | "2536 Unsupported RQ count. (%d)\n", |
| 15239 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15240 | if (drq->entry_count < 512) { |
| 15241 | status = -EINVAL; |
| 15242 | goto out; |
| 15243 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15244 | /* otherwise default to smallest count (drop through) */ |
| 15245 | case 512: |
| 15246 | bf_set(lpfc_rq_context_rqe_count, |
| 15247 | &rq_create->u.request.context, |
| 15248 | LPFC_RQ_RING_SIZE_512); |
| 15249 | break; |
| 15250 | case 1024: |
| 15251 | bf_set(lpfc_rq_context_rqe_count, |
| 15252 | &rq_create->u.request.context, |
| 15253 | LPFC_RQ_RING_SIZE_1024); |
| 15254 | break; |
| 15255 | case 2048: |
| 15256 | bf_set(lpfc_rq_context_rqe_count, |
| 15257 | &rq_create->u.request.context, |
| 15258 | LPFC_RQ_RING_SIZE_2048); |
| 15259 | break; |
| 15260 | case 4096: |
| 15261 | bf_set(lpfc_rq_context_rqe_count, |
| 15262 | &rq_create->u.request.context, |
| 15263 | LPFC_RQ_RING_SIZE_4096); |
| 15264 | break; |
| 15265 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15266 | if (subtype == LPFC_NVMET) |
| 15267 | bf_set(lpfc_rq_context_buf_size, |
| 15268 | &rq_create->u.request.context, |
| 15269 | LPFC_NVMET_DATA_BUF_SIZE); |
| 15270 | else |
| 15271 | bf_set(lpfc_rq_context_buf_size, |
| 15272 | &rq_create->u.request.context, |
| 15273 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15274 | } |
| 15275 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15276 | cq->queue_id); |
| 15277 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15278 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15279 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15280 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15281 | putPaddrLow(dmabuf->phys); |
| 15282 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15283 | putPaddrHigh(dmabuf->phys); |
| 15284 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15285 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15286 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15287 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15288 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15289 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15290 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15291 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15292 | if (shdr_status || shdr_add_status || rc) { |
| 15293 | status = -ENXIO; |
| 15294 | goto out; |
| 15295 | } |
| 15296 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15297 | if (drq->queue_id == 0xFFFF) { |
| 15298 | status = -ENXIO; |
| 15299 | goto out; |
| 15300 | } |
| 15301 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15302 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15303 | drq->subtype = subtype; |
| 15304 | drq->host_index = 0; |
| 15305 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15306 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15307 | |
| 15308 | /* link the header and data RQs onto the parent cq child list */ |
| 15309 | list_add_tail(&hrq->list, &cq->child_list); |
| 15310 | list_add_tail(&drq->list, &cq->child_list); |
| 15311 | |
| 15312 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15313 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15314 | return status; |
| 15315 | } |
| 15316 | |
| 15317 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15318 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 15319 | * @phba: HBA structure that indicates port to create a queue on. |
| 15320 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 15321 | * @drqp: The queue structure array to use to create the data receive queues. |
| 15322 | * @cqp: The completion queue array to bind these receive queues to. |
| 15323 | * |
| 15324 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15325 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15326 | * to the HBA. |
| 15327 | * |
| 15328 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15329 | * struct is used to get the entry count that is necessary to determine the |
| 15330 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15331 | * completion queue to bind received buffers that are posted to these queues to. |
| 15332 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15333 | * receive queue pair. This function is asynchronous and will wait for the |
| 15334 | * mailbox command to finish before continuing. |
| 15335 | * |
| 15336 | * On success this function will return a zero. If unable to allocate enough |
| 15337 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15338 | * fails this function will return -ENXIO. |
| 15339 | **/ |
| 15340 | int |
| 15341 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 15342 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 15343 | uint32_t subtype) |
| 15344 | { |
| 15345 | struct lpfc_queue *hrq, *drq, *cq; |
| 15346 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 15347 | struct lpfc_dmabuf *dmabuf; |
| 15348 | LPFC_MBOXQ_t *mbox; |
| 15349 | int rc, length, alloclen, status = 0; |
| 15350 | int cnt, idx, numrq, page_idx = 0; |
| 15351 | uint32_t shdr_status, shdr_add_status; |
| 15352 | union lpfc_sli4_cfg_shdr *shdr; |
| 15353 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15354 | |
| 15355 | numrq = phba->cfg_nvmet_mrq; |
| 15356 | /* sanity check on array memory */ |
| 15357 | if (!hrqp || !drqp || !cqp || !numrq) |
| 15358 | return -ENODEV; |
| 15359 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15360 | hw_page_size = SLI4_PAGE_SIZE; |
| 15361 | |
| 15362 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15363 | if (!mbox) |
| 15364 | return -ENOMEM; |
| 15365 | |
| 15366 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 15367 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 15368 | sizeof(struct dma_address)); |
| 15369 | |
| 15370 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15371 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 15372 | LPFC_SLI4_MBX_NEMBED); |
| 15373 | if (alloclen < length) { |
| 15374 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15375 | "3099 Allocated DMA memory size (%d) is " |
| 15376 | "less than the requested DMA memory size " |
| 15377 | "(%d)\n", alloclen, length); |
| 15378 | status = -ENOMEM; |
| 15379 | goto out; |
| 15380 | } |
| 15381 | |
| 15382 | |
| 15383 | |
| 15384 | rq_create = mbox->sge_array->addr[0]; |
| 15385 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 15386 | |
| 15387 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 15388 | cnt = 0; |
| 15389 | |
| 15390 | for (idx = 0; idx < numrq; idx++) { |
| 15391 | hrq = hrqp[idx]; |
| 15392 | drq = drqp[idx]; |
| 15393 | cq = cqp[idx]; |
| 15394 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15395 | /* sanity check on queue memory */ |
| 15396 | if (!hrq || !drq || !cq) { |
| 15397 | status = -ENODEV; |
| 15398 | goto out; |
| 15399 | } |
| 15400 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 15401 | if (hrq->entry_count != drq->entry_count) { |
| 15402 | status = -EINVAL; |
| 15403 | goto out; |
| 15404 | } |
| 15405 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15406 | if (idx == 0) { |
| 15407 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 15408 | &rq_create->u.request, |
| 15409 | hrq->page_count); |
| 15410 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 15411 | &rq_create->u.request, (numrq * 2)); |
| 15412 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 15413 | 1); |
| 15414 | bf_set(lpfc_rq_context_base_cq, |
| 15415 | &rq_create->u.request.context, |
| 15416 | cq->queue_id); |
| 15417 | bf_set(lpfc_rq_context_data_size, |
| 15418 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15419 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15420 | bf_set(lpfc_rq_context_hdr_size, |
| 15421 | &rq_create->u.request.context, |
| 15422 | LPFC_HDR_BUF_SIZE); |
| 15423 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15424 | &rq_create->u.request.context, |
| 15425 | hrq->entry_count); |
| 15426 | bf_set(lpfc_rq_context_rqe_size, |
| 15427 | &rq_create->u.request.context, |
| 15428 | LPFC_RQE_SIZE_8); |
| 15429 | bf_set(lpfc_rq_context_page_size, |
| 15430 | &rq_create->u.request.context, |
| 15431 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 15432 | } |
| 15433 | rc = 0; |
| 15434 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 15435 | memset(dmabuf->virt, 0, hw_page_size); |
| 15436 | cnt = page_idx + dmabuf->buffer_tag; |
| 15437 | rq_create->u.request.page[cnt].addr_lo = |
| 15438 | putPaddrLow(dmabuf->phys); |
| 15439 | rq_create->u.request.page[cnt].addr_hi = |
| 15440 | putPaddrHigh(dmabuf->phys); |
| 15441 | rc++; |
| 15442 | } |
| 15443 | page_idx += rc; |
| 15444 | |
| 15445 | rc = 0; |
| 15446 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15447 | memset(dmabuf->virt, 0, hw_page_size); |
| 15448 | cnt = page_idx + dmabuf->buffer_tag; |
| 15449 | rq_create->u.request.page[cnt].addr_lo = |
| 15450 | putPaddrLow(dmabuf->phys); |
| 15451 | rq_create->u.request.page[cnt].addr_hi = |
| 15452 | putPaddrHigh(dmabuf->phys); |
| 15453 | rc++; |
| 15454 | } |
| 15455 | page_idx += rc; |
| 15456 | |
| 15457 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15458 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15459 | hrq->type = LPFC_HRQ; |
| 15460 | hrq->assoc_qid = cq->queue_id; |
| 15461 | hrq->subtype = subtype; |
| 15462 | hrq->host_index = 0; |
| 15463 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15464 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15465 | |
| 15466 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 15467 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15468 | drq->type = LPFC_DRQ; |
| 15469 | drq->assoc_qid = cq->queue_id; |
| 15470 | drq->subtype = subtype; |
| 15471 | drq->host_index = 0; |
| 15472 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15473 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15474 | |
| 15475 | list_add_tail(&hrq->list, &cq->child_list); |
| 15476 | list_add_tail(&drq->list, &cq->child_list); |
| 15477 | } |
| 15478 | |
| 15479 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15480 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15481 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15482 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15483 | if (shdr_status || shdr_add_status || rc) { |
| 15484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15485 | "3120 RQ_CREATE mailbox failed with " |
| 15486 | "status x%x add_status x%x, mbx status x%x\n", |
| 15487 | shdr_status, shdr_add_status, rc); |
| 15488 | status = -ENXIO; |
| 15489 | goto out; |
| 15490 | } |
| 15491 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15492 | if (rc == 0xFFFF) { |
| 15493 | status = -ENXIO; |
| 15494 | goto out; |
| 15495 | } |
| 15496 | |
| 15497 | /* Initialize all RQs with associated queue id */ |
| 15498 | for (idx = 0; idx < numrq; idx++) { |
| 15499 | hrq = hrqp[idx]; |
| 15500 | hrq->queue_id = rc + (2 * idx); |
| 15501 | drq = drqp[idx]; |
| 15502 | drq->queue_id = rc + (2 * idx) + 1; |
| 15503 | } |
| 15504 | |
| 15505 | out: |
| 15506 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15507 | return status; |
| 15508 | } |
| 15509 | |
| 15510 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15511 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 15512 | * @eq: The queue structure associated with the queue to destroy. |
| 15513 | * |
| 15514 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 15515 | * command, specific to the type of queue, to the HBA. |
| 15516 | * |
| 15517 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 15518 | * |
| 15519 | * 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] | 15520 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15521 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15522 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15523 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 15524 | { |
| 15525 | LPFC_MBOXQ_t *mbox; |
| 15526 | int rc, length, status = 0; |
| 15527 | uint32_t shdr_status, shdr_add_status; |
| 15528 | union lpfc_sli4_cfg_shdr *shdr; |
| 15529 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15530 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15531 | if (!eq) |
| 15532 | return -ENODEV; |
| 15533 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15534 | if (!mbox) |
| 15535 | return -ENOMEM; |
| 15536 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 15537 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15538 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15539 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 15540 | length, LPFC_SLI4_MBX_EMBED); |
| 15541 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 15542 | eq->queue_id); |
| 15543 | mbox->vport = eq->phba->pport; |
| 15544 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15545 | |
| 15546 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 15547 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15548 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15549 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 15550 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15551 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15552 | if (shdr_status || shdr_add_status || rc) { |
| 15553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15554 | "2505 EQ_DESTROY mailbox failed with " |
| 15555 | "status x%x add_status x%x, mbx status x%x\n", |
| 15556 | shdr_status, shdr_add_status, rc); |
| 15557 | status = -ENXIO; |
| 15558 | } |
| 15559 | |
| 15560 | /* Remove eq from any list */ |
| 15561 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15562 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15563 | return status; |
| 15564 | } |
| 15565 | |
| 15566 | /** |
| 15567 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 15568 | * @cq: The queue structure associated with the queue to destroy. |
| 15569 | * |
| 15570 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 15571 | * command, specific to the type of queue, to the HBA. |
| 15572 | * |
| 15573 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 15574 | * |
| 15575 | * 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] | 15576 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15577 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15578 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15579 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 15580 | { |
| 15581 | LPFC_MBOXQ_t *mbox; |
| 15582 | int rc, length, status = 0; |
| 15583 | uint32_t shdr_status, shdr_add_status; |
| 15584 | union lpfc_sli4_cfg_shdr *shdr; |
| 15585 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15586 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15587 | if (!cq) |
| 15588 | return -ENODEV; |
| 15589 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15590 | if (!mbox) |
| 15591 | return -ENOMEM; |
| 15592 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 15593 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15594 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15595 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 15596 | length, LPFC_SLI4_MBX_EMBED); |
| 15597 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 15598 | cq->queue_id); |
| 15599 | mbox->vport = cq->phba->pport; |
| 15600 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15601 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 15602 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15603 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15604 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 15605 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15606 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15607 | if (shdr_status || shdr_add_status || rc) { |
| 15608 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15609 | "2506 CQ_DESTROY mailbox failed with " |
| 15610 | "status x%x add_status x%x, mbx status x%x\n", |
| 15611 | shdr_status, shdr_add_status, rc); |
| 15612 | status = -ENXIO; |
| 15613 | } |
| 15614 | /* Remove cq from any list */ |
| 15615 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15616 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15617 | return status; |
| 15618 | } |
| 15619 | |
| 15620 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15621 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 15622 | * @qm: The queue structure associated with the queue to destroy. |
| 15623 | * |
| 15624 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 15625 | * command, specific to the type of queue, to the HBA. |
| 15626 | * |
| 15627 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 15628 | * |
| 15629 | * 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] | 15630 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15631 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15632 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15633 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 15634 | { |
| 15635 | LPFC_MBOXQ_t *mbox; |
| 15636 | int rc, length, status = 0; |
| 15637 | uint32_t shdr_status, shdr_add_status; |
| 15638 | union lpfc_sli4_cfg_shdr *shdr; |
| 15639 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15640 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15641 | if (!mq) |
| 15642 | return -ENODEV; |
| 15643 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15644 | if (!mbox) |
| 15645 | return -ENOMEM; |
| 15646 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 15647 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15648 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15649 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 15650 | length, LPFC_SLI4_MBX_EMBED); |
| 15651 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 15652 | mq->queue_id); |
| 15653 | mbox->vport = mq->phba->pport; |
| 15654 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15655 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 15656 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15657 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15658 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 15659 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15660 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15661 | if (shdr_status || shdr_add_status || rc) { |
| 15662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15663 | "2507 MQ_DESTROY mailbox failed with " |
| 15664 | "status x%x add_status x%x, mbx status x%x\n", |
| 15665 | shdr_status, shdr_add_status, rc); |
| 15666 | status = -ENXIO; |
| 15667 | } |
| 15668 | /* Remove mq from any list */ |
| 15669 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15670 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15671 | return status; |
| 15672 | } |
| 15673 | |
| 15674 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15675 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 15676 | * @wq: The queue structure associated with the queue to destroy. |
| 15677 | * |
| 15678 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 15679 | * command, specific to the type of queue, to the HBA. |
| 15680 | * |
| 15681 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 15682 | * |
| 15683 | * 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] | 15684 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15685 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15686 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15687 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 15688 | { |
| 15689 | LPFC_MBOXQ_t *mbox; |
| 15690 | int rc, length, status = 0; |
| 15691 | uint32_t shdr_status, shdr_add_status; |
| 15692 | union lpfc_sli4_cfg_shdr *shdr; |
| 15693 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15694 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15695 | if (!wq) |
| 15696 | return -ENODEV; |
| 15697 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15698 | if (!mbox) |
| 15699 | return -ENOMEM; |
| 15700 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 15701 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15702 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15703 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 15704 | length, LPFC_SLI4_MBX_EMBED); |
| 15705 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 15706 | wq->queue_id); |
| 15707 | mbox->vport = wq->phba->pport; |
| 15708 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15709 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 15710 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15711 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 15712 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15713 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15714 | if (shdr_status || shdr_add_status || rc) { |
| 15715 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15716 | "2508 WQ_DESTROY mailbox failed with " |
| 15717 | "status x%x add_status x%x, mbx status x%x\n", |
| 15718 | shdr_status, shdr_add_status, rc); |
| 15719 | status = -ENXIO; |
| 15720 | } |
| 15721 | /* Remove wq from any list */ |
| 15722 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 15723 | kfree(wq->pring); |
| 15724 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15725 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15726 | return status; |
| 15727 | } |
| 15728 | |
| 15729 | /** |
| 15730 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 15731 | * @rq: The queue structure associated with the queue to destroy. |
| 15732 | * |
| 15733 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 15734 | * command, specific to the type of queue, to the HBA. |
| 15735 | * |
| 15736 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 15737 | * |
| 15738 | * 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] | 15739 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15740 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15741 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15742 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15743 | struct lpfc_queue *drq) |
| 15744 | { |
| 15745 | LPFC_MBOXQ_t *mbox; |
| 15746 | int rc, length, status = 0; |
| 15747 | uint32_t shdr_status, shdr_add_status; |
| 15748 | union lpfc_sli4_cfg_shdr *shdr; |
| 15749 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15750 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15751 | if (!hrq || !drq) |
| 15752 | return -ENODEV; |
| 15753 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15754 | if (!mbox) |
| 15755 | return -ENOMEM; |
| 15756 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15757 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15758 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15759 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 15760 | length, LPFC_SLI4_MBX_EMBED); |
| 15761 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 15762 | hrq->queue_id); |
| 15763 | mbox->vport = hrq->phba->pport; |
| 15764 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15765 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 15766 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15767 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15768 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 15769 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15770 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15771 | if (shdr_status || shdr_add_status || rc) { |
| 15772 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15773 | "2509 RQ_DESTROY mailbox failed with " |
| 15774 | "status x%x add_status x%x, mbx status x%x\n", |
| 15775 | shdr_status, shdr_add_status, rc); |
| 15776 | if (rc != MBX_TIMEOUT) |
| 15777 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 15778 | return -ENXIO; |
| 15779 | } |
| 15780 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 15781 | drq->queue_id); |
| 15782 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 15783 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15784 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 15785 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15786 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15787 | if (shdr_status || shdr_add_status || rc) { |
| 15788 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15789 | "2510 RQ_DESTROY mailbox failed with " |
| 15790 | "status x%x add_status x%x, mbx status x%x\n", |
| 15791 | shdr_status, shdr_add_status, rc); |
| 15792 | status = -ENXIO; |
| 15793 | } |
| 15794 | list_del_init(&hrq->list); |
| 15795 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15796 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15797 | return status; |
| 15798 | } |
| 15799 | |
| 15800 | /** |
| 15801 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 15802 | * @phba: The virtual port for which this call being executed. |
| 15803 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 15804 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 15805 | * @xritag: the xritag that ties this io to the SGL pages. |
| 15806 | * |
| 15807 | * This routine will post the sgl pages for the IO that has the xritag |
| 15808 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 15809 | * creation and persists for as long as the driver is loaded. |
| 15810 | * if the caller has fewer than 256 scatter gather segments to map then |
| 15811 | * pdma_phys_addr1 should be 0. |
| 15812 | * If the caller needs to map more than 256 scatter gather segment then |
| 15813 | * pdma_phys_addr1 should be a valid physical address. |
| 15814 | * physical address for SGLs must be 64 byte aligned. |
| 15815 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 15816 | * the second sgl can have between 1 and 256 entries. |
| 15817 | * |
| 15818 | * Return codes: |
| 15819 | * 0 - Success |
| 15820 | * -ENXIO, -ENOMEM - Failure |
| 15821 | **/ |
| 15822 | int |
| 15823 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 15824 | dma_addr_t pdma_phys_addr0, |
| 15825 | dma_addr_t pdma_phys_addr1, |
| 15826 | uint16_t xritag) |
| 15827 | { |
| 15828 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 15829 | LPFC_MBOXQ_t *mbox; |
| 15830 | int rc; |
| 15831 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15832 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15833 | union lpfc_sli4_cfg_shdr *shdr; |
| 15834 | |
| 15835 | if (xritag == NO_XRI) { |
| 15836 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15837 | "0364 Invalid param:\n"); |
| 15838 | return -EINVAL; |
| 15839 | } |
| 15840 | |
| 15841 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15842 | if (!mbox) |
| 15843 | return -ENOMEM; |
| 15844 | |
| 15845 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15846 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 15847 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15848 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15849 | |
| 15850 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 15851 | &mbox->u.mqe.un.post_sgl_pages; |
| 15852 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 15853 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 15854 | |
| 15855 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 15856 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 15857 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 15858 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 15859 | |
| 15860 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 15861 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 15862 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 15863 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 15864 | if (!phba->sli4_hba.intr_enable) |
| 15865 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15866 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15867 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15868 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 15869 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15870 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15871 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 15872 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15873 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15874 | if (rc != MBX_TIMEOUT) |
| 15875 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15876 | if (shdr_status || shdr_add_status || rc) { |
| 15877 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15878 | "2511 POST_SGL mailbox failed with " |
| 15879 | "status x%x add_status x%x, mbx status x%x\n", |
| 15880 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15881 | } |
| 15882 | return 0; |
| 15883 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15884 | |
| 15885 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15886 | * 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] | 15887 | * @phba: pointer to lpfc hba data structure. |
| 15888 | * |
| 15889 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15890 | * HBA consistent with the SLI-4 interface spec. This routine |
| 15891 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15892 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15893 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15894 | * Returns |
| 15895 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 15896 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 15897 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15898 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15899 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 15900 | { |
| 15901 | unsigned long xri; |
| 15902 | |
| 15903 | /* |
| 15904 | * Fetch the next logical xri. Because this index is logical, |
| 15905 | * the driver starts at 0 each time. |
| 15906 | */ |
| 15907 | spin_lock_irq(&phba->hbalock); |
| 15908 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 15909 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 15910 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 15911 | spin_unlock_irq(&phba->hbalock); |
| 15912 | return NO_XRI; |
| 15913 | } else { |
| 15914 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 15915 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15916 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15917 | spin_unlock_irq(&phba->hbalock); |
| 15918 | return xri; |
| 15919 | } |
| 15920 | |
| 15921 | /** |
| 15922 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 15923 | * @phba: pointer to lpfc hba data structure. |
| 15924 | * |
| 15925 | * This routine is invoked to release an xri to the pool of |
| 15926 | * available rpis maintained by the driver. |
| 15927 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15928 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15929 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 15930 | { |
| 15931 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15932 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 15933 | } |
| 15934 | } |
| 15935 | |
| 15936 | /** |
| 15937 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 15938 | * @phba: pointer to lpfc hba data structure. |
| 15939 | * |
| 15940 | * This routine is invoked to release an xri to the pool of |
| 15941 | * available rpis maintained by the driver. |
| 15942 | **/ |
| 15943 | void |
| 15944 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 15945 | { |
| 15946 | spin_lock_irq(&phba->hbalock); |
| 15947 | __lpfc_sli4_free_xri(phba, xri); |
| 15948 | spin_unlock_irq(&phba->hbalock); |
| 15949 | } |
| 15950 | |
| 15951 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15952 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 15953 | * @phba: Pointer to HBA context object. |
| 15954 | * |
| 15955 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 15956 | * it will return 0xffff. |
| 15957 | * The function returns the allocated xritag if successful, else returns zero. |
| 15958 | * Zero is not a valid xritag. |
| 15959 | * The caller is not required to hold any lock. |
| 15960 | **/ |
| 15961 | uint16_t |
| 15962 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 15963 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15964 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15965 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15966 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 15967 | if (xri_index == NO_XRI) |
| 15968 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 15969 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 15970 | " Max XRI is %d, Used XRI is %d\n", |
| 15971 | xri_index, |
| 15972 | phba->sli4_hba.max_cfg_param.max_xri, |
| 15973 | phba->sli4_hba.max_cfg_param.xri_used); |
| 15974 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15975 | } |
| 15976 | |
| 15977 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15978 | * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15979 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 15980 | * @post_sgl_list: pointer to els sgl entry list. |
| 15981 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15982 | * |
| 15983 | * This routine is invoked to post a block of driver's sgl pages to the |
| 15984 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 15985 | * is only called when the driver is loading and after all IO has been |
| 15986 | * stopped. |
| 15987 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 15988 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15989 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 15990 | struct list_head *post_sgl_list, |
| 15991 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15992 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 15993 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15994 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 15995 | struct sgl_page_pairs *sgl_pg_pairs; |
| 15996 | void *viraddr; |
| 15997 | LPFC_MBOXQ_t *mbox; |
| 15998 | uint32_t reqlen, alloclen, pg_pairs; |
| 15999 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16000 | uint16_t xritag_start = 0; |
| 16001 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16002 | uint32_t shdr_status, shdr_add_status; |
| 16003 | union lpfc_sli4_cfg_shdr *shdr; |
| 16004 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16005 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16006 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16007 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16008 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16009 | "2559 Block sgl registration required DMA " |
| 16010 | "size (%d) great than a page\n", reqlen); |
| 16011 | return -ENOMEM; |
| 16012 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16013 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16014 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16015 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16016 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16017 | |
| 16018 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16019 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16020 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16021 | LPFC_SLI4_MBX_NEMBED); |
| 16022 | |
| 16023 | if (alloclen < reqlen) { |
| 16024 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16025 | "0285 Allocated DMA memory size (%d) is " |
| 16026 | "less than the requested DMA memory " |
| 16027 | "size (%d)\n", alloclen, reqlen); |
| 16028 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16029 | return -ENOMEM; |
| 16030 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16031 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16032 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16033 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16034 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16035 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16036 | pg_pairs = 0; |
| 16037 | 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] | 16038 | /* Set up the sge entry */ |
| 16039 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16040 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16041 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16042 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16043 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16044 | cpu_to_le32(putPaddrLow(0)); |
| 16045 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16046 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16047 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16048 | /* Keep the first xritag on the list */ |
| 16049 | if (pg_pairs == 0) |
| 16050 | xritag_start = sglq_entry->sli4_xritag; |
| 16051 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16052 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16053 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16054 | |
| 16055 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16056 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16057 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16058 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16059 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16060 | if (!phba->sli4_hba.intr_enable) |
| 16061 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16062 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16063 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16064 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16065 | } |
| 16066 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16067 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16068 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16069 | if (rc != MBX_TIMEOUT) |
| 16070 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16071 | if (shdr_status || shdr_add_status || rc) { |
| 16072 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16073 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16074 | "status x%x add_status x%x mbx status x%x\n", |
| 16075 | shdr_status, shdr_add_status, rc); |
| 16076 | rc = -ENXIO; |
| 16077 | } |
| 16078 | return rc; |
| 16079 | } |
| 16080 | |
| 16081 | /** |
| 16082 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 16083 | * @phba: pointer to lpfc hba data structure. |
| 16084 | * @sblist: pointer to scsi buffer list. |
| 16085 | * @count: number of scsi buffers on the list. |
| 16086 | * |
| 16087 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 16088 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 16089 | * No Lock is held. |
| 16090 | * |
| 16091 | **/ |
| 16092 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16093 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 16094 | struct list_head *sblist, |
| 16095 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16096 | { |
| 16097 | struct lpfc_scsi_buf *psb; |
| 16098 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16099 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16100 | void *viraddr; |
| 16101 | LPFC_MBOXQ_t *mbox; |
| 16102 | uint32_t reqlen, alloclen, pg_pairs; |
| 16103 | uint32_t mbox_tmo; |
| 16104 | uint16_t xritag_start = 0; |
| 16105 | int rc = 0; |
| 16106 | uint32_t shdr_status, shdr_add_status; |
| 16107 | dma_addr_t pdma_phys_bpl1; |
| 16108 | union lpfc_sli4_cfg_shdr *shdr; |
| 16109 | |
| 16110 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16111 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16112 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16113 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16114 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 16115 | "0217 Block sgl registration required DMA " |
| 16116 | "size (%d) great than a page\n", reqlen); |
| 16117 | return -ENOMEM; |
| 16118 | } |
| 16119 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16120 | if (!mbox) { |
| 16121 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16122 | "0283 Failed to allocate mbox cmd memory\n"); |
| 16123 | return -ENOMEM; |
| 16124 | } |
| 16125 | |
| 16126 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16127 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16128 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16129 | LPFC_SLI4_MBX_NEMBED); |
| 16130 | |
| 16131 | if (alloclen < reqlen) { |
| 16132 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16133 | "2561 Allocated DMA memory size (%d) is " |
| 16134 | "less than the requested DMA memory " |
| 16135 | "size (%d)\n", alloclen, reqlen); |
| 16136 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16137 | return -ENOMEM; |
| 16138 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16139 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16140 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16141 | viraddr = mbox->sge_array->addr[0]; |
| 16142 | |
| 16143 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16144 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16145 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16146 | |
| 16147 | pg_pairs = 0; |
| 16148 | list_for_each_entry(psb, sblist, list) { |
| 16149 | /* Set up the sge entry */ |
| 16150 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16151 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 16152 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16153 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 16154 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 16155 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 16156 | else |
| 16157 | pdma_phys_bpl1 = 0; |
| 16158 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16159 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16160 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16161 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16162 | /* Keep the first xritag on the list */ |
| 16163 | if (pg_pairs == 0) |
| 16164 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 16165 | sgl_pg_pairs++; |
| 16166 | pg_pairs++; |
| 16167 | } |
| 16168 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16169 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16170 | /* Perform endian conversion if necessary */ |
| 16171 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16172 | |
| 16173 | if (!phba->sli4_hba.intr_enable) |
| 16174 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16175 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16176 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16177 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16178 | } |
| 16179 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16180 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16181 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16182 | if (rc != MBX_TIMEOUT) |
| 16183 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16184 | if (shdr_status || shdr_add_status || rc) { |
| 16185 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16186 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 16187 | "status x%x add_status x%x mbx status x%x\n", |
| 16188 | shdr_status, shdr_add_status, rc); |
| 16189 | rc = -ENXIO; |
| 16190 | } |
| 16191 | return rc; |
| 16192 | } |
| 16193 | |
| 16194 | /** |
| 16195 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16196 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16197 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16198 | * |
| 16199 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16200 | * valid type of frame that the LPFC driver will handle. This function will |
| 16201 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16202 | * frame does not pass the check. |
| 16203 | **/ |
| 16204 | static int |
| 16205 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16206 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16207 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16208 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16209 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16210 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16211 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 16212 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16213 | switch (fc_hdr->fh_r_ctl) { |
| 16214 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16215 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16216 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16217 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16218 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16219 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16220 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16221 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16222 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16223 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16224 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16225 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16226 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16227 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16228 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16229 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16230 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16231 | case FC_RCTL_BA_PRMT: |
| 16232 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16233 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 16234 | case FC_RCTL_P_RJT: /* port reject */ |
| 16235 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 16236 | case FC_RCTL_P_BSY: /* port busy */ |
| 16237 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 16238 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 16239 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16240 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16241 | case FC_RCTL_END: /* end */ |
| 16242 | break; |
| 16243 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 16244 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16245 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 16246 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 16247 | default: |
| 16248 | goto drop; |
| 16249 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16250 | |
| 16251 | #define FC_TYPE_VENDOR_UNIQUE 0xFF |
| 16252 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16253 | switch (fc_hdr->fh_type) { |
| 16254 | case FC_TYPE_BLS: |
| 16255 | case FC_TYPE_ELS: |
| 16256 | case FC_TYPE_FCP: |
| 16257 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16258 | case FC_TYPE_NVME: |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16259 | case FC_TYPE_VENDOR_UNIQUE: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16260 | break; |
| 16261 | case FC_TYPE_IP: |
| 16262 | case FC_TYPE_ILS: |
| 16263 | default: |
| 16264 | goto drop; |
| 16265 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16266 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16267 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16268 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 16269 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16270 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 16271 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 16272 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 16273 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 16274 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16275 | return 0; |
| 16276 | drop: |
| 16277 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16278 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 16279 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16280 | return 1; |
| 16281 | } |
| 16282 | |
| 16283 | /** |
| 16284 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 16285 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16286 | * |
| 16287 | * This function processes the FC header to retrieve the VFI from the VF |
| 16288 | * header, if one exists. This function will return the VFI if one exists |
| 16289 | * or 0 if no VSAN Header exists. |
| 16290 | **/ |
| 16291 | static uint32_t |
| 16292 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 16293 | { |
| 16294 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16295 | |
| 16296 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 16297 | return 0; |
| 16298 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 16299 | } |
| 16300 | |
| 16301 | /** |
| 16302 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 16303 | * @phba: Pointer to the HBA structure to search for the vport on |
| 16304 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16305 | * @fcfi: The FC Fabric ID that the frame came from |
| 16306 | * |
| 16307 | * This function searches the @phba for a vport that matches the content of the |
| 16308 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 16309 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 16310 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 16311 | * vport. |
| 16312 | **/ |
| 16313 | static struct lpfc_vport * |
| 16314 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16315 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16316 | { |
| 16317 | struct lpfc_vport **vports; |
| 16318 | struct lpfc_vport *vport = NULL; |
| 16319 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16320 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 16321 | if (did == Fabric_DID) |
| 16322 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16323 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 16324 | !(phba->link_state == LPFC_HBA_READY)) |
| 16325 | return phba->pport; |
| 16326 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16327 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16328 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16329 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 16330 | if (phba->fcf.fcfi == fcfi && |
| 16331 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 16332 | vports[i]->fc_myDID == did) { |
| 16333 | vport = vports[i]; |
| 16334 | break; |
| 16335 | } |
| 16336 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16337 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16338 | lpfc_destroy_vport_work_array(phba, vports); |
| 16339 | return vport; |
| 16340 | } |
| 16341 | |
| 16342 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16343 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 16344 | * @vport: The vport to work on. |
| 16345 | * |
| 16346 | * This function updates the receive sequence time stamp for this vport. The |
| 16347 | * receive sequence time stamp indicates the time that the last frame of the |
| 16348 | * the sequence that has been idle for the longest amount of time was received. |
| 16349 | * the driver uses this time stamp to indicate if any received sequences have |
| 16350 | * timed out. |
| 16351 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16352 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16353 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 16354 | { |
| 16355 | struct lpfc_dmabuf *h_buf; |
| 16356 | struct hbq_dmabuf *dmabuf = NULL; |
| 16357 | |
| 16358 | /* get the oldest sequence on the rcv list */ |
| 16359 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 16360 | struct lpfc_dmabuf, list); |
| 16361 | if (!h_buf) |
| 16362 | return; |
| 16363 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16364 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 16365 | } |
| 16366 | |
| 16367 | /** |
| 16368 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 16369 | * @vport: The vport that the received sequences were sent to. |
| 16370 | * |
| 16371 | * This function cleans up all outstanding received sequences. This is called |
| 16372 | * by the driver when a link event or user action invalidates all the received |
| 16373 | * sequences. |
| 16374 | **/ |
| 16375 | void |
| 16376 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 16377 | { |
| 16378 | struct lpfc_dmabuf *h_buf, *hnext; |
| 16379 | struct lpfc_dmabuf *d_buf, *dnext; |
| 16380 | struct hbq_dmabuf *dmabuf = NULL; |
| 16381 | |
| 16382 | /* start with the oldest sequence on the rcv list */ |
| 16383 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 16384 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16385 | list_del_init(&dmabuf->hbuf.list); |
| 16386 | list_for_each_entry_safe(d_buf, dnext, |
| 16387 | &dmabuf->dbuf.list, list) { |
| 16388 | list_del_init(&d_buf->list); |
| 16389 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16390 | } |
| 16391 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 16392 | } |
| 16393 | } |
| 16394 | |
| 16395 | /** |
| 16396 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 16397 | * @vport: The vport that the received sequences were sent to. |
| 16398 | * |
| 16399 | * This function determines whether any received sequences have timed out by |
| 16400 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 16401 | * indicates that there is at least one timed out sequence this routine will |
| 16402 | * go through the received sequences one at a time from most inactive to most |
| 16403 | * active to determine which ones need to be cleaned up. Once it has determined |
| 16404 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 16405 | * without sending an abort. |
| 16406 | **/ |
| 16407 | void |
| 16408 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 16409 | { |
| 16410 | struct lpfc_dmabuf *h_buf, *hnext; |
| 16411 | struct lpfc_dmabuf *d_buf, *dnext; |
| 16412 | struct hbq_dmabuf *dmabuf = NULL; |
| 16413 | unsigned long timeout; |
| 16414 | int abort_count = 0; |
| 16415 | |
| 16416 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 16417 | vport->rcv_buffer_time_stamp); |
| 16418 | if (list_empty(&vport->rcv_buffer_list) || |
| 16419 | time_before(jiffies, timeout)) |
| 16420 | return; |
| 16421 | /* start with the oldest sequence on the rcv list */ |
| 16422 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 16423 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16424 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 16425 | dmabuf->time_stamp); |
| 16426 | if (time_before(jiffies, timeout)) |
| 16427 | break; |
| 16428 | abort_count++; |
| 16429 | list_del_init(&dmabuf->hbuf.list); |
| 16430 | list_for_each_entry_safe(d_buf, dnext, |
| 16431 | &dmabuf->dbuf.list, list) { |
| 16432 | list_del_init(&d_buf->list); |
| 16433 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16434 | } |
| 16435 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 16436 | } |
| 16437 | if (abort_count) |
| 16438 | lpfc_update_rcv_time_stamp(vport); |
| 16439 | } |
| 16440 | |
| 16441 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16442 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 16443 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 16444 | * |
| 16445 | * This function searches through the existing incomplete sequences that have |
| 16446 | * been sent to this @vport. If the frame matches one of the incomplete |
| 16447 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 16448 | * make up that sequence. If no sequence is found that matches this frame then |
| 16449 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 16450 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 16451 | * the frame was linked to. |
| 16452 | **/ |
| 16453 | static struct hbq_dmabuf * |
| 16454 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 16455 | { |
| 16456 | struct fc_frame_header *new_hdr; |
| 16457 | struct fc_frame_header *temp_hdr; |
| 16458 | struct lpfc_dmabuf *d_buf; |
| 16459 | struct lpfc_dmabuf *h_buf; |
| 16460 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 16461 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16462 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16463 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16464 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16465 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16466 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16467 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16468 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 16469 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 16470 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 16471 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 16472 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 16473 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 16474 | continue; |
| 16475 | /* found a pending sequence that matches this frame */ |
| 16476 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16477 | break; |
| 16478 | } |
| 16479 | if (!seq_dmabuf) { |
| 16480 | /* |
| 16481 | * This indicates first frame received for this sequence. |
| 16482 | * Queue the buffer on the vport's rcv_buffer_list. |
| 16483 | */ |
| 16484 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16485 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16486 | return dmabuf; |
| 16487 | } |
| 16488 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16489 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 16490 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16491 | list_del_init(&seq_dmabuf->hbuf.list); |
| 16492 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 16493 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16494 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16495 | return dmabuf; |
| 16496 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16497 | /* move this sequence to the tail to indicate a young sequence */ |
| 16498 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 16499 | seq_dmabuf->time_stamp = jiffies; |
| 16500 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16501 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 16502 | temp_hdr = dmabuf->hbuf.virt; |
| 16503 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 16504 | return seq_dmabuf; |
| 16505 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16506 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16507 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 16508 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16509 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 16510 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 16511 | /* |
| 16512 | * If the frame's sequence count is greater than the frame on |
| 16513 | * the list then insert the frame right after this frame |
| 16514 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16515 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 16516 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16517 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16518 | found = 1; |
| 16519 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16520 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16521 | |
| 16522 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 16523 | break; |
| 16524 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16525 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16526 | |
| 16527 | if (found) |
| 16528 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16529 | return NULL; |
| 16530 | } |
| 16531 | |
| 16532 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16533 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 16534 | * @vport: pointer to a vitural port |
| 16535 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16536 | * |
| 16537 | * This function tries to abort from the partially assembed sequence, described |
| 16538 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 16539 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 16540 | * the frames from the partially assembled sequence. |
| 16541 | * |
| 16542 | * Return |
| 16543 | * true -- if there is matching partially assembled sequence present and all |
| 16544 | * the frames freed with the sequence; |
| 16545 | * false -- if there is no matching partially assembled sequence present so |
| 16546 | * nothing got aborted in the lower layer driver |
| 16547 | **/ |
| 16548 | static bool |
| 16549 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 16550 | struct hbq_dmabuf *dmabuf) |
| 16551 | { |
| 16552 | struct fc_frame_header *new_hdr; |
| 16553 | struct fc_frame_header *temp_hdr; |
| 16554 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 16555 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 16556 | |
| 16557 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 16558 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 16559 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 16560 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 16561 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 16562 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 16563 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 16564 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 16565 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 16566 | continue; |
| 16567 | /* found a pending sequence that matches this frame */ |
| 16568 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16569 | break; |
| 16570 | } |
| 16571 | |
| 16572 | /* Free up all the frames from the partially assembled sequence */ |
| 16573 | if (seq_dmabuf) { |
| 16574 | list_for_each_entry_safe(d_buf, n_buf, |
| 16575 | &seq_dmabuf->dbuf.list, list) { |
| 16576 | list_del_init(&d_buf->list); |
| 16577 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16578 | } |
| 16579 | return true; |
| 16580 | } |
| 16581 | return false; |
| 16582 | } |
| 16583 | |
| 16584 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16585 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 16586 | * @vport: pointer to a vitural port |
| 16587 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16588 | * |
| 16589 | * This function tries to abort from the assembed sequence from upper level |
| 16590 | * protocol, described by the information from basic abbort @dmabuf. It |
| 16591 | * checks to see whether such pending context exists at upper level protocol. |
| 16592 | * If so, it shall clean up the pending context. |
| 16593 | * |
| 16594 | * Return |
| 16595 | * true -- if there is matching pending context of the sequence cleaned |
| 16596 | * at ulp; |
| 16597 | * false -- if there is no matching pending context of the sequence present |
| 16598 | * at ulp. |
| 16599 | **/ |
| 16600 | static bool |
| 16601 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 16602 | { |
| 16603 | struct lpfc_hba *phba = vport->phba; |
| 16604 | int handled; |
| 16605 | |
| 16606 | /* Accepting abort at ulp with SLI4 only */ |
| 16607 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16608 | return false; |
| 16609 | |
| 16610 | /* Register all caring upper level protocols to attend abort */ |
| 16611 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 16612 | if (handled) |
| 16613 | return true; |
| 16614 | |
| 16615 | return false; |
| 16616 | } |
| 16617 | |
| 16618 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16619 | * 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] | 16620 | * @phba: Pointer to HBA context object. |
| 16621 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 16622 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 16623 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16624 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16625 | * event. It properly releases the memory allocated to the sequence abort |
| 16626 | * accept iocb. |
| 16627 | **/ |
| 16628 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16629 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16630 | struct lpfc_iocbq *cmd_iocbq, |
| 16631 | struct lpfc_iocbq *rsp_iocbq) |
| 16632 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16633 | struct lpfc_nodelist *ndlp; |
| 16634 | |
| 16635 | if (cmd_iocbq) { |
| 16636 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 16637 | lpfc_nlp_put(ndlp); |
| 16638 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16639 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16640 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16641 | |
| 16642 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 16643 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 16644 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16645 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 16646 | rsp_iocbq->iocb.ulpStatus, |
| 16647 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16648 | } |
| 16649 | |
| 16650 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16651 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 16652 | * @phba: Pointer to HBA context object. |
| 16653 | * @xri: xri id in transaction. |
| 16654 | * |
| 16655 | * This function validates the xri maps to the known range of XRIs allocated an |
| 16656 | * used by the driver. |
| 16657 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16658 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16659 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 16660 | uint16_t xri) |
| 16661 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16662 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16663 | |
| 16664 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 16665 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 16666 | return i; |
| 16667 | } |
| 16668 | return NO_XRI; |
| 16669 | } |
| 16670 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16671 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16672 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16673 | * @phba: Pointer to HBA context object. |
| 16674 | * @fc_hdr: pointer to a FC frame header. |
| 16675 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16676 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16677 | * event after aborting the sequence handling. |
| 16678 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 16679 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16680 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 16681 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16682 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16683 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16684 | struct lpfc_iocbq *ctiocb = NULL; |
| 16685 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 16686 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16687 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16688 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16689 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16690 | |
| 16691 | if (!lpfc_is_link_up(phba)) |
| 16692 | return; |
| 16693 | |
| 16694 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 16695 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16696 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16697 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16698 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16699 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 16700 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16701 | if (!ndlp) { |
| 16702 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 16703 | "1268 Failed to allocate ndlp for " |
| 16704 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 16705 | return; |
| 16706 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16707 | /* Put ndlp onto pport node list */ |
| 16708 | lpfc_enqueue_node(vport, ndlp); |
| 16709 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 16710 | /* re-setup ndlp without removing from node list */ |
| 16711 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 16712 | if (!ndlp) { |
| 16713 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 16714 | "3275 Failed to active ndlp found " |
| 16715 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 16716 | return; |
| 16717 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16718 | } |
| 16719 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16720 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16721 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 16722 | if (!ctiocb) |
| 16723 | return; |
| 16724 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16725 | /* Extract the F_CTL field from FC_HDR */ |
| 16726 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 16727 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16728 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16729 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16730 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16731 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 16732 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 16733 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 16734 | |
| 16735 | /* Fill in the rest of iocb fields */ |
| 16736 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 16737 | icmd->ulpBdeCount = 0; |
| 16738 | icmd->ulpLe = 1; |
| 16739 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16740 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16741 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16742 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16743 | ctiocb->iocb_cmpl = NULL; |
| 16744 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16745 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16746 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16747 | ctiocb->sli4_xritag = NO_XRI; |
| 16748 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 16749 | if (fctl & FC_FC_EX_CTX) |
| 16750 | /* Exchange responder sent the abort so we |
| 16751 | * own the oxid. |
| 16752 | */ |
| 16753 | xri = oxid; |
| 16754 | else |
| 16755 | xri = rxid; |
| 16756 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 16757 | if (lxri != NO_XRI) |
| 16758 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 16759 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16760 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 16761 | * the oxid maps to the FCP XRI range, the port no longer has |
| 16762 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 16763 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16764 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16765 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16766 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16767 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 16768 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 16769 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 16770 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 16771 | } |
| 16772 | |
| 16773 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 16774 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 16775 | * the IOCB for a BA_RJT. |
| 16776 | */ |
| 16777 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16778 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 16779 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 16780 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 16781 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 16782 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16783 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16784 | if (fctl & FC_FC_EX_CTX) { |
| 16785 | /* ABTS sent by responder to CT exchange, construction |
| 16786 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 16787 | * field and RX_ID from ABTS for RX_ID field. |
| 16788 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16789 | 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] | 16790 | } else { |
| 16791 | /* ABTS sent by initiator to CT exchange, construction |
| 16792 | * 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] | 16793 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16794 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16795 | 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] | 16796 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 16797 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16798 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16799 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16800 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16801 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 16802 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 16803 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16804 | |
| 16805 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 16806 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16807 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 16808 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 16809 | "xri x%x, Data x%x\n", |
| 16810 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 16811 | phba->link_state); |
| 16812 | lpfc_nlp_put(ndlp); |
| 16813 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16814 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 16815 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16816 | } |
| 16817 | |
| 16818 | /** |
| 16819 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 16820 | * @vport: Pointer to the vport on which this sequence was received |
| 16821 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16822 | * |
| 16823 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 16824 | * receive sequence is only partially assembed by the driver, it shall abort |
| 16825 | * the partially assembled frames for the sequence. Otherwise, if the |
| 16826 | * unsolicited receive sequence has been completely assembled and passed to |
| 16827 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 16828 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 16829 | * accept to accept the abort. |
| 16830 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16831 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16832 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 16833 | struct hbq_dmabuf *dmabuf) |
| 16834 | { |
| 16835 | struct lpfc_hba *phba = vport->phba; |
| 16836 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16837 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16838 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16839 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16840 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 16841 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16842 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16843 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16844 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16845 | /* ABTS by responder to exchange, no cleanup needed */ |
| 16846 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16847 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16848 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 16849 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 16850 | if (aborted == false) |
| 16851 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16852 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16853 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 16854 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 16855 | if (phba->nvmet_support) { |
| 16856 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 16857 | return; |
| 16858 | } |
| 16859 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16860 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 16861 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16862 | } |
| 16863 | |
| 16864 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16865 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 16866 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16867 | * |
| 16868 | * This function checks the sequence, starting with the frame described by |
| 16869 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 16870 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 16871 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 16872 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 16873 | * set. 3) That there are no holes in the sequence count. The function will |
| 16874 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 16875 | **/ |
| 16876 | static int |
| 16877 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 16878 | { |
| 16879 | struct fc_frame_header *hdr; |
| 16880 | struct lpfc_dmabuf *d_buf; |
| 16881 | struct hbq_dmabuf *seq_dmabuf; |
| 16882 | uint32_t fctl; |
| 16883 | int seq_count = 0; |
| 16884 | |
| 16885 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 16886 | /* make sure first fame of sequence has a sequence count of zero */ |
| 16887 | if (hdr->fh_seq_cnt != seq_count) |
| 16888 | return 0; |
| 16889 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 16890 | hdr->fh_f_ctl[1] << 8 | |
| 16891 | hdr->fh_f_ctl[2]); |
| 16892 | /* If last frame of sequence we can return success. */ |
| 16893 | if (fctl & FC_FC_END_SEQ) |
| 16894 | return 1; |
| 16895 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 16896 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 16897 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 16898 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16899 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16900 | return 0; |
| 16901 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 16902 | hdr->fh_f_ctl[1] << 8 | |
| 16903 | hdr->fh_f_ctl[2]); |
| 16904 | /* If last frame of sequence we can return success. */ |
| 16905 | if (fctl & FC_FC_END_SEQ) |
| 16906 | return 1; |
| 16907 | } |
| 16908 | return 0; |
| 16909 | } |
| 16910 | |
| 16911 | /** |
| 16912 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 16913 | * @vport: Pointer to the vport on which this sequence was received |
| 16914 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16915 | * |
| 16916 | * This function takes a sequence, described by a list of frames, and creates |
| 16917 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 16918 | * used to issue to the generic unsolicited sequence handler. This routine |
| 16919 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 16920 | * to allocate an iocbq then it throw out the received frames that were not |
| 16921 | * able to be described and return a pointer to the first iocbq. If unable to |
| 16922 | * allocate any iocbqs (including the first) this function will return NULL. |
| 16923 | **/ |
| 16924 | static struct lpfc_iocbq * |
| 16925 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 16926 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16927 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16928 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 16929 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 16930 | struct fc_frame_header *fc_hdr; |
| 16931 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16932 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16933 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16934 | |
| 16935 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 16936 | /* remove from receive buffer list */ |
| 16937 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16938 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16939 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16940 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16941 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16942 | /* Get an iocbq struct to fill in. */ |
| 16943 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 16944 | if (first_iocbq) { |
| 16945 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16946 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16947 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16948 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16949 | |
| 16950 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 16951 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 16952 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 16953 | first_iocbq->iocb.un.rcvels.parmRo = |
| 16954 | sli4_did_from_fc_hdr(fc_hdr); |
| 16955 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 16956 | } else |
| 16957 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16958 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 16959 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 16960 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 16961 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 16962 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 16963 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16964 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16965 | tot_len = bf_get(lpfc_rcqe_length, |
| 16966 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 16967 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16968 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 16969 | first_iocbq->context3 = NULL; |
| 16970 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16971 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 16972 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16973 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16974 | else |
| 16975 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 16976 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16977 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16978 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16979 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16980 | } |
| 16981 | iocbq = first_iocbq; |
| 16982 | /* |
| 16983 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 16984 | * of buffers for this sequence and save two buffers in each IOCBq |
| 16985 | */ |
| 16986 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 16987 | if (!iocbq) { |
| 16988 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16989 | continue; |
| 16990 | } |
| 16991 | if (!iocbq->context3) { |
| 16992 | iocbq->context3 = d_buf; |
| 16993 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16994 | /* We need to get the size out of the right CQE */ |
| 16995 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 16996 | len = bf_get(lpfc_rcqe_length, |
| 16997 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16998 | pbde = (struct ulp_bde64 *) |
| 16999 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17000 | if (len > LPFC_DATA_BUF_SIZE) |
| 17001 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17002 | else |
| 17003 | pbde->tus.f.bdeSize = len; |
| 17004 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17005 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17006 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17007 | } else { |
| 17008 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17009 | if (!iocbq) { |
| 17010 | if (first_iocbq) { |
| 17011 | first_iocbq->iocb.ulpStatus = |
| 17012 | IOSTAT_FCP_RSP_ERROR; |
| 17013 | first_iocbq->iocb.un.ulpWord[4] = |
| 17014 | IOERR_NO_RESOURCES; |
| 17015 | } |
| 17016 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17017 | continue; |
| 17018 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17019 | /* We need to get the size out of the right CQE */ |
| 17020 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17021 | len = bf_get(lpfc_rcqe_length, |
| 17022 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17023 | iocbq->context2 = d_buf; |
| 17024 | iocbq->context3 = NULL; |
| 17025 | iocbq->iocb.ulpBdeCount = 1; |
| 17026 | if (len > LPFC_DATA_BUF_SIZE) |
| 17027 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17028 | LPFC_DATA_BUF_SIZE; |
| 17029 | else |
| 17030 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17031 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17032 | tot_len += len; |
| 17033 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17034 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17035 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17036 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17037 | } |
| 17038 | } |
| 17039 | return first_iocbq; |
| 17040 | } |
| 17041 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17042 | static void |
| 17043 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17044 | struct hbq_dmabuf *seq_dmabuf) |
| 17045 | { |
| 17046 | struct fc_frame_header *fc_hdr; |
| 17047 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17048 | struct lpfc_hba *phba = vport->phba; |
| 17049 | |
| 17050 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17051 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17052 | if (!iocbq) { |
| 17053 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17054 | "2707 Ring %d handler: Failed to allocate " |
| 17055 | "iocb Rctl x%x Type x%x received\n", |
| 17056 | LPFC_ELS_RING, |
| 17057 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17058 | return; |
| 17059 | } |
| 17060 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17061 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17062 | iocbq, fc_hdr->fh_r_ctl, |
| 17063 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17064 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17065 | "2540 Ring %d handler: unexpected Rctl " |
| 17066 | "x%x Type x%x received\n", |
| 17067 | LPFC_ELS_RING, |
| 17068 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17069 | |
| 17070 | /* Free iocb created in lpfc_prep_seq */ |
| 17071 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17072 | &iocbq->list, list) { |
| 17073 | list_del_init(&curr_iocb->list); |
| 17074 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17075 | } |
| 17076 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17077 | } |
| 17078 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17079 | static void |
| 17080 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17081 | struct lpfc_iocbq *rspiocb) |
| 17082 | { |
| 17083 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17084 | |
| 17085 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17086 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17087 | kfree(pcmd); |
| 17088 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 17089 | } |
| 17090 | |
| 17091 | static void |
| 17092 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17093 | struct hbq_dmabuf *dmabuf) |
| 17094 | { |
| 17095 | struct fc_frame_header *fc_hdr; |
| 17096 | struct lpfc_hba *phba = vport->phba; |
| 17097 | struct lpfc_iocbq *iocbq = NULL; |
| 17098 | union lpfc_wqe *wqe; |
| 17099 | struct lpfc_dmabuf *pcmd = NULL; |
| 17100 | uint32_t frame_len; |
| 17101 | int rc; |
| 17102 | |
| 17103 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17104 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17105 | |
| 17106 | /* Send the received frame back */ |
| 17107 | iocbq = lpfc_sli_get_iocbq(phba); |
| 17108 | if (!iocbq) |
| 17109 | goto exit; |
| 17110 | |
| 17111 | /* Allocate buffer for command payload */ |
| 17112 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17113 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17114 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17115 | &pcmd->phys); |
| 17116 | if (!pcmd || !pcmd->virt) |
| 17117 | goto exit; |
| 17118 | |
| 17119 | INIT_LIST_HEAD(&pcmd->list); |
| 17120 | |
| 17121 | /* copyin the payload */ |
| 17122 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17123 | |
| 17124 | /* fill in BDE's for command */ |
| 17125 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17126 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17127 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17128 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17129 | |
| 17130 | iocbq->context2 = pcmd; |
| 17131 | iocbq->vport = vport; |
| 17132 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17133 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17134 | |
| 17135 | /* |
| 17136 | * Setup rest of the iocb as though it were a WQE |
| 17137 | * Build the SEND_FRAME WQE |
| 17138 | */ |
| 17139 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17140 | |
| 17141 | wqe->send_frame.frame_len = frame_len; |
| 17142 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17143 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17144 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17145 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17146 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17147 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17148 | |
| 17149 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17150 | iocbq->iocb.ulpLe = 1; |
| 17151 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17152 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17153 | if (rc == IOCB_ERROR) |
| 17154 | goto exit; |
| 17155 | |
| 17156 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17157 | return; |
| 17158 | |
| 17159 | exit: |
| 17160 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17161 | "2023 Unable to process MDS loopback frame\n"); |
| 17162 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17163 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17164 | kfree(pcmd); |
Dick Kennedy | 6d69765 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17165 | if (iocbq) |
| 17166 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17167 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17168 | } |
| 17169 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17170 | /** |
| 17171 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17172 | * @phba: Pointer to HBA context object. |
| 17173 | * |
| 17174 | * This function is called with no lock held. This function processes all |
| 17175 | * the received buffers and gives it to upper layers when a received buffer |
| 17176 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17177 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17178 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17179 | * appropriate receive function when the final frame in a sequence is received. |
| 17180 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17181 | void |
| 17182 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17183 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17184 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17185 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17186 | struct fc_frame_header *fc_hdr; |
| 17187 | struct lpfc_vport *vport; |
| 17188 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17189 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17190 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17191 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17192 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17193 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17194 | /* check to see if this a valid type of frame */ |
| 17195 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17196 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17197 | return; |
| 17198 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17199 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17200 | if ((bf_get(lpfc_cqe_code, |
| 17201 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17202 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17203 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17204 | else |
| 17205 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17206 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17207 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17208 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 17209 | vport = phba->pport; |
| 17210 | /* Handle MDS Loopback frames */ |
| 17211 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17212 | return; |
| 17213 | } |
| 17214 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17215 | /* d_id this frame is directed to */ |
| 17216 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17217 | |
| 17218 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17219 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17220 | /* throw out the frame */ |
| 17221 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17222 | return; |
| 17223 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17224 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17225 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 17226 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 17227 | (did != Fabric_DID)) { |
| 17228 | /* |
| 17229 | * Throw out the frame if we are not pt2pt. |
| 17230 | * The pt2pt protocol allows for discovery frames |
| 17231 | * to be received without a registered VPI. |
| 17232 | */ |
| 17233 | if (!(vport->fc_flag & FC_PT2PT) || |
| 17234 | (phba->link_state == LPFC_HBA_READY)) { |
| 17235 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17236 | return; |
| 17237 | } |
| 17238 | } |
| 17239 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17240 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 17241 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 17242 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 17243 | return; |
| 17244 | } |
| 17245 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17246 | /* Link this frame */ |
| 17247 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 17248 | if (!seq_dmabuf) { |
| 17249 | /* unable to add frame to vport - throw it out */ |
| 17250 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17251 | return; |
| 17252 | } |
| 17253 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17254 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17255 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17256 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17257 | /* Send the complete sequence to the upper layer protocol */ |
| 17258 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17259 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17260 | |
| 17261 | /** |
| 17262 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 17263 | * @phba: pointer to lpfc hba data structure. |
| 17264 | * |
| 17265 | * This routine is invoked to post rpi header templates to the |
| 17266 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17267 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17268 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17269 | * |
| 17270 | * This routine does not require any locks. It's usage is expected |
| 17271 | * to be driver load or reset recovery when the driver is |
| 17272 | * sequential. |
| 17273 | * |
| 17274 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17275 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17276 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17277 | * When this error occurs, the driver is not guaranteed |
| 17278 | * to have any rpi regions posted to the device and |
| 17279 | * must either attempt to repost the regions or take a |
| 17280 | * fatal error. |
| 17281 | **/ |
| 17282 | int |
| 17283 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 17284 | { |
| 17285 | struct lpfc_rpi_hdr *rpi_page; |
| 17286 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17287 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17288 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17289 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17290 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17291 | goto exit; |
| 17292 | if (phba->sli4_hba.extents_in_use) |
| 17293 | return -EIO; |
| 17294 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17295 | 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] | 17296 | /* |
| 17297 | * Assign the rpi headers a physical rpi only if the driver |
| 17298 | * has not initialized those resources. A port reset only |
| 17299 | * needs the headers posted. |
| 17300 | */ |
| 17301 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 17302 | LPFC_RPI_RSRC_RDY) |
| 17303 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 17304 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17305 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 17306 | if (rc != MBX_SUCCESS) { |
| 17307 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17308 | "2008 Error %d posting all rpi " |
| 17309 | "headers\n", rc); |
| 17310 | rc = -EIO; |
| 17311 | break; |
| 17312 | } |
| 17313 | } |
| 17314 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17315 | exit: |
| 17316 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 17317 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17318 | return rc; |
| 17319 | } |
| 17320 | |
| 17321 | /** |
| 17322 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 17323 | * @phba: pointer to lpfc hba data structure. |
| 17324 | * @rpi_page: pointer to the rpi memory region. |
| 17325 | * |
| 17326 | * This routine is invoked to post a single rpi header to the |
| 17327 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 17328 | * maps up to 64 rpi context regions. |
| 17329 | * |
| 17330 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17331 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17332 | * -ENOMEM - No available memory |
| 17333 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17334 | **/ |
| 17335 | int |
| 17336 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 17337 | { |
| 17338 | LPFC_MBOXQ_t *mboxq; |
| 17339 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 17340 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17341 | uint32_t shdr_status, shdr_add_status; |
| 17342 | union lpfc_sli4_cfg_shdr *shdr; |
| 17343 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17344 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17345 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17346 | return rc; |
| 17347 | if (phba->sli4_hba.extents_in_use) |
| 17348 | return -EIO; |
| 17349 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17350 | /* The port is notified of the header region via a mailbox command. */ |
| 17351 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17352 | if (!mboxq) { |
| 17353 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17354 | "2001 Unable to allocate memory for issuing " |
| 17355 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 17356 | return -ENOMEM; |
| 17357 | } |
| 17358 | |
| 17359 | /* Post all rpi memory regions to the port. */ |
| 17360 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17361 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17362 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 17363 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 17364 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 17365 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17366 | |
| 17367 | |
| 17368 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17369 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 17370 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17371 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 17372 | hdr_tmpl, rpi_page->page_count); |
| 17373 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17374 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 17375 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 17376 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17377 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 17378 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17379 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17380 | if (rc != MBX_TIMEOUT) |
| 17381 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 17382 | if (shdr_status || shdr_add_status || rc) { |
| 17383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17384 | "2514 POST_RPI_HDR mailbox failed with " |
| 17385 | "status x%x add_status x%x, mbx status x%x\n", |
| 17386 | shdr_status, shdr_add_status, rc); |
| 17387 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 17388 | } else { |
| 17389 | /* |
| 17390 | * The next_rpi stores the next logical module-64 rpi value used |
| 17391 | * to post physical rpis in subsequent rpi postings. |
| 17392 | */ |
| 17393 | spin_lock_irq(&phba->hbalock); |
| 17394 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 17395 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17396 | } |
| 17397 | return rc; |
| 17398 | } |
| 17399 | |
| 17400 | /** |
| 17401 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 17402 | * @phba: pointer to lpfc hba data structure. |
| 17403 | * |
| 17404 | * This routine is invoked to post rpi header templates to the |
| 17405 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17406 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17407 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17408 | * |
| 17409 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17410 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17411 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 17412 | **/ |
| 17413 | int |
| 17414 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 17415 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17416 | unsigned long rpi; |
| 17417 | uint16_t max_rpi, rpi_limit; |
| 17418 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17419 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17420 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17421 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17422 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17423 | * Fetch the next logical rpi. Because this index is logical, |
| 17424 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17425 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17426 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 17427 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 17428 | rpi_limit = phba->sli4_hba.next_rpi; |
| 17429 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17430 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 17431 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17432 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 17433 | else { |
| 17434 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 17435 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 17436 | phba->sli4_hba.rpi_count++; |
| 17437 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 17438 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 17439 | "0001 rpi:%x max:%x lim:%x\n", |
| 17440 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17441 | |
| 17442 | /* |
| 17443 | * 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] | 17444 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17445 | */ |
| 17446 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 17447 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17448 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17449 | return rpi; |
| 17450 | } |
| 17451 | |
| 17452 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17453 | * RPI header postings are not required for SLI4 ports capable of |
| 17454 | * extents. |
| 17455 | */ |
| 17456 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17457 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17458 | return rpi; |
| 17459 | } |
| 17460 | |
| 17461 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17462 | * If the driver is running low on rpi resources, allocate another |
| 17463 | * page now. Note that the next_rpi value is used because |
| 17464 | * it represents how many are actually in use whereas max_rpi notes |
| 17465 | * how many are supported max by the device. |
| 17466 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17467 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17468 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17469 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 17470 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 17471 | if (!rpi_hdr) { |
| 17472 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17473 | "2002 Error Could not grow rpi " |
| 17474 | "count\n"); |
| 17475 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17476 | lrpi = rpi_hdr->start_rpi; |
| 17477 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17478 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 17479 | } |
| 17480 | } |
| 17481 | |
| 17482 | return rpi; |
| 17483 | } |
| 17484 | |
| 17485 | /** |
| 17486 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 17487 | * @phba: pointer to lpfc hba data structure. |
| 17488 | * |
| 17489 | * This routine is invoked to release an rpi to the pool of |
| 17490 | * available rpis maintained by the driver. |
| 17491 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17492 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 17493 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 17494 | { |
| 17495 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 17496 | phba->sli4_hba.rpi_count--; |
| 17497 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 17498 | } |
| 17499 | } |
| 17500 | |
| 17501 | /** |
| 17502 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 17503 | * @phba: pointer to lpfc hba data structure. |
| 17504 | * |
| 17505 | * This routine is invoked to release an rpi to the pool of |
| 17506 | * available rpis maintained by the driver. |
| 17507 | **/ |
| 17508 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17509 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 17510 | { |
| 17511 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 17512 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17513 | spin_unlock_irq(&phba->hbalock); |
| 17514 | } |
| 17515 | |
| 17516 | /** |
| 17517 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 17518 | * @phba: pointer to lpfc hba data structure. |
| 17519 | * |
| 17520 | * This routine is invoked to remove the memory region that |
| 17521 | * provided rpi via a bitmask. |
| 17522 | **/ |
| 17523 | void |
| 17524 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 17525 | { |
| 17526 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17527 | kfree(phba->sli4_hba.rpi_ids); |
| 17528 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17529 | } |
| 17530 | |
| 17531 | /** |
| 17532 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 17533 | * @phba: pointer to lpfc hba data structure. |
| 17534 | * |
| 17535 | * This routine is invoked to remove the memory region that |
| 17536 | * provided rpi via a bitmask. |
| 17537 | **/ |
| 17538 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17539 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 17540 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17541 | { |
| 17542 | LPFC_MBOXQ_t *mboxq; |
| 17543 | struct lpfc_hba *phba = ndlp->phba; |
| 17544 | int rc; |
| 17545 | |
| 17546 | /* The port is notified of the header region via a mailbox command. */ |
| 17547 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17548 | if (!mboxq) |
| 17549 | return -ENOMEM; |
| 17550 | |
| 17551 | /* Post all rpi memory regions to the port. */ |
| 17552 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17553 | if (cmpl) { |
| 17554 | mboxq->mbox_cmpl = cmpl; |
| 17555 | mboxq->context1 = arg; |
| 17556 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 17557 | } else |
| 17558 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17559 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17560 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17561 | if (rc == MBX_NOT_FINISHED) { |
| 17562 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17563 | "2010 Resume RPI Mailbox failed " |
| 17564 | "status %d, mbxStatus x%x\n", rc, |
| 17565 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 17566 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 17567 | return -EIO; |
| 17568 | } |
| 17569 | return 0; |
| 17570 | } |
| 17571 | |
| 17572 | /** |
| 17573 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17574 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17575 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17576 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17577 | * |
| 17578 | * Returns: |
| 17579 | * 0 success |
| 17580 | * -Evalue otherwise |
| 17581 | **/ |
| 17582 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17583 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17584 | { |
| 17585 | LPFC_MBOXQ_t *mboxq; |
| 17586 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17587 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17588 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17589 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17590 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17591 | if (!mboxq) |
| 17592 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17593 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17594 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17595 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17596 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17597 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17598 | "2022 INIT VPI Mailbox failed " |
| 17599 | "status %d, mbxStatus x%x\n", rc, |
| 17600 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17601 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17602 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17603 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17604 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17605 | |
| 17606 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17607 | } |
| 17608 | |
| 17609 | /** |
| 17610 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 17611 | * @phba: pointer to lpfc hba data structure. |
| 17612 | * @mboxq: Pointer to mailbox object. |
| 17613 | * |
| 17614 | * This routine is invoked to manually add a single FCF record. The caller |
| 17615 | * must pass a completely initialized FCF_Record. This routine takes |
| 17616 | * care of the nonembedded mailbox operations. |
| 17617 | **/ |
| 17618 | static void |
| 17619 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 17620 | { |
| 17621 | void *virt_addr; |
| 17622 | union lpfc_sli4_cfg_shdr *shdr; |
| 17623 | uint32_t shdr_status, shdr_add_status; |
| 17624 | |
| 17625 | virt_addr = mboxq->sge_array->addr[0]; |
| 17626 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17627 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 17628 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17629 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17630 | |
| 17631 | if ((shdr_status || shdr_add_status) && |
| 17632 | (shdr_status != STATUS_FCF_IN_USE)) |
| 17633 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17634 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 17635 | "status x%x add_status x%x\n", |
| 17636 | shdr_status, shdr_add_status); |
| 17637 | |
| 17638 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17639 | } |
| 17640 | |
| 17641 | /** |
| 17642 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 17643 | * @phba: pointer to lpfc hba data structure. |
| 17644 | * @fcf_record: pointer to the initialized fcf record to add. |
| 17645 | * |
| 17646 | * This routine is invoked to manually add a single FCF record. The caller |
| 17647 | * must pass a completely initialized FCF_Record. This routine takes |
| 17648 | * care of the nonembedded mailbox operations. |
| 17649 | **/ |
| 17650 | int |
| 17651 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 17652 | { |
| 17653 | int rc = 0; |
| 17654 | LPFC_MBOXQ_t *mboxq; |
| 17655 | uint8_t *bytep; |
| 17656 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17657 | struct lpfc_mbx_sge sge; |
| 17658 | uint32_t alloc_len, req_len; |
| 17659 | uint32_t fcfindex; |
| 17660 | |
| 17661 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17662 | if (!mboxq) { |
| 17663 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17664 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 17665 | return -ENOMEM; |
| 17666 | } |
| 17667 | |
| 17668 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 17669 | sizeof(uint32_t); |
| 17670 | |
| 17671 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 17672 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17673 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 17674 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 17675 | if (alloc_len < req_len) { |
| 17676 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17677 | "2523 Allocated DMA memory size (x%x) is " |
| 17678 | "less than the requested DMA memory " |
| 17679 | "size (x%x)\n", alloc_len, req_len); |
| 17680 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17681 | return -ENOMEM; |
| 17682 | } |
| 17683 | |
| 17684 | /* |
| 17685 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 17686 | * routine only uses a single SGE. |
| 17687 | */ |
| 17688 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17689 | virt_addr = mboxq->sge_array->addr[0]; |
| 17690 | /* |
| 17691 | * Configure the FCF record for FCFI 0. This is the driver's |
| 17692 | * hardcoded default and gets used in nonFIP mode. |
| 17693 | */ |
| 17694 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 17695 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 17696 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 17697 | |
| 17698 | /* |
| 17699 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 17700 | * the FCoE header plus word10. The data copy needs to be endian |
| 17701 | * correct. |
| 17702 | */ |
| 17703 | bytep += sizeof(uint32_t); |
| 17704 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 17705 | mboxq->vport = phba->pport; |
| 17706 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 17707 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17708 | if (rc == MBX_NOT_FINISHED) { |
| 17709 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17710 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 17711 | "status 0x%x\n", rc); |
| 17712 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17713 | rc = -EIO; |
| 17714 | } else |
| 17715 | rc = 0; |
| 17716 | |
| 17717 | return rc; |
| 17718 | } |
| 17719 | |
| 17720 | /** |
| 17721 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 17722 | * @phba: pointer to lpfc hba data structure. |
| 17723 | * @fcf_record: pointer to the fcf record to write the default data. |
| 17724 | * @fcf_index: FCF table entry index. |
| 17725 | * |
| 17726 | * This routine is invoked to build the driver's default FCF record. The |
| 17727 | * values used are hardcoded. This routine handles memory initialization. |
| 17728 | * |
| 17729 | **/ |
| 17730 | void |
| 17731 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 17732 | struct fcf_record *fcf_record, |
| 17733 | uint16_t fcf_index) |
| 17734 | { |
| 17735 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 17736 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 17737 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 17738 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 17739 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 17740 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 17741 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 17742 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 17743 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 17744 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 17745 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 17746 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 17747 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 17748 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 17749 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17750 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 17751 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 17752 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 17753 | /* Set the VLAN bit map */ |
| 17754 | if (phba->valid_vlan) { |
| 17755 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 17756 | = 1 << (phba->vlan_id % 8); |
| 17757 | } |
| 17758 | } |
| 17759 | |
| 17760 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17761 | * 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] | 17762 | * @phba: pointer to lpfc hba data structure. |
| 17763 | * @fcf_index: FCF table entry offset. |
| 17764 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17765 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 17766 | * record and processing it one at a time starting from the @fcf_index |
| 17767 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 17768 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17769 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17770 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17771 | **/ |
| 17772 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17773 | 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] | 17774 | { |
| 17775 | int rc = 0, error; |
| 17776 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17777 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 17778 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 17779 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17780 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17781 | if (!mboxq) { |
| 17782 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17783 | "2000 Failed to allocate mbox for " |
| 17784 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17785 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17786 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17787 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17788 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17789 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17790 | if (rc) { |
| 17791 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17792 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17793 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17794 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17795 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17796 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17797 | |
| 17798 | spin_lock_irq(&phba->hbalock); |
| 17799 | phba->hba_flag |= FCF_TS_INPROG; |
| 17800 | spin_unlock_irq(&phba->hbalock); |
| 17801 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17802 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17803 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17804 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17805 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 17806 | /* Reset eligible FCF count for new scan */ |
| 17807 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 17808 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17809 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 17810 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17811 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17812 | if (error) { |
| 17813 | if (mboxq) |
| 17814 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17815 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17816 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17817 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17818 | spin_unlock_irq(&phba->hbalock); |
| 17819 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17820 | return error; |
| 17821 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 17822 | |
| 17823 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17824 | * 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] | 17825 | * @phba: pointer to lpfc hba data structure. |
| 17826 | * @fcf_index: FCF table entry offset. |
| 17827 | * |
| 17828 | * 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] | 17829 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17830 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17831 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17832 | * otherwise. |
| 17833 | **/ |
| 17834 | int |
| 17835 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 17836 | { |
| 17837 | int rc = 0, error; |
| 17838 | LPFC_MBOXQ_t *mboxq; |
| 17839 | |
| 17840 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17841 | if (!mboxq) { |
| 17842 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 17843 | "2763 Failed to allocate mbox for " |
| 17844 | "READ_FCF cmd\n"); |
| 17845 | error = -ENOMEM; |
| 17846 | goto fail_fcf_read; |
| 17847 | } |
| 17848 | /* Construct the read FCF record mailbox command */ |
| 17849 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 17850 | if (rc) { |
| 17851 | error = -EINVAL; |
| 17852 | goto fail_fcf_read; |
| 17853 | } |
| 17854 | /* Issue the mailbox command asynchronously */ |
| 17855 | mboxq->vport = phba->pport; |
| 17856 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 17857 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17858 | if (rc == MBX_NOT_FINISHED) |
| 17859 | error = -EIO; |
| 17860 | else |
| 17861 | error = 0; |
| 17862 | |
| 17863 | fail_fcf_read: |
| 17864 | if (error && mboxq) |
| 17865 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17866 | return error; |
| 17867 | } |
| 17868 | |
| 17869 | /** |
| 17870 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 17871 | * @phba: pointer to lpfc hba data structure. |
| 17872 | * @fcf_index: FCF table entry offset. |
| 17873 | * |
| 17874 | * 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] | 17875 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17876 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17877 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17878 | * otherwise. |
| 17879 | **/ |
| 17880 | int |
| 17881 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 17882 | { |
| 17883 | int rc = 0, error; |
| 17884 | LPFC_MBOXQ_t *mboxq; |
| 17885 | |
| 17886 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17887 | if (!mboxq) { |
| 17888 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 17889 | "2758 Failed to allocate mbox for " |
| 17890 | "READ_FCF cmd\n"); |
| 17891 | error = -ENOMEM; |
| 17892 | goto fail_fcf_read; |
| 17893 | } |
| 17894 | /* Construct the read FCF record mailbox command */ |
| 17895 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 17896 | if (rc) { |
| 17897 | error = -EINVAL; |
| 17898 | goto fail_fcf_read; |
| 17899 | } |
| 17900 | /* Issue the mailbox command asynchronously */ |
| 17901 | mboxq->vport = phba->pport; |
| 17902 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 17903 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17904 | if (rc == MBX_NOT_FINISHED) |
| 17905 | error = -EIO; |
| 17906 | else |
| 17907 | error = 0; |
| 17908 | |
| 17909 | fail_fcf_read: |
| 17910 | if (error && mboxq) |
| 17911 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17912 | return error; |
| 17913 | } |
| 17914 | |
| 17915 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 17916 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17917 | * phba pointer to the lpfc_hba struct for this port. |
| 17918 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 17919 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 17920 | * rr_bmask based on their priority level. Starting from the highest priority |
| 17921 | * to the lowest. The most likely FCF candidate will be in the highest |
| 17922 | * priority group. When this routine is called it searches the fcf_pri list for |
| 17923 | * next lowest priority group and repopulates the rr_bmask with only those |
| 17924 | * fcf_indexes. |
| 17925 | * returns: |
| 17926 | * 1=success 0=failure |
| 17927 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17928 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17929 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 17930 | { |
| 17931 | uint16_t next_fcf_pri; |
| 17932 | uint16_t last_index; |
| 17933 | struct lpfc_fcf_pri *fcf_pri; |
| 17934 | int rc; |
| 17935 | int ret = 0; |
| 17936 | |
| 17937 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 17938 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 17939 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 17940 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 17941 | |
| 17942 | /* Verify the priority list has 2 or more entries */ |
| 17943 | spin_lock_irq(&phba->hbalock); |
| 17944 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 17945 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 17946 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17947 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 17948 | "3061 Last IDX %d\n", last_index); |
| 17949 | return 0; /* Empty rr list */ |
| 17950 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 17951 | spin_unlock_irq(&phba->hbalock); |
| 17952 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17953 | next_fcf_pri = 0; |
| 17954 | /* |
| 17955 | * Clear the rr_bmask and set all of the bits that are at this |
| 17956 | * priority. |
| 17957 | */ |
| 17958 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 17959 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 17960 | spin_lock_irq(&phba->hbalock); |
| 17961 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 17962 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 17963 | continue; |
| 17964 | /* |
| 17965 | * the 1st priority that has not FLOGI failed |
| 17966 | * will be the highest. |
| 17967 | */ |
| 17968 | if (!next_fcf_pri) |
| 17969 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 17970 | spin_unlock_irq(&phba->hbalock); |
| 17971 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 17972 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 17973 | fcf_pri->fcf_rec.fcf_index); |
| 17974 | if (rc) |
| 17975 | return 0; |
| 17976 | } |
| 17977 | spin_lock_irq(&phba->hbalock); |
| 17978 | } |
| 17979 | /* |
| 17980 | * if next_fcf_pri was not set above and the list is not empty then |
| 17981 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 17982 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17983 | */ |
| 17984 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 17985 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 17986 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 17987 | /* |
| 17988 | * the 1st priority that has not FLOGI failed |
| 17989 | * will be the highest. |
| 17990 | */ |
| 17991 | if (!next_fcf_pri) |
| 17992 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 17993 | spin_unlock_irq(&phba->hbalock); |
| 17994 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 17995 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 17996 | fcf_pri->fcf_rec.fcf_index); |
| 17997 | if (rc) |
| 17998 | return 0; |
| 17999 | } |
| 18000 | spin_lock_irq(&phba->hbalock); |
| 18001 | } |
| 18002 | } else |
| 18003 | ret = 1; |
| 18004 | spin_unlock_irq(&phba->hbalock); |
| 18005 | |
| 18006 | return ret; |
| 18007 | } |
| 18008 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18009 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18010 | * @phba: pointer to lpfc hba data structure. |
| 18011 | * |
| 18012 | * This routine is to get the next eligible FCF record index in a round |
| 18013 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18014 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18015 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18016 | * shall be returned. |
| 18017 | **/ |
| 18018 | uint16_t |
| 18019 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18020 | { |
| 18021 | uint16_t next_fcf_index; |
| 18022 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18023 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18024 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18025 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18026 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18027 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18028 | /* Determine the next fcf index to check */ |
| 18029 | next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18030 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18031 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18032 | next_fcf_index); |
| 18033 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18034 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18035 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18036 | /* |
| 18037 | * If we have wrapped then we need to clear the bits that |
| 18038 | * have been tested so that we can detect when we should |
| 18039 | * change the priority level. |
| 18040 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18041 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18042 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18043 | } |
| 18044 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18045 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18046 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18047 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18048 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18049 | /* |
| 18050 | * If next fcf index is not found check if there are lower |
| 18051 | * Priority level fcf's in the fcf_priority list. |
| 18052 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18053 | * at that level and continue the selection process. |
| 18054 | */ |
| 18055 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18056 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18057 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18058 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18059 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 18060 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18061 | else { |
| 18062 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18063 | "3063 Only FCF available idx %d, flag %x\n", |
| 18064 | next_fcf_index, |
| 18065 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 18066 | return next_fcf_index; |
| 18067 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18068 | } |
| 18069 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18070 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18071 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18072 | LPFC_FCF_FLOGI_FAILED) { |
| 18073 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18074 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18075 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18076 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18077 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18078 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18079 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18080 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18081 | next_fcf_index); |
| 18082 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18083 | return next_fcf_index; |
| 18084 | } |
| 18085 | |
| 18086 | /** |
| 18087 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18088 | * @phba: pointer to lpfc hba data structure. |
| 18089 | * |
| 18090 | * 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] | 18091 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18092 | * does not go beyond the range of the driver allocated bmask dimension |
| 18093 | * before setting the bit. |
| 18094 | * |
| 18095 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18096 | * -EINVAL. |
| 18097 | **/ |
| 18098 | int |
| 18099 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18100 | { |
| 18101 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18102 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18103 | "2610 FCF (x%x) reached driver's book " |
| 18104 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18105 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18106 | return -EINVAL; |
| 18107 | } |
| 18108 | /* Set the eligible FCF record index bmask */ |
| 18109 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18110 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18111 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18112 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18113 | "bmask\n", fcf_index); |
| 18114 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18115 | return 0; |
| 18116 | } |
| 18117 | |
| 18118 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18119 | * 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] | 18120 | * @phba: pointer to lpfc hba data structure. |
| 18121 | * |
| 18122 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18123 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18124 | * does not go beyond the range of the driver allocated bmask dimension |
| 18125 | * before clearing the bit. |
| 18126 | **/ |
| 18127 | void |
| 18128 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18129 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18130 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18131 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18132 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18133 | "2762 FCF (x%x) reached driver's book " |
| 18134 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18135 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18136 | return; |
| 18137 | } |
| 18138 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18139 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18140 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18141 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18142 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18143 | list_del_init(&fcf_pri->list); |
| 18144 | break; |
| 18145 | } |
| 18146 | } |
| 18147 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18148 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18149 | |
| 18150 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18151 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18152 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18153 | } |
| 18154 | |
| 18155 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18156 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18157 | * @phba: pointer to lpfc hba data structure. |
| 18158 | * |
| 18159 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18160 | * command. If the mailbox command returned failure, it will try to stop the |
| 18161 | * FCF rediscover wait timer. |
| 18162 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18163 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18164 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18165 | { |
| 18166 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18167 | uint32_t shdr_status, shdr_add_status; |
| 18168 | |
| 18169 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18170 | |
| 18171 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18172 | &redisc_fcf->header.cfg_shdr.response); |
| 18173 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18174 | &redisc_fcf->header.cfg_shdr.response); |
| 18175 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18176 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18177 | "2746 Requesting for FCF rediscovery failed " |
| 18178 | "status x%x add_status x%x\n", |
| 18179 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18180 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18181 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18182 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18183 | spin_unlock_irq(&phba->hbalock); |
| 18184 | /* |
| 18185 | * CVL event triggered FCF rediscover request failed, |
| 18186 | * last resort to re-try current registered FCF entry. |
| 18187 | */ |
| 18188 | lpfc_retry_pport_discovery(phba); |
| 18189 | } else { |
| 18190 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18191 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18192 | spin_unlock_irq(&phba->hbalock); |
| 18193 | /* |
| 18194 | * DEAD FCF event triggered FCF rediscover request |
| 18195 | * failed, last resort to fail over as a link down |
| 18196 | * to FCF registration. |
| 18197 | */ |
| 18198 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18199 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18200 | } else { |
| 18201 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18202 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18203 | /* |
| 18204 | * Start FCF rediscovery wait timer for pending FCF |
| 18205 | * before rescan FCF record table. |
| 18206 | */ |
| 18207 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18208 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18209 | |
| 18210 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18211 | } |
| 18212 | |
| 18213 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18214 | * 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] | 18215 | * @phba: pointer to lpfc hba data structure. |
| 18216 | * |
| 18217 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18218 | * by the port. |
| 18219 | **/ |
| 18220 | int |
| 18221 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18222 | { |
| 18223 | LPFC_MBOXQ_t *mbox; |
| 18224 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18225 | int rc, length; |
| 18226 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18227 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18228 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18229 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18230 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18231 | if (!mbox) { |
| 18232 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18233 | "2745 Failed to allocate mbox for " |
| 18234 | "requesting FCF rediscover.\n"); |
| 18235 | return -ENOMEM; |
| 18236 | } |
| 18237 | |
| 18238 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 18239 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 18240 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18241 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 18242 | length, LPFC_SLI4_MBX_EMBED); |
| 18243 | |
| 18244 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18245 | /* Set count to 0 for invalidating the entire FCF database */ |
| 18246 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 18247 | |
| 18248 | /* Issue the mailbox command asynchronously */ |
| 18249 | mbox->vport = phba->pport; |
| 18250 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 18251 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 18252 | |
| 18253 | if (rc == MBX_NOT_FINISHED) { |
| 18254 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18255 | return -EIO; |
| 18256 | } |
| 18257 | return 0; |
| 18258 | } |
| 18259 | |
| 18260 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18261 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 18262 | * @phba: pointer to lpfc hba data structure. |
| 18263 | * |
| 18264 | * This function is the failover routine as a last resort to the FCF DEAD |
| 18265 | * event when driver failed to perform fast FCF failover. |
| 18266 | **/ |
| 18267 | void |
| 18268 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 18269 | { |
| 18270 | uint32_t link_state; |
| 18271 | |
| 18272 | /* |
| 18273 | * Last resort as FCF DEAD event failover will treat this as |
| 18274 | * a link down, but save the link state because we don't want |
| 18275 | * it to be changed to Link Down unless it is already down. |
| 18276 | */ |
| 18277 | link_state = phba->link_state; |
| 18278 | lpfc_linkdown(phba); |
| 18279 | phba->link_state = link_state; |
| 18280 | |
| 18281 | /* Unregister FCF if no devices connected to it */ |
| 18282 | lpfc_unregister_unused_fcf(phba); |
| 18283 | } |
| 18284 | |
| 18285 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18286 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18287 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18288 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18289 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18290 | * This function gets SLI3 port configure region 23 data through memory dump |
| 18291 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18292 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18293 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18294 | static uint32_t |
| 18295 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18296 | { |
| 18297 | LPFC_MBOXQ_t *pmb = NULL; |
| 18298 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18299 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18300 | int rc; |
| 18301 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18302 | if (!rgn23_data) |
| 18303 | return 0; |
| 18304 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18305 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18306 | if (!pmb) { |
| 18307 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18308 | "2600 failed to allocate mailbox memory\n"); |
| 18309 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18310 | } |
| 18311 | mb = &pmb->u.mb; |
| 18312 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18313 | do { |
| 18314 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 18315 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 18316 | |
| 18317 | if (rc != MBX_SUCCESS) { |
| 18318 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18319 | "2601 failed to read config " |
| 18320 | "region 23, rc 0x%x Status 0x%x\n", |
| 18321 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18322 | mb->un.varDmp.word_cnt = 0; |
| 18323 | } |
| 18324 | /* |
| 18325 | * dump mem may return a zero when finished or we got a |
| 18326 | * mailbox error, either way we are done. |
| 18327 | */ |
| 18328 | if (mb->un.varDmp.word_cnt == 0) |
| 18329 | break; |
| 18330 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 18331 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 18332 | |
| 18333 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18334 | rgn23_data + offset, |
| 18335 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18336 | offset += mb->un.varDmp.word_cnt; |
| 18337 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 18338 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18339 | mempool_free(pmb, phba->mbox_mem_pool); |
| 18340 | return offset; |
| 18341 | } |
| 18342 | |
| 18343 | /** |
| 18344 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 18345 | * @phba: pointer to lpfc hba data structure. |
| 18346 | * @rgn23_data: pointer to configure region 23 data. |
| 18347 | * |
| 18348 | * This function gets SLI4 port configure region 23 data through memory dump |
| 18349 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18350 | * will be returned, otherwise, 0 will be returned. |
| 18351 | **/ |
| 18352 | static uint32_t |
| 18353 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 18354 | { |
| 18355 | LPFC_MBOXQ_t *mboxq = NULL; |
| 18356 | struct lpfc_dmabuf *mp = NULL; |
| 18357 | struct lpfc_mqe *mqe; |
| 18358 | uint32_t data_length = 0; |
| 18359 | int rc; |
| 18360 | |
| 18361 | if (!rgn23_data) |
| 18362 | return 0; |
| 18363 | |
| 18364 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18365 | if (!mboxq) { |
| 18366 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18367 | "3105 failed to allocate mailbox memory\n"); |
| 18368 | return 0; |
| 18369 | } |
| 18370 | |
| 18371 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 18372 | goto out; |
| 18373 | mqe = &mboxq->u.mqe; |
| 18374 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 18375 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 18376 | if (rc) |
| 18377 | goto out; |
| 18378 | data_length = mqe->un.mb_words[5]; |
| 18379 | if (data_length == 0) |
| 18380 | goto out; |
| 18381 | if (data_length > DMP_RGN23_SIZE) { |
| 18382 | data_length = 0; |
| 18383 | goto out; |
| 18384 | } |
| 18385 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 18386 | out: |
| 18387 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18388 | if (mp) { |
| 18389 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 18390 | kfree(mp); |
| 18391 | } |
| 18392 | return data_length; |
| 18393 | } |
| 18394 | |
| 18395 | /** |
| 18396 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 18397 | * @phba: pointer to lpfc hba data structure. |
| 18398 | * |
| 18399 | * This function read region 23 and parse TLV for port status to |
| 18400 | * decide if the user disaled the port. If the TLV indicates the |
| 18401 | * port is disabled, the hba_flag is set accordingly. |
| 18402 | **/ |
| 18403 | void |
| 18404 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 18405 | { |
| 18406 | uint8_t *rgn23_data = NULL; |
| 18407 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 18408 | uint32_t offset = 0; |
| 18409 | |
| 18410 | /* Get adapter Region 23 data */ |
| 18411 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 18412 | if (!rgn23_data) |
| 18413 | goto out; |
| 18414 | |
| 18415 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 18416 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 18417 | else { |
| 18418 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 18419 | &phba->sli4_hba.sli_intf); |
| 18420 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 18421 | goto out; |
| 18422 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 18423 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18424 | |
| 18425 | if (!data_size) |
| 18426 | goto out; |
| 18427 | |
| 18428 | /* Check the region signature first */ |
| 18429 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 18430 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18431 | "2619 Config region 23 has bad signature\n"); |
| 18432 | goto out; |
| 18433 | } |
| 18434 | offset += 4; |
| 18435 | |
| 18436 | /* Check the data structure version */ |
| 18437 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 18438 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18439 | "2620 Config region 23 has bad version\n"); |
| 18440 | goto out; |
| 18441 | } |
| 18442 | offset += 4; |
| 18443 | |
| 18444 | /* Parse TLV entries in the region */ |
| 18445 | while (offset < data_size) { |
| 18446 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 18447 | break; |
| 18448 | /* |
| 18449 | * If the TLV is not driver specific TLV or driver id is |
| 18450 | * not linux driver id, skip the record. |
| 18451 | */ |
| 18452 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 18453 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 18454 | (rgn23_data[offset + 3] != 0)) { |
| 18455 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 18456 | continue; |
| 18457 | } |
| 18458 | |
| 18459 | /* Driver found a driver specific TLV in the config region */ |
| 18460 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 18461 | offset += 4; |
| 18462 | tlv_offset = 0; |
| 18463 | |
| 18464 | /* |
| 18465 | * Search for configured port state sub-TLV. |
| 18466 | */ |
| 18467 | while ((offset < data_size) && |
| 18468 | (tlv_offset < sub_tlv_len)) { |
| 18469 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 18470 | offset += 4; |
| 18471 | tlv_offset += 4; |
| 18472 | break; |
| 18473 | } |
| 18474 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 18475 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 18476 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 18477 | continue; |
| 18478 | } |
| 18479 | |
| 18480 | /* This HBA contains PORT_STE configured */ |
| 18481 | if (!rgn23_data[offset + 2]) |
| 18482 | phba->hba_flag |= LINK_DISABLED; |
| 18483 | |
| 18484 | goto out; |
| 18485 | } |
| 18486 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18487 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18488 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18489 | kfree(rgn23_data); |
| 18490 | return; |
| 18491 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18492 | |
| 18493 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18494 | * lpfc_wr_object - write an object to the firmware |
| 18495 | * @phba: HBA structure that indicates port to create a queue on. |
| 18496 | * @dmabuf_list: list of dmabufs to write to the port. |
| 18497 | * @size: the total byte value of the objects to write to the port. |
| 18498 | * @offset: the current offset to be used to start the transfer. |
| 18499 | * |
| 18500 | * This routine will create a wr_object mailbox command to send to the port. |
| 18501 | * the mailbox command will be constructed using the dma buffers described in |
| 18502 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 18503 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 18504 | * used to indicate the starting offset of the transfer and will also return |
| 18505 | * the offset after the write object mailbox has completed. @size is used to |
| 18506 | * determine the end of the object and whether the eof bit should be set. |
| 18507 | * |
| 18508 | * Return 0 is successful and offset will contain the the new offset to use |
| 18509 | * for the next write. |
| 18510 | * Return negative value for error cases. |
| 18511 | **/ |
| 18512 | int |
| 18513 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 18514 | uint32_t size, uint32_t *offset) |
| 18515 | { |
| 18516 | struct lpfc_mbx_wr_object *wr_object; |
| 18517 | LPFC_MBOXQ_t *mbox; |
| 18518 | int rc = 0, i = 0; |
| 18519 | uint32_t shdr_status, shdr_add_status; |
| 18520 | uint32_t mbox_tmo; |
| 18521 | union lpfc_sli4_cfg_shdr *shdr; |
| 18522 | struct lpfc_dmabuf *dmabuf; |
| 18523 | uint32_t written = 0; |
| 18524 | |
| 18525 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18526 | if (!mbox) |
| 18527 | return -ENOMEM; |
| 18528 | |
| 18529 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 18530 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 18531 | sizeof(struct lpfc_mbx_wr_object) - |
| 18532 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 18533 | |
| 18534 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 18535 | wr_object->u.request.write_offset = *offset; |
| 18536 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 18537 | wr_object->u.request.object_name[0] = |
| 18538 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 18539 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 18540 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 18541 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 18542 | break; |
| 18543 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 18544 | wr_object->u.request.bde[i].addrHigh = |
| 18545 | putPaddrHigh(dmabuf->phys); |
| 18546 | if (written + SLI4_PAGE_SIZE >= size) { |
| 18547 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 18548 | (size - written); |
| 18549 | written += (size - written); |
| 18550 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 18551 | } else { |
| 18552 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 18553 | SLI4_PAGE_SIZE; |
| 18554 | written += SLI4_PAGE_SIZE; |
| 18555 | } |
| 18556 | i++; |
| 18557 | } |
| 18558 | wr_object->u.request.bde_count = i; |
| 18559 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 18560 | if (!phba->sli4_hba.intr_enable) |
| 18561 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 18562 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18563 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18564 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 18565 | } |
| 18566 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18567 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 18568 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18569 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18570 | if (rc != MBX_TIMEOUT) |
| 18571 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18572 | if (shdr_status || shdr_add_status || rc) { |
| 18573 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18574 | "3025 Write Object mailbox failed with " |
| 18575 | "status x%x add_status x%x, mbx status x%x\n", |
| 18576 | shdr_status, shdr_add_status, rc); |
| 18577 | rc = -ENXIO; |
| 18578 | } else |
| 18579 | *offset += wr_object->u.response.actual_write_length; |
| 18580 | return rc; |
| 18581 | } |
| 18582 | |
| 18583 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18584 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 18585 | * @vport: pointer to vport data structure. |
| 18586 | * |
| 18587 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 18588 | * and REG_VPI mailbox commands associated with the vport. This function |
| 18589 | * is called when driver want to restart discovery of the vport due to |
| 18590 | * a Clear Virtual Link event. |
| 18591 | **/ |
| 18592 | void |
| 18593 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 18594 | { |
| 18595 | struct lpfc_hba *phba = vport->phba; |
| 18596 | LPFC_MBOXQ_t *mb, *nextmb; |
| 18597 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18598 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18599 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 18600 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18601 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 18602 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18603 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18604 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18605 | spin_lock_irq(&phba->hbalock); |
| 18606 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 18607 | if (mb->vport != vport) |
| 18608 | continue; |
| 18609 | |
| 18610 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 18611 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 18612 | continue; |
| 18613 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18614 | list_del(&mb->list); |
| 18615 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 18616 | } |
| 18617 | /* Clean up active mailbox command with the vport */ |
| 18618 | mb = phba->sli.mbox_active; |
| 18619 | if (mb && (mb->vport == vport)) { |
| 18620 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 18621 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 18622 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 18623 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18624 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 18625 | /* Put reference count for delayed processing */ |
| 18626 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 18627 | /* Unregister the RPI when mailbox complete */ |
| 18628 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 18629 | } |
| 18630 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 18631 | /* Cleanup any mailbox completions which are not yet processed */ |
| 18632 | do { |
| 18633 | restart_loop = 0; |
| 18634 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 18635 | /* |
| 18636 | * If this mailox is already processed or it is |
| 18637 | * for another vport ignore it. |
| 18638 | */ |
| 18639 | if ((mb->vport != vport) || |
| 18640 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 18641 | continue; |
| 18642 | |
| 18643 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 18644 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 18645 | continue; |
| 18646 | |
| 18647 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 18648 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18649 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 18650 | /* Unregister the RPI when mailbox complete */ |
| 18651 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 18652 | restart_loop = 1; |
| 18653 | spin_unlock_irq(&phba->hbalock); |
| 18654 | spin_lock(shost->host_lock); |
| 18655 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 18656 | spin_unlock(shost->host_lock); |
| 18657 | spin_lock_irq(&phba->hbalock); |
| 18658 | break; |
| 18659 | } |
| 18660 | } |
| 18661 | } while (restart_loop); |
| 18662 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18663 | spin_unlock_irq(&phba->hbalock); |
| 18664 | |
| 18665 | /* Release the cleaned-up mailbox commands */ |
| 18666 | while (!list_empty(&mbox_cmd_list)) { |
| 18667 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18668 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18669 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 18670 | if (mp) { |
| 18671 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 18672 | kfree(mp); |
| 18673 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18674 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18675 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18676 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 18677 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 18678 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 18679 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18680 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18681 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18682 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18683 | mempool_free(mb, phba->mbox_mem_pool); |
| 18684 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18685 | |
| 18686 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 18687 | if (act_mbx_ndlp) { |
| 18688 | spin_lock(shost->host_lock); |
| 18689 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 18690 | spin_unlock(shost->host_lock); |
| 18691 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18692 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18693 | } |
| 18694 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18695 | /** |
| 18696 | * lpfc_drain_txq - Drain the txq |
| 18697 | * @phba: Pointer to HBA context object. |
| 18698 | * |
| 18699 | * This function attempt to submit IOCBs on the txq |
| 18700 | * to the adapter. For SLI4 adapters, the txq contains |
| 18701 | * ELS IOCBs that have been deferred because the there |
| 18702 | * are no SGLs. This congestion can occur with large |
| 18703 | * vport counts during node discovery. |
| 18704 | **/ |
| 18705 | |
| 18706 | uint32_t |
| 18707 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 18708 | { |
| 18709 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18710 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 18711 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18712 | unsigned long iflags = 0; |
| 18713 | char *fail_msg = NULL; |
| 18714 | struct lpfc_sglq *sglq; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18715 | union lpfc_wqe128 wqe128; |
| 18716 | union lpfc_wqe *wqe = (union lpfc_wqe *) &wqe128; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 18717 | uint32_t txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18718 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18719 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 27b1313 | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 18720 | if (unlikely(!pring)) |
| 18721 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18722 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18723 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18724 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 18725 | txq_cnt++; |
| 18726 | } |
| 18727 | |
| 18728 | if (txq_cnt > pring->txq_max) |
| 18729 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18730 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18731 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18732 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18733 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18734 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18735 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 18736 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18737 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18738 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18739 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18740 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18741 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18742 | break; |
| 18743 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18744 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18745 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 18746 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18747 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18748 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18749 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18750 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18751 | |
| 18752 | /* The xri and iocb resources secured, |
| 18753 | * attempt to issue request |
| 18754 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18755 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18756 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 18757 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 18758 | fail_msg = "to convert bpl to sgl"; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18759 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18760 | fail_msg = "to convert iocb to wqe"; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18761 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18762 | fail_msg = " - Wq is full"; |
| 18763 | else |
| 18764 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 18765 | |
| 18766 | if (fail_msg) { |
| 18767 | /* Failed means we can't issue and need to cancel */ |
| 18768 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18769 | "2822 IOCB failed %s iotag 0x%x " |
| 18770 | "xri 0x%x\n", |
| 18771 | fail_msg, |
| 18772 | piocbq->iotag, piocbq->sli4_xritag); |
| 18773 | list_add_tail(&piocbq->list, &completions); |
| 18774 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18775 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18776 | } |
| 18777 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18778 | /* Cancel all the IOCBs that cannot be issued */ |
| 18779 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 18780 | IOERR_SLI_ABORTED); |
| 18781 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18782 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18783 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18784 | |
| 18785 | /** |
| 18786 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 18787 | * @phba: Pointer to HBA context object. |
| 18788 | * @pwqe: Pointer to command WQE. |
| 18789 | * @sglq: Pointer to the scatter gather queue object. |
| 18790 | * |
| 18791 | * This routine converts the bpl or bde that is in the WQE |
| 18792 | * to a sgl list for the sli4 hardware. The physical address |
| 18793 | * of the bpl/bde is converted back to a virtual address. |
| 18794 | * If the WQE contains a BPL then the list of BDE's is |
| 18795 | * converted to sli4_sge's. If the WQE contains a single |
| 18796 | * BDE then it is converted to a single sli_sge. |
| 18797 | * The WQE is still in cpu endianness so the contents of |
| 18798 | * the bpl can be used without byte swapping. |
| 18799 | * |
| 18800 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 18801 | */ |
| 18802 | static uint16_t |
| 18803 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 18804 | struct lpfc_sglq *sglq) |
| 18805 | { |
| 18806 | uint16_t xritag = NO_XRI; |
| 18807 | struct ulp_bde64 *bpl = NULL; |
| 18808 | struct ulp_bde64 bde; |
| 18809 | struct sli4_sge *sgl = NULL; |
| 18810 | struct lpfc_dmabuf *dmabuf; |
| 18811 | union lpfc_wqe *wqe; |
| 18812 | int numBdes = 0; |
| 18813 | int i = 0; |
| 18814 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 18815 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 18816 | uint32_t cmd; |
| 18817 | |
| 18818 | if (!pwqeq || !sglq) |
| 18819 | return xritag; |
| 18820 | |
| 18821 | sgl = (struct sli4_sge *)sglq->sgl; |
| 18822 | wqe = &pwqeq->wqe; |
| 18823 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 18824 | |
| 18825 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 18826 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 18827 | return sglq->sli4_xritag; |
| 18828 | numBdes = pwqeq->rsvd2; |
| 18829 | if (numBdes) { |
| 18830 | /* The addrHigh and addrLow fields within the WQE |
| 18831 | * have not been byteswapped yet so there is no |
| 18832 | * need to swap them back. |
| 18833 | */ |
| 18834 | if (pwqeq->context3) |
| 18835 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 18836 | else |
| 18837 | return xritag; |
| 18838 | |
| 18839 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 18840 | if (!bpl) |
| 18841 | return xritag; |
| 18842 | |
| 18843 | for (i = 0; i < numBdes; i++) { |
| 18844 | /* Should already be byte swapped. */ |
| 18845 | sgl->addr_hi = bpl->addrHigh; |
| 18846 | sgl->addr_lo = bpl->addrLow; |
| 18847 | |
| 18848 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 18849 | if ((i+1) == numBdes) |
| 18850 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 18851 | else |
| 18852 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 18853 | /* swap the size field back to the cpu so we |
| 18854 | * can assign it to the sgl. |
| 18855 | */ |
| 18856 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 18857 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 18858 | /* The offsets in the sgl need to be accumulated |
| 18859 | * separately for the request and reply lists. |
| 18860 | * The request is always first, the reply follows. |
| 18861 | */ |
| 18862 | switch (cmd) { |
| 18863 | case CMD_GEN_REQUEST64_WQE: |
| 18864 | /* add up the reply sg entries */ |
| 18865 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 18866 | inbound++; |
| 18867 | /* first inbound? reset the offset */ |
| 18868 | if (inbound == 1) |
| 18869 | offset = 0; |
| 18870 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 18871 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18872 | LPFC_SGE_TYPE_DATA); |
| 18873 | offset += bde.tus.f.bdeSize; |
| 18874 | break; |
| 18875 | case CMD_FCP_TRSP64_WQE: |
| 18876 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 18877 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18878 | LPFC_SGE_TYPE_DATA); |
| 18879 | break; |
| 18880 | case CMD_FCP_TSEND64_WQE: |
| 18881 | case CMD_FCP_TRECEIVE64_WQE: |
| 18882 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18883 | bpl->tus.f.bdeFlags); |
| 18884 | if (i < 3) |
| 18885 | offset = 0; |
| 18886 | else |
| 18887 | offset += bde.tus.f.bdeSize; |
| 18888 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 18889 | break; |
| 18890 | } |
| 18891 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 18892 | bpl++; |
| 18893 | sgl++; |
| 18894 | } |
| 18895 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 18896 | /* The addrHigh and addrLow fields of the BDE have not |
| 18897 | * been byteswapped yet so they need to be swapped |
| 18898 | * before putting them in the sgl. |
| 18899 | */ |
| 18900 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 18901 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 18902 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 18903 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 18904 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 18905 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 18906 | } |
| 18907 | return sglq->sli4_xritag; |
| 18908 | } |
| 18909 | |
| 18910 | /** |
| 18911 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 18912 | * @phba: Pointer to HBA context object. |
| 18913 | * @ring_number: Base sli ring number |
| 18914 | * @pwqe: Pointer to command WQE. |
| 18915 | **/ |
| 18916 | int |
| 18917 | lpfc_sli4_issue_wqe(struct lpfc_hba *phba, uint32_t ring_number, |
| 18918 | struct lpfc_iocbq *pwqe) |
| 18919 | { |
| 18920 | union lpfc_wqe *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 18921 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18922 | struct lpfc_queue *wq; |
| 18923 | struct lpfc_sglq *sglq; |
| 18924 | struct lpfc_sli_ring *pring; |
| 18925 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18926 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18927 | |
| 18928 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 18929 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 18930 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 18931 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 18932 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 18933 | if (!sglq) { |
| 18934 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18935 | return WQE_BUSY; |
| 18936 | } |
| 18937 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 18938 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 18939 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 18940 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18941 | return WQE_ERROR; |
| 18942 | } |
| 18943 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 18944 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18945 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 18946 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18947 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18948 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18949 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18950 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18951 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 18952 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18953 | return 0; |
| 18954 | } |
| 18955 | |
| 18956 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 18957 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 18958 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 18959 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 18960 | |
| 18961 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 18962 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 18963 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 18964 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18965 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 18966 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18967 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18968 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18969 | } |
| 18970 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 18971 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18972 | return 0; |
| 18973 | } |
| 18974 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 18975 | /* NVMET requests */ |
| 18976 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 18977 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 18978 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 18979 | |
| 18980 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 18981 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 18982 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 18983 | if (pwqe->sli4_xritag == NO_XRI) { |
| 18984 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 18985 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 18986 | } |
| 18987 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 18988 | pwqe->sli4_xritag); |
| 18989 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 18990 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 18991 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18992 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 18993 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 18994 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18995 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 18996 | } |
| 18997 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 18998 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18999 | return 0; |
| 19000 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19001 | return WQE_ERROR; |
| 19002 | } |