| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 128bdda | 2018-01-30 15:59:03 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * |
James Smart | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * 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] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 29 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 31 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | #include <scsi/scsi_cmnd.h> |
| 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 35 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 37 | #include <linux/aer.h> |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 38 | #ifdef CONFIG_X86 |
| 39 | #include <asm/set_memory.h> |
| 40 | #endif |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 42 | #include <linux/nvme-fc-driver.h> |
| 43 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 44 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc_hw.h" |
| 46 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 47 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 48 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 51 | #include "lpfc_scsi.h" |
| 52 | #include "lpfc_nvme.h" |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 53 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | #include "lpfc_crtn.h" |
| 55 | #include "lpfc_logmsg.h" |
| 56 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 57 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 58 | #include "lpfc_vport.h" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 59 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | |
| 61 | /* There are only four IOCB completion types. */ |
| 62 | typedef enum _lpfc_iocb_type { |
| 63 | LPFC_UNKNOWN_IOCB, |
| 64 | LPFC_UNSOL_IOCB, |
| 65 | LPFC_SOL_IOCB, |
| 66 | LPFC_ABORT_IOCB |
| 67 | } lpfc_iocb_type; |
| 68 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 69 | |
| 70 | /* Provide function prototypes local to this module. */ |
| 71 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 72 | uint32_t); |
| 73 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 74 | uint8_t *, uint32_t *); |
| 75 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 76 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 77 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 78 | struct hbq_dmabuf *); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 79 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 80 | struct hbq_dmabuf *dmabuf); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 81 | 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] | 82 | struct lpfc_cqe *); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 83 | 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] | 84 | int); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 85 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
| 86 | struct lpfc_eqe *eqe, uint32_t qidx); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 87 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 88 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 89 | static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, |
| 90 | struct lpfc_sli_ring *pring, |
| 91 | struct lpfc_iocbq *cmdiocb); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 92 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 93 | static IOCB_t * |
| 94 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 95 | { |
| 96 | return &iocbq->iocb; |
| 97 | } |
| 98 | |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 99 | #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN) |
| 100 | /** |
| 101 | * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function |
| 102 | * @srcp: Source memory pointer. |
| 103 | * @destp: Destination memory pointer. |
| 104 | * @cnt: Number of words required to be copied. |
| 105 | * Must be a multiple of sizeof(uint64_t) |
| 106 | * |
| 107 | * This function is used for copying data between driver memory |
| 108 | * and the SLI WQ. This function also changes the endianness |
| 109 | * of each word if native endianness is different from SLI |
| 110 | * endianness. This function can be called with or without |
| 111 | * lock. |
| 112 | **/ |
| 113 | void |
| 114 | lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 115 | { |
| 116 | uint64_t *src = srcp; |
| 117 | uint64_t *dest = destp; |
| 118 | int i; |
| 119 | |
| 120 | for (i = 0; i < (int)cnt; i += sizeof(uint64_t)) |
| 121 | *dest++ = *src++; |
| 122 | } |
| 123 | #else |
| 124 | #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c) |
| 125 | #endif |
| 126 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 127 | /** |
| 128 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 129 | * @q: The Work Queue to operate on. |
| 130 | * @wqe: The work Queue Entry to put on the Work queue. |
| 131 | * |
| 132 | * This routine will copy the contents of @wqe to the next available entry on |
| 133 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 134 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 135 | * successful. If no entries are available on @q then this function will return |
| 136 | * -ENOMEM. |
| 137 | * The caller is expected to hold the hbalock when calling this routine. |
| 138 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 139 | static int |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 140 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 141 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 142 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 143 | struct lpfc_register doorbell; |
| 144 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 145 | uint32_t idx; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 146 | uint32_t i = 0; |
| 147 | uint8_t *tmp; |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 148 | u32 if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 149 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 150 | /* sanity check on queue memory */ |
| 151 | if (unlikely(!q)) |
| 152 | return -ENOMEM; |
| 153 | temp_wqe = q->qe[q->host_index].wqe; |
| 154 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 155 | /* 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] | 156 | idx = ((q->host_index + 1) % q->entry_count); |
| 157 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 158 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 159 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 160 | } |
| 161 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 162 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 163 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 164 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 04673e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 165 | else |
| 166 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 167 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 168 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 169 | lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 170 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 171 | /* write to DPP aperture taking advatage of Combined Writes */ |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 172 | tmp = (uint8_t *)temp_wqe; |
| 173 | #ifdef __raw_writeq |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 174 | for (i = 0; i < q->entry_size; i += sizeof(uint64_t)) |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 175 | __raw_writeq(*((uint64_t *)(tmp + i)), |
| 176 | q->dpp_regaddr + i); |
| 177 | #else |
| 178 | for (i = 0; i < q->entry_size; i += sizeof(uint32_t)) |
| 179 | __raw_writel(*((uint32_t *)(tmp + i)), |
| 180 | q->dpp_regaddr + i); |
| 181 | #endif |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 182 | } |
| 183 | /* ensure WQE bcopy and DPP flushed before doorbell write */ |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 184 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 185 | |
| 186 | /* Update the host index before invoking device */ |
| 187 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 188 | |
| 189 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 190 | |
| 191 | /* Ring Doorbell */ |
| 192 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 193 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 194 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 195 | bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1); |
| 196 | bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1); |
| 197 | bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell, |
| 198 | q->dpp_id); |
| 199 | bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell, |
| 200 | q->queue_id); |
| 201 | } else { |
| 202 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 203 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 204 | |
| 205 | /* Leave bits <23:16> clear for if_type 6 dpp */ |
| 206 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 207 | &q->phba->sli4_hba.sli_intf); |
| 208 | if (if_type != LPFC_SLI_INTF_IF_TYPE_6) |
| 209 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, |
| 210 | host_index); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 211 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 212 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 213 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 214 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 215 | } else { |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 225 | * @q: The Work Queue to operate on. |
| 226 | * @index: The index to advance the hba index to. |
| 227 | * |
| 228 | * This routine will update the HBA index of a queue to reflect consumption of |
| 229 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 230 | * an entry the host calls this function to update the queue's internal |
| 231 | * pointers. This routine returns the number of entries that were consumed by |
| 232 | * the HBA. |
| 233 | **/ |
| 234 | static uint32_t |
| 235 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 236 | { |
| 237 | uint32_t released = 0; |
| 238 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 239 | /* sanity check on queue memory */ |
| 240 | if (unlikely(!q)) |
| 241 | return 0; |
| 242 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 243 | if (q->hba_index == index) |
| 244 | return 0; |
| 245 | do { |
| 246 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 247 | released++; |
| 248 | } while (q->hba_index != index); |
| 249 | return released; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 254 | * @q: The Mailbox Queue to operate on. |
| 255 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 256 | * |
| 257 | * This routine will copy the contents of @mqe to the next available entry on |
| 258 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 259 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 260 | * successful. If no entries are available on @q then this function will return |
| 261 | * -ENOMEM. |
| 262 | * The caller is expected to hold the hbalock when calling this routine. |
| 263 | **/ |
| 264 | static uint32_t |
| 265 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 266 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 267 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 268 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 269 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 270 | /* sanity check on queue memory */ |
| 271 | if (unlikely(!q)) |
| 272 | return -ENOMEM; |
| 273 | temp_mqe = q->qe[q->host_index].mqe; |
| 274 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 275 | /* If the host has not yet processed the next entry then we are done */ |
| 276 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 277 | return -ENOMEM; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 278 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 279 | /* Save off the mailbox pointer for completion */ |
| 280 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 281 | |
| 282 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 283 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 284 | |
| 285 | /* Ring Doorbell */ |
| 286 | doorbell.word0 = 0; |
| 287 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 288 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 289 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 295 | * @q: The Mailbox Queue to operate on. |
| 296 | * |
| 297 | * This routine will update the HBA index of a queue to reflect consumption of |
| 298 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 299 | * an entry the host calls this function to update the queue's internal |
| 300 | * pointers. This routine returns the number of entries that were consumed by |
| 301 | * the HBA. |
| 302 | **/ |
| 303 | static uint32_t |
| 304 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 305 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 306 | /* sanity check on queue memory */ |
| 307 | if (unlikely(!q)) |
| 308 | return 0; |
| 309 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 310 | /* Clear the mailbox pointer for completion */ |
| 311 | q->phba->mbox = NULL; |
| 312 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 313 | return 1; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 318 | * @q: The Event Queue to get the first valid EQE from |
| 319 | * |
| 320 | * This routine will get the first valid Event Queue Entry from @q, update |
| 321 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 322 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 323 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 324 | **/ |
| 325 | static struct lpfc_eqe * |
| 326 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 327 | { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 328 | struct lpfc_hba *phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 329 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 330 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 331 | |
| 332 | /* sanity check on queue memory */ |
| 333 | if (unlikely(!q)) |
| 334 | return NULL; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 335 | phba = q->phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 336 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 337 | |
| 338 | /* If the next EQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 339 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 340 | return NULL; |
| 341 | /* 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] | 342 | idx = ((q->hba_index + 1) % q->entry_count); |
| 343 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 344 | return NULL; |
| 345 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 346 | q->hba_index = idx; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 347 | /* if the index wrapped around, toggle the valid bit */ |
| 348 | if (phba->sli4_hba.pc_sli4_params.eqav && !q->hba_index) |
| 349 | q->qe_valid = (q->qe_valid) ? 0 : 1; |
| 350 | |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 351 | |
| 352 | /* |
| 353 | * insert barrier for instruction interlock : data from the hardware |
| 354 | * 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] | 355 | * upon. Speculative instructions were allowing a bcopy at the start |
| 356 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 357 | * after our return, to copy data before the valid bit check above |
| 358 | * was done. As such, some of the copied data was stale. The barrier |
| 359 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 360 | */ |
| 361 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 362 | return eqe; |
| 363 | } |
| 364 | |
| 365 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 366 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 367 | * @q: The Event Queue to disable interrupts |
| 368 | * |
| 369 | **/ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 370 | inline void |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 371 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 372 | { |
| 373 | struct lpfc_register doorbell; |
| 374 | |
| 375 | doorbell.word0 = 0; |
| 376 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 377 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 378 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 379 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 380 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 381 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 385 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ |
| 386 | * @q: The Event Queue to disable interrupts |
| 387 | * |
| 388 | **/ |
| 389 | inline void |
| 390 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) |
| 391 | { |
| 392 | struct lpfc_register doorbell; |
| 393 | |
| 394 | doorbell.word0 = 0; |
James Smart | aad59d5 | 2018-09-10 10:30:47 -0700 | [diff] [blame] | 395 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 396 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 397 | } |
| 398 | |
| 399 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 400 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 401 | * @q: The Event Queue that the host has completed processing for. |
| 402 | * @arm: Indicates whether the host wants to arms this CQ. |
| 403 | * |
| 404 | * This routine will mark all Event Queue Entries on @q, from the last |
| 405 | * known completed entry to the last entry that was processed, as completed |
| 406 | * by clearing the valid bit for each completion queue entry. Then it will |
| 407 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 408 | * The internal host index in the @q will be updated by this routine to indicate |
| 409 | * that the host has finished processing the entries. The @arm parameter |
| 410 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 411 | * |
| 412 | * This function will return the number of EQEs that were popped. |
| 413 | **/ |
| 414 | uint32_t |
| 415 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 416 | { |
| 417 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 418 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 419 | struct lpfc_eqe *temp_eqe; |
| 420 | struct lpfc_register doorbell; |
| 421 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 422 | /* sanity check on queue memory */ |
| 423 | if (unlikely(!q)) |
| 424 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 425 | phba = q->phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 426 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 427 | /* while there are valid entries */ |
| 428 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 429 | if (!phba->sli4_hba.pc_sli4_params.eqav) { |
| 430 | temp_eqe = q->qe[q->host_index].eqe; |
| 431 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
| 432 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 433 | released++; |
| 434 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 435 | } |
| 436 | if (unlikely(released == 0 && !arm)) |
| 437 | return 0; |
| 438 | |
| 439 | /* ring doorbell for number popped */ |
| 440 | doorbell.word0 = 0; |
| 441 | if (arm) { |
| 442 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 443 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 444 | } |
| 445 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 446 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 447 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 448 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 449 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 450 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 451 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 452 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 453 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 454 | return released; |
| 455 | } |
| 456 | |
| 457 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 458 | * lpfc_sli4_if6_eq_release - Indicates the host has finished processing an EQ |
| 459 | * @q: The Event Queue that the host has completed processing for. |
| 460 | * @arm: Indicates whether the host wants to arms this CQ. |
| 461 | * |
| 462 | * This routine will mark all Event Queue Entries on @q, from the last |
| 463 | * known completed entry to the last entry that was processed, as completed |
| 464 | * by clearing the valid bit for each completion queue entry. Then it will |
| 465 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 466 | * The internal host index in the @q will be updated by this routine to indicate |
| 467 | * that the host has finished processing the entries. The @arm parameter |
| 468 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 469 | * |
| 470 | * This function will return the number of EQEs that were popped. |
| 471 | **/ |
| 472 | uint32_t |
| 473 | lpfc_sli4_if6_eq_release(struct lpfc_queue *q, bool arm) |
| 474 | { |
| 475 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 476 | struct lpfc_hba *phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 477 | struct lpfc_eqe *temp_eqe; |
| 478 | struct lpfc_register doorbell; |
| 479 | |
| 480 | /* sanity check on queue memory */ |
| 481 | if (unlikely(!q)) |
| 482 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 483 | phba = q->phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 484 | |
| 485 | /* while there are valid entries */ |
| 486 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 487 | if (!phba->sli4_hba.pc_sli4_params.eqav) { |
| 488 | temp_eqe = q->qe[q->host_index].eqe; |
| 489 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
| 490 | } |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 491 | released++; |
| 492 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 493 | } |
| 494 | if (unlikely(released == 0 && !arm)) |
| 495 | return 0; |
| 496 | |
| 497 | /* ring doorbell for number popped */ |
| 498 | doorbell.word0 = 0; |
| 499 | if (arm) |
| 500 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); |
| 501 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, released); |
| 502 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
| 503 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 504 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 505 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 506 | readl(q->phba->sli4_hba.EQDBregaddr); |
| 507 | return released; |
| 508 | } |
| 509 | |
| 510 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 511 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 512 | * @q: The Completion Queue to get the first valid CQE from |
| 513 | * |
| 514 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 515 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 516 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 517 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 518 | **/ |
| 519 | static struct lpfc_cqe * |
| 520 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 521 | { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 522 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 523 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 524 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 525 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 526 | /* sanity check on queue memory */ |
| 527 | if (unlikely(!q)) |
| 528 | return NULL; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 529 | phba = q->phba; |
| 530 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 531 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 532 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 533 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 534 | return NULL; |
| 535 | /* 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] | 536 | idx = ((q->hba_index + 1) % q->entry_count); |
| 537 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 538 | return NULL; |
| 539 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 540 | q->hba_index = idx; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 541 | /* if the index wrapped around, toggle the valid bit */ |
| 542 | if (phba->sli4_hba.pc_sli4_params.cqav && !q->hba_index) |
| 543 | q->qe_valid = (q->qe_valid) ? 0 : 1; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 544 | |
| 545 | /* |
| 546 | * insert barrier for instruction interlock : data from the hardware |
| 547 | * 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] | 548 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 549 | * instructions allowing action on content before valid bit checked, |
| 550 | * add barrier here as well. May not be needed as "content" is a |
| 551 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 552 | */ |
| 553 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 554 | return cqe; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 559 | * @q: The Completion Queue that the host has completed processing for. |
| 560 | * @arm: Indicates whether the host wants to arms this CQ. |
| 561 | * |
| 562 | * This routine will mark all Completion queue entries on @q, from the last |
| 563 | * known completed entry to the last entry that was processed, as completed |
| 564 | * by clearing the valid bit for each completion queue entry. Then it will |
| 565 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 566 | * The internal host index in the @q will be updated by this routine to indicate |
| 567 | * that the host has finished processing the entries. The @arm parameter |
| 568 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 569 | * |
| 570 | * This function will return the number of CQEs that were released. |
| 571 | **/ |
| 572 | uint32_t |
| 573 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 574 | { |
| 575 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 576 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 577 | struct lpfc_cqe *temp_qe; |
| 578 | struct lpfc_register doorbell; |
| 579 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 580 | /* sanity check on queue memory */ |
| 581 | if (unlikely(!q)) |
| 582 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 583 | phba = q->phba; |
| 584 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 585 | /* while there are valid entries */ |
| 586 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 587 | if (!phba->sli4_hba.pc_sli4_params.cqav) { |
| 588 | temp_qe = q->qe[q->host_index].cqe; |
| 589 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
| 590 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 591 | released++; |
| 592 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 593 | } |
| 594 | if (unlikely(released == 0 && !arm)) |
| 595 | return 0; |
| 596 | |
| 597 | /* ring doorbell for number popped */ |
| 598 | doorbell.word0 = 0; |
| 599 | if (arm) |
| 600 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 601 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 602 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 603 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 604 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 605 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 606 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 607 | return released; |
| 608 | } |
| 609 | |
| 610 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 611 | * lpfc_sli4_if6_cq_release - Indicates the host has finished processing a CQ |
| 612 | * @q: The Completion Queue that the host has completed processing for. |
| 613 | * @arm: Indicates whether the host wants to arms this CQ. |
| 614 | * |
| 615 | * This routine will mark all Completion queue entries on @q, from the last |
| 616 | * known completed entry to the last entry that was processed, as completed |
| 617 | * by clearing the valid bit for each completion queue entry. Then it will |
| 618 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 619 | * The internal host index in the @q will be updated by this routine to indicate |
| 620 | * that the host has finished processing the entries. The @arm parameter |
| 621 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 622 | * |
| 623 | * This function will return the number of CQEs that were released. |
| 624 | **/ |
| 625 | uint32_t |
| 626 | lpfc_sli4_if6_cq_release(struct lpfc_queue *q, bool arm) |
| 627 | { |
| 628 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 629 | struct lpfc_hba *phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 630 | struct lpfc_cqe *temp_qe; |
| 631 | struct lpfc_register doorbell; |
| 632 | |
| 633 | /* sanity check on queue memory */ |
| 634 | if (unlikely(!q)) |
| 635 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 636 | phba = q->phba; |
| 637 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 638 | /* while there are valid entries */ |
| 639 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 640 | if (!phba->sli4_hba.pc_sli4_params.cqav) { |
| 641 | temp_qe = q->qe[q->host_index].cqe; |
| 642 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
| 643 | } |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 644 | released++; |
| 645 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 646 | } |
| 647 | if (unlikely(released == 0 && !arm)) |
| 648 | return 0; |
| 649 | |
| 650 | /* ring doorbell for number popped */ |
| 651 | doorbell.word0 = 0; |
| 652 | if (arm) |
| 653 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
| 654 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, released); |
| 655 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 656 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
| 657 | return released; |
| 658 | } |
| 659 | |
| 660 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 661 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 662 | * @q: The Header Receive Queue to operate on. |
| 663 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 664 | * |
| 665 | * This routine will copy the contents of @wqe to the next available entry on |
| 666 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 667 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 668 | * index that the rqe was copied to if successful. If no entries are available |
| 669 | * on @q then this function will return -ENOMEM. |
| 670 | * The caller is expected to hold the hbalock when calling this routine. |
| 671 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 672 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 673 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 674 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 675 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 676 | struct lpfc_rqe *temp_hrqe; |
| 677 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 678 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 679 | int hq_put_index; |
| 680 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 681 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 682 | /* sanity check on queue memory */ |
| 683 | if (unlikely(!hq) || unlikely(!dq)) |
| 684 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 685 | hq_put_index = hq->host_index; |
| 686 | dq_put_index = dq->host_index; |
| 687 | temp_hrqe = hq->qe[hq_put_index].rqe; |
| 688 | temp_drqe = dq->qe[dq_put_index].rqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 689 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 690 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 691 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 692 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 693 | return -EINVAL; |
| 694 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 695 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 696 | return -EBUSY; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 697 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 698 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 699 | |
| 700 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 701 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 702 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 703 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 704 | |
| 705 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 706 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 707 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 708 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 709 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 710 | hq->entry_repost); |
| 711 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 712 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 713 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 714 | hq->entry_repost); |
| 715 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 716 | hq->host_index); |
| 717 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 718 | } else { |
| 719 | return -EINVAL; |
| 720 | } |
| 721 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 722 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 723 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
| 727 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 728 | * @q: The Header Receive Queue to operate on. |
| 729 | * |
| 730 | * This routine will update the HBA index of a queue to reflect consumption of |
| 731 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 732 | * consumed an entry the host calls this function to update the queue's |
| 733 | * internal pointers. This routine returns the number of entries that were |
| 734 | * consumed by the HBA. |
| 735 | **/ |
| 736 | static uint32_t |
| 737 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 738 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 739 | /* sanity check on queue memory */ |
| 740 | if (unlikely(!hq) || unlikely(!dq)) |
| 741 | return 0; |
| 742 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 743 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 744 | return 0; |
| 745 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 746 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 747 | return 1; |
| 748 | } |
| 749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 750 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 751 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 752 | * @phba: Pointer to HBA context object. |
| 753 | * @pring: Pointer to driver SLI ring object. |
| 754 | * |
| 755 | * This function returns pointer to next command iocb entry |
| 756 | * in the command ring. The caller must hold hbalock to prevent |
| 757 | * other threads consume the next command iocb. |
| 758 | * SLI-2/SLI-3 provide different sized iocbs. |
| 759 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 760 | static inline IOCB_t * |
| 761 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 762 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 763 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 764 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 765 | } |
| 766 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 767 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 768 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 769 | * @phba: Pointer to HBA context object. |
| 770 | * @pring: Pointer to driver SLI ring object. |
| 771 | * |
| 772 | * This function returns pointer to next response iocb entry |
| 773 | * in the response ring. The caller must hold hbalock to make sure |
| 774 | * that no other thread consume the next response iocb. |
| 775 | * SLI-2/SLI-3 provide different sized iocbs. |
| 776 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 777 | static inline IOCB_t * |
| 778 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 779 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 780 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 781 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 782 | } |
| 783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 784 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 785 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 786 | * @phba: Pointer to HBA context object. |
| 787 | * |
| 788 | * This function is called with hbalock held. This function |
| 789 | * allocates a new driver iocb object from the iocb pool. If the |
| 790 | * allocation is successful, it returns pointer to the newly |
| 791 | * allocated iocb object else it returns NULL. |
| 792 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 793 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 794 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 795 | { |
| 796 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 797 | struct lpfc_iocbq * iocbq = NULL; |
| 798 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 799 | lockdep_assert_held(&phba->hbalock); |
| 800 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 801 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 802 | if (iocbq) |
| 803 | phba->iocb_cnt++; |
| 804 | if (phba->iocb_cnt > phba->iocb_max) |
| 805 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 806 | return iocbq; |
| 807 | } |
| 808 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 809 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 810 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 811 | * @phba: Pointer to HBA context object. |
| 812 | * @xritag: XRI value. |
| 813 | * |
| 814 | * This function clears the sglq pointer from the array of acive |
| 815 | * sglq's. The xritag that is passed in is used to index into the |
| 816 | * array. Before the xritag can be used it needs to be adjusted |
| 817 | * by subtracting the xribase. |
| 818 | * |
| 819 | * Returns sglq ponter = success, NULL = Failure. |
| 820 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 821 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 822 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 823 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 824 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 825 | |
| 826 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 827 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 828 | return sglq; |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 833 | * @phba: Pointer to HBA context object. |
| 834 | * @xritag: XRI value. |
| 835 | * |
| 836 | * This function returns the sglq pointer from the array of acive |
| 837 | * sglq's. The xritag that is passed in is used to index into the |
| 838 | * array. Before the xritag can be used it needs to be adjusted |
| 839 | * by subtracting the xribase. |
| 840 | * |
| 841 | * Returns sglq ponter = success, NULL = Failure. |
| 842 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 843 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 844 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 845 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 846 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 847 | |
| 848 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 849 | return sglq; |
| 850 | } |
| 851 | |
| 852 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 853 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 854 | * @phba: Pointer to HBA context object. |
| 855 | * @xritag: xri used in this exchange. |
| 856 | * @rrq: The RRQ to be cleared. |
| 857 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 858 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 859 | void |
| 860 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 861 | uint16_t xritag, |
| 862 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 863 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 864 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 865 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 866 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 867 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 868 | |
| 869 | /* The target DID could have been swapped (cable swap) |
| 870 | * we should use the ndlp from the findnode if it is |
| 871 | * available. |
| 872 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 873 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 874 | ndlp = rrq->ndlp; |
| 875 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 876 | if (!ndlp) |
| 877 | goto out; |
| 878 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 879 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 880 | rrq->send_rrq = 0; |
| 881 | rrq->xritag = 0; |
| 882 | rrq->rrq_stop_time = 0; |
| 883 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 884 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 885 | mempool_free(rrq, phba->rrq_pool); |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 890 | * @phba: Pointer to HBA context object. |
| 891 | * |
| 892 | * This function is called with hbalock held. This function |
| 893 | * Checks if stop_time (ratov from setting rrq active) has |
| 894 | * been reached, if it has and the send_rrq flag is set then |
| 895 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 896 | * then it will just call the routine to clear the rrq and |
| 897 | * free the rrq resource. |
| 898 | * The timer is set to the next rrq that is going to expire before |
| 899 | * leaving the routine. |
| 900 | * |
| 901 | **/ |
| 902 | void |
| 903 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 904 | { |
| 905 | struct lpfc_node_rrq *rrq; |
| 906 | struct lpfc_node_rrq *nextrrq; |
| 907 | unsigned long next_time; |
| 908 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 909 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 910 | |
| 911 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 912 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 913 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 914 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 915 | &phba->active_rrq_list, list) { |
| 916 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 917 | list_move(&rrq->list, &send_rrq); |
| 918 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 919 | next_time = rrq->rrq_stop_time; |
| 920 | } |
| 921 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 922 | if ((!list_empty(&phba->active_rrq_list)) && |
| 923 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 924 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 925 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 926 | list_del(&rrq->list); |
| 927 | if (!rrq->send_rrq) |
| 928 | /* this call will free the rrq */ |
| 929 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 930 | else if (lpfc_send_rrq(phba, rrq)) { |
| 931 | /* if we send the rrq then the completion handler |
| 932 | * will clear the bit in the xribitmap. |
| 933 | */ |
| 934 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 935 | rrq); |
| 936 | } |
| 937 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /** |
| 941 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 942 | * @vport: Pointer to vport context object. |
| 943 | * @xri: The xri used in the exchange. |
| 944 | * @did: The targets DID for this exchange. |
| 945 | * |
| 946 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 947 | * rrq = rrq for this xri and target. |
| 948 | **/ |
| 949 | struct lpfc_node_rrq * |
| 950 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 951 | { |
| 952 | struct lpfc_hba *phba = vport->phba; |
| 953 | struct lpfc_node_rrq *rrq; |
| 954 | struct lpfc_node_rrq *nextrrq; |
| 955 | unsigned long iflags; |
| 956 | |
| 957 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 958 | return NULL; |
| 959 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 960 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 961 | if (rrq->vport == vport && rrq->xritag == xri && |
| 962 | rrq->nlp_DID == did){ |
| 963 | list_del(&rrq->list); |
| 964 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 965 | return rrq; |
| 966 | } |
| 967 | } |
| 968 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 969 | return NULL; |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 974 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 975 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 976 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 977 | * phba->active_rrq_list and clear the rrq. |
| 978 | * 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] | 979 | **/ |
| 980 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 981 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 982 | |
| 983 | { |
| 984 | struct lpfc_hba *phba = vport->phba; |
| 985 | struct lpfc_node_rrq *rrq; |
| 986 | struct lpfc_node_rrq *nextrrq; |
| 987 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 988 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 989 | |
| 990 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 991 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 992 | if (!ndlp) { |
| 993 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 994 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 995 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 996 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 997 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 998 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 999 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1000 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1001 | |
| 1002 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 1003 | list_del(&rrq->list); |
| 1004 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1005 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1009 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1010 | * @phba: Pointer to HBA context object. |
| 1011 | * @ndlp: Targets nodelist pointer for this exchange. |
| 1012 | * @xritag the xri in the bitmap to test. |
| 1013 | * |
| 1014 | * This function is called with hbalock held. This function |
| 1015 | * returns 0 = rrq not active for this xri |
| 1016 | * 1 = rrq is valid for this xri. |
| 1017 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1018 | int |
| 1019 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1020 | uint16_t xritag) |
| 1021 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1022 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1023 | if (!ndlp) |
| 1024 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1025 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1026 | return 0; |
| 1027 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1028 | return 1; |
| 1029 | else |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1035 | * @phba: Pointer to HBA context object. |
| 1036 | * @ndlp: nodelist pointer for this target. |
| 1037 | * @xritag: xri used in this exchange. |
| 1038 | * @rxid: Remote Exchange ID. |
| 1039 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1040 | * |
| 1041 | * This function takes the hbalock. |
| 1042 | * The active bit is always set in the active rrq xri_bitmap even |
| 1043 | * if there is no slot avaiable for the other rrq information. |
| 1044 | * |
| 1045 | * returns 0 rrq actived for this xri |
| 1046 | * < 0 No memory or invalid ndlp. |
| 1047 | **/ |
| 1048 | int |
| 1049 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1050 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1051 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1052 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1053 | struct lpfc_node_rrq *rrq; |
| 1054 | int empty; |
| 1055 | |
| 1056 | if (!ndlp) |
| 1057 | return -EINVAL; |
| 1058 | |
| 1059 | if (!phba->cfg_enable_rrq) |
| 1060 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1061 | |
| 1062 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1063 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1064 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1065 | goto out; |
| 1066 | } |
| 1067 | |
| 1068 | /* |
| 1069 | * set the active bit even if there is no mem available. |
| 1070 | */ |
| 1071 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 1072 | goto out; |
| 1073 | |
| 1074 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1075 | goto out; |
| 1076 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1077 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1078 | goto out; |
| 1079 | |
| 1080 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1081 | goto out; |
| 1082 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1083 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1084 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 1085 | if (!rrq) { |
| 1086 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1087 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1088 | " DID:0x%x Send:%d\n", |
| 1089 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1090 | return -EINVAL; |
| 1091 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1092 | if (phba->cfg_enable_rrq == 1) |
| 1093 | rrq->send_rrq = send_rrq; |
| 1094 | else |
| 1095 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1096 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1097 | rrq->rrq_stop_time = jiffies + |
| 1098 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1099 | rrq->ndlp = ndlp; |
| 1100 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1101 | rrq->vport = ndlp->vport; |
| 1102 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1103 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1104 | empty = list_empty(&phba->active_rrq_list); |
| 1105 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1106 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1107 | if (empty) |
| 1108 | lpfc_worker_wake_up(phba); |
| 1109 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1110 | return 0; |
| 1111 | out: |
| 1112 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1113 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1114 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1115 | " DID:0x%x Send:%d\n", |
| 1116 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1117 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1121 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1122 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1123 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1124 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1125 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1126 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1127 | * list is not empty then it is successful, it returns pointer to the newly |
| 1128 | * allocated sglq object else it returns NULL. |
| 1129 | **/ |
| 1130 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1131 | __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] | 1132 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1133 | 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] | 1134 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1135 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1136 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1137 | struct lpfc_nodelist *ndlp; |
| 1138 | int found = 0; |
| 1139 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1140 | lockdep_assert_held(&phba->hbalock); |
| 1141 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1142 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1143 | lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1144 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1145 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1146 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1147 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1148 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1149 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1150 | ndlp = NULL; |
| 1151 | else |
| 1152 | ndlp = piocbq->context_un.ndlp; |
| 1153 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1154 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1155 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1156 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1157 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1158 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1159 | start_sglq = sglq; |
| 1160 | while (!found) { |
| 1161 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1162 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1163 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1164 | test_bit(sglq->sli4_lxritag, |
| 1165 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1166 | /* This xri has an rrq outstanding for this DID. |
| 1167 | * put it back in the list and get another xri. |
| 1168 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1169 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1170 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1171 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1172 | struct lpfc_sglq, list); |
| 1173 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1174 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1175 | sglq = NULL; |
| 1176 | break; |
| 1177 | } else |
| 1178 | continue; |
| 1179 | } |
| 1180 | sglq->ndlp = ndlp; |
| 1181 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1182 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1183 | sglq->state = SGL_ALLOCATED; |
| 1184 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1185 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1186 | return sglq; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1190 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1191 | * @phba: Pointer to HBA context object. |
| 1192 | * @piocb: Pointer to the iocbq. |
| 1193 | * |
| 1194 | * This function is called with the sgl_list lock held. This function |
| 1195 | * gets a new driver sglq object from the sglq list. If the |
| 1196 | * list is not empty then it is successful, it returns pointer to the newly |
| 1197 | * allocated sglq object else it returns NULL. |
| 1198 | **/ |
| 1199 | struct lpfc_sglq * |
| 1200 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1201 | { |
| 1202 | struct list_head *lpfc_nvmet_sgl_list; |
| 1203 | struct lpfc_sglq *sglq = NULL; |
| 1204 | |
| 1205 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1206 | |
| 1207 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1208 | |
| 1209 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1210 | if (!sglq) |
| 1211 | return NULL; |
| 1212 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1213 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | return sglq; |
| 1215 | } |
| 1216 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1217 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1218 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1219 | * @phba: Pointer to HBA context object. |
| 1220 | * |
| 1221 | * This function is called with no lock held. This function |
| 1222 | * allocates a new driver iocb object from the iocb pool. If the |
| 1223 | * allocation is successful, it returns pointer to the newly |
| 1224 | * allocated iocb object else it returns NULL. |
| 1225 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1226 | struct lpfc_iocbq * |
| 1227 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1228 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1229 | struct lpfc_iocbq * iocbq = NULL; |
| 1230 | unsigned long iflags; |
| 1231 | |
| 1232 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1233 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1234 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1235 | return iocbq; |
| 1236 | } |
| 1237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1238 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1239 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1240 | * @phba: Pointer to HBA context object. |
| 1241 | * @iocbq: Pointer to driver iocb object. |
| 1242 | * |
| 1243 | * This function is called with hbalock held to release driver |
| 1244 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1245 | * does not change for each use of the iocb object. This function |
| 1246 | * clears all other fields of the iocb object when it is freed. |
| 1247 | * The sqlq structure that holds the xritag and phys and virtual |
| 1248 | * mappings for the scatter gather list is retrieved from the |
| 1249 | * active array of sglq. The get of the sglq pointer also clears |
| 1250 | * the entry in the array. If the status of the IO indiactes that |
| 1251 | * this IO was aborted then the sglq entry it put on the |
| 1252 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1253 | * 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] | 1254 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1255 | **/ |
| 1256 | static void |
| 1257 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1258 | { |
| 1259 | struct lpfc_sglq *sglq; |
| 1260 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1261 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1262 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1263 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1264 | lockdep_assert_held(&phba->hbalock); |
| 1265 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1266 | if (iocbq->sli4_xritag == NO_XRI) |
| 1267 | sglq = NULL; |
| 1268 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1269 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1270 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1271 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1272 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1273 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1274 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1275 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1276 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1277 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1278 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1279 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1280 | spin_unlock_irqrestore( |
| 1281 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1282 | goto out; |
| 1283 | } |
| 1284 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1285 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1286 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1287 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1288 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1289 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1290 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1291 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1292 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1293 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1294 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1295 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1296 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1297 | sglq->state = SGL_FREED; |
| 1298 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1299 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1300 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1301 | spin_unlock_irqrestore( |
| 1302 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1303 | |
| 1304 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1305 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1306 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1307 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1308 | } |
| 1309 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1310 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1311 | /* |
| 1312 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1313 | */ |
| 1314 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1315 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1316 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1317 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1318 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1319 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1320 | } |
| 1321 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1322 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1323 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1324 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1325 | * @phba: Pointer to HBA context object. |
| 1326 | * @iocbq: Pointer to driver iocb object. |
| 1327 | * |
| 1328 | * This function is called with hbalock held to release driver |
| 1329 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1330 | * does not change for each use of the iocb object. This function |
| 1331 | * clears all other fields of the iocb object when it is freed. |
| 1332 | **/ |
| 1333 | static void |
| 1334 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1335 | { |
| 1336 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1337 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1338 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1339 | |
| 1340 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1341 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1342 | */ |
| 1343 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1344 | iocbq->sli4_xritag = NO_XRI; |
| 1345 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1346 | } |
| 1347 | |
| 1348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1349 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1350 | * @phba: Pointer to HBA context object. |
| 1351 | * @iocbq: Pointer to driver iocb object. |
| 1352 | * |
| 1353 | * This function is called with hbalock held to release driver |
| 1354 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1355 | * does not change for each use of the iocb object. This function |
| 1356 | * clears all other fields of the iocb object when it is freed. |
| 1357 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1358 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1359 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1360 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1361 | lockdep_assert_held(&phba->hbalock); |
| 1362 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1363 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1364 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1365 | } |
| 1366 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1367 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1368 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1369 | * @phba: Pointer to HBA context object. |
| 1370 | * @iocbq: Pointer to driver iocb object. |
| 1371 | * |
| 1372 | * This function is called with no lock held to release the iocb to |
| 1373 | * iocb pool. |
| 1374 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1375 | void |
| 1376 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1377 | { |
| 1378 | unsigned long iflags; |
| 1379 | |
| 1380 | /* |
| 1381 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1382 | */ |
| 1383 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1384 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1385 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1386 | } |
| 1387 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1388 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1389 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1390 | * @phba: Pointer to HBA context object. |
| 1391 | * @iocblist: List of IOCBs. |
| 1392 | * @ulpstatus: ULP status in IOCB command field. |
| 1393 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1394 | * |
| 1395 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1396 | * on the list by invoking the complete callback function associated with the |
| 1397 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1398 | * fields. |
| 1399 | **/ |
| 1400 | void |
| 1401 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1402 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1403 | { |
| 1404 | struct lpfc_iocbq *piocb; |
| 1405 | |
| 1406 | while (!list_empty(iocblist)) { |
| 1407 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1408 | if (!piocb->iocb_cmpl) |
| 1409 | lpfc_sli_release_iocbq(phba, piocb); |
| 1410 | else { |
| 1411 | piocb->iocb.ulpStatus = ulpstatus; |
| 1412 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1413 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1414 | } |
| 1415 | } |
| 1416 | return; |
| 1417 | } |
| 1418 | |
| 1419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1420 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1421 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1422 | * |
| 1423 | * This function is called by ring event handler function to get the iocb type. |
| 1424 | * This function translates the iocb command to an iocb command type used to |
| 1425 | * decide the final disposition of each completed IOCB. |
| 1426 | * The function returns |
| 1427 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1428 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1429 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1430 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1431 | * |
| 1432 | * The caller is not required to hold any lock. |
| 1433 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1434 | static lpfc_iocb_type |
| 1435 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1436 | { |
| 1437 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1438 | |
| 1439 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1440 | return 0; |
| 1441 | |
| 1442 | switch (iocb_cmnd) { |
| 1443 | case CMD_XMIT_SEQUENCE_CR: |
| 1444 | case CMD_XMIT_SEQUENCE_CX: |
| 1445 | case CMD_XMIT_BCAST_CN: |
| 1446 | case CMD_XMIT_BCAST_CX: |
| 1447 | case CMD_ELS_REQUEST_CR: |
| 1448 | case CMD_ELS_REQUEST_CX: |
| 1449 | case CMD_CREATE_XRI_CR: |
| 1450 | case CMD_CREATE_XRI_CX: |
| 1451 | case CMD_GET_RPI_CN: |
| 1452 | case CMD_XMIT_ELS_RSP_CX: |
| 1453 | case CMD_GET_RPI_CR: |
| 1454 | case CMD_FCP_IWRITE_CR: |
| 1455 | case CMD_FCP_IWRITE_CX: |
| 1456 | case CMD_FCP_IREAD_CR: |
| 1457 | case CMD_FCP_IREAD_CX: |
| 1458 | case CMD_FCP_ICMND_CR: |
| 1459 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1460 | case CMD_FCP_TSEND_CX: |
| 1461 | case CMD_FCP_TRSP_CX: |
| 1462 | case CMD_FCP_TRECEIVE_CX: |
| 1463 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | case CMD_ADAPTER_MSG: |
| 1465 | case CMD_ADAPTER_DUMP: |
| 1466 | case CMD_XMIT_SEQUENCE64_CR: |
| 1467 | case CMD_XMIT_SEQUENCE64_CX: |
| 1468 | case CMD_XMIT_BCAST64_CN: |
| 1469 | case CMD_XMIT_BCAST64_CX: |
| 1470 | case CMD_ELS_REQUEST64_CR: |
| 1471 | case CMD_ELS_REQUEST64_CX: |
| 1472 | case CMD_FCP_IWRITE64_CR: |
| 1473 | case CMD_FCP_IWRITE64_CX: |
| 1474 | case CMD_FCP_IREAD64_CR: |
| 1475 | case CMD_FCP_IREAD64_CX: |
| 1476 | case CMD_FCP_ICMND64_CR: |
| 1477 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1478 | case CMD_FCP_TSEND64_CX: |
| 1479 | case CMD_FCP_TRSP64_CX: |
| 1480 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | case CMD_GEN_REQUEST64_CR: |
| 1482 | case CMD_GEN_REQUEST64_CX: |
| 1483 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1484 | case DSSCMD_IWRITE64_CR: |
| 1485 | case DSSCMD_IWRITE64_CX: |
| 1486 | case DSSCMD_IREAD64_CR: |
| 1487 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | type = LPFC_SOL_IOCB; |
| 1489 | break; |
| 1490 | case CMD_ABORT_XRI_CN: |
| 1491 | case CMD_ABORT_XRI_CX: |
| 1492 | case CMD_CLOSE_XRI_CN: |
| 1493 | case CMD_CLOSE_XRI_CX: |
| 1494 | case CMD_XRI_ABORTED_CX: |
| 1495 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1496 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | type = LPFC_ABORT_IOCB; |
| 1498 | break; |
| 1499 | case CMD_RCV_SEQUENCE_CX: |
| 1500 | case CMD_RCV_ELS_REQ_CX: |
| 1501 | case CMD_RCV_SEQUENCE64_CX: |
| 1502 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1503 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1504 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1505 | case CMD_IOCB_RCV_ELS64_CX: |
| 1506 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1507 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | type = LPFC_UNSOL_IOCB; |
| 1509 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1510 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1511 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1512 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1513 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1514 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1515 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1516 | case CMD_IOCB_RET_HBQE64_CN: |
| 1517 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1518 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1519 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1520 | case CMD_IOCB_LOGENTRY_CN: |
| 1521 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1522 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1523 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1524 | type = LPFC_UNKNOWN_IOCB; |
| 1525 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1526 | default: |
| 1527 | type = LPFC_UNKNOWN_IOCB; |
| 1528 | break; |
| 1529 | } |
| 1530 | |
| 1531 | return type; |
| 1532 | } |
| 1533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1534 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1535 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1536 | * @phba: Pointer to HBA context object. |
| 1537 | * |
| 1538 | * This function is called from SLI initialization code |
| 1539 | * to configure every ring of the HBA's SLI interface. The |
| 1540 | * caller is not required to hold any lock. This function issues |
| 1541 | * a config_ring mailbox command for each ring. |
| 1542 | * This function returns zero if successful else returns a negative |
| 1543 | * error code. |
| 1544 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1546 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | { |
| 1548 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1549 | LPFC_MBOXQ_t *pmb; |
| 1550 | MAILBOX_t *pmbox; |
| 1551 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1553 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1554 | if (!pmb) |
| 1555 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1556 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1557 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | lpfc_config_ring(phba, i, pmb); |
| 1560 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1561 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1563 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1564 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1565 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1566 | rc, pmbox->mbxCommand, |
| 1567 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1568 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1569 | ret = -ENXIO; |
| 1570 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1571 | } |
| 1572 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1573 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1574 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | } |
| 1576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1578 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1579 | * @phba: Pointer to HBA context object. |
| 1580 | * @pring: Pointer to driver SLI ring object. |
| 1581 | * @piocb: Pointer to the driver iocb object. |
| 1582 | * |
| 1583 | * This function is called with hbalock held. The function adds the |
| 1584 | * new iocb to txcmplq of the given ring. This function always returns |
| 1585 | * 0. If this function is called for ELS ring, this function checks if |
| 1586 | * there is a vport associated with the ELS command. This function also |
| 1587 | * starts els_tmofunc timer if this is an ELS command. |
| 1588 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1589 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1590 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1591 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1592 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1593 | lockdep_assert_held(&phba->hbalock); |
| 1594 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1595 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1596 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1597 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1598 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1599 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1600 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1601 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1602 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1603 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1604 | BUG_ON(!piocb->vport); |
| 1605 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1606 | mod_timer(&piocb->vport->els_tmofunc, |
| 1607 | jiffies + |
| 1608 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1609 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1610 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1611 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1612 | } |
| 1613 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1614 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1615 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1616 | * @phba: Pointer to HBA context object. |
| 1617 | * @pring: Pointer to driver SLI ring object. |
| 1618 | * |
| 1619 | * This function is called with hbalock held to get next |
| 1620 | * iocb in txq of the given ring. If there is any iocb in |
| 1621 | * the txq, the function returns first iocb in the list after |
| 1622 | * removing the iocb from the list, else it returns NULL. |
| 1623 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1624 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1625 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1627 | struct lpfc_iocbq *cmd_iocb; |
| 1628 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1629 | lockdep_assert_held(&phba->hbalock); |
| 1630 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1631 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1632 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1633 | } |
| 1634 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1635 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1636 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1637 | * @phba: Pointer to HBA context object. |
| 1638 | * @pring: Pointer to driver SLI ring object. |
| 1639 | * |
| 1640 | * This function is called with hbalock held and the caller must post the |
| 1641 | * iocb without releasing the lock. If the caller releases the lock, |
| 1642 | * iocb slot returned by the function is not guaranteed to be available. |
| 1643 | * The function returns pointer to the next available iocb slot if there |
| 1644 | * is available slot in the ring, else it returns NULL. |
| 1645 | * If the get index of the ring is ahead of the put index, the function |
| 1646 | * will post an error attention event to the worker thread to take the |
| 1647 | * HBA to offline state. |
| 1648 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1649 | static IOCB_t * |
| 1650 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1651 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1652 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1653 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1654 | |
| 1655 | lockdep_assert_held(&phba->hbalock); |
| 1656 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1657 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1658 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1659 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1661 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1662 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1664 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1665 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1666 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1667 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1668 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1669 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1670 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1671 | pring->sli.sli3.local_getidx, |
| 1672 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1673 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1674 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1675 | /* |
| 1676 | * All error attention handlers are posted to |
| 1677 | * worker thread |
| 1678 | */ |
| 1679 | phba->work_ha |= HA_ERATT; |
| 1680 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1681 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1682 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1683 | |
| 1684 | return NULL; |
| 1685 | } |
| 1686 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1687 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | return NULL; |
| 1689 | } |
| 1690 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1691 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | } |
| 1693 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1694 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1695 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1696 | * @phba: Pointer to HBA context object. |
| 1697 | * @iocbq: Pointer to driver iocb object. |
| 1698 | * |
| 1699 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1700 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1701 | * array and assigns a new iotag. |
| 1702 | * The function returns the allocated iotag if successful, else returns zero. |
| 1703 | * Zero is not a valid iotag. |
| 1704 | * The caller is not required to hold any lock. |
| 1705 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1706 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1707 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1708 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1709 | struct lpfc_iocbq **new_arr; |
| 1710 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1711 | size_t new_len; |
| 1712 | struct lpfc_sli *psli = &phba->sli; |
| 1713 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1714 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1715 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1716 | iotag = psli->last_iotag; |
| 1717 | if(++iotag < psli->iocbq_lookup_len) { |
| 1718 | psli->last_iotag = iotag; |
| 1719 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1720 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1721 | iocbq->iotag = iotag; |
| 1722 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1723 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1724 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1725 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1726 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1727 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1728 | GFP_KERNEL); |
| 1729 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1730 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1731 | old_arr = psli->iocbq_lookup; |
| 1732 | if (new_len <= psli->iocbq_lookup_len) { |
| 1733 | /* highly unprobable case */ |
| 1734 | kfree(new_arr); |
| 1735 | iotag = psli->last_iotag; |
| 1736 | if(++iotag < psli->iocbq_lookup_len) { |
| 1737 | psli->last_iotag = iotag; |
| 1738 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1739 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1740 | iocbq->iotag = iotag; |
| 1741 | return iotag; |
| 1742 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1743 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1744 | return 0; |
| 1745 | } |
| 1746 | if (psli->iocbq_lookup) |
| 1747 | memcpy(new_arr, old_arr, |
| 1748 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1749 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1750 | psli->iocbq_lookup = new_arr; |
| 1751 | psli->iocbq_lookup_len = new_len; |
| 1752 | psli->last_iotag = iotag; |
| 1753 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1754 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1755 | iocbq->iotag = iotag; |
| 1756 | kfree(old_arr); |
| 1757 | return iotag; |
| 1758 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1759 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1760 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1762 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1763 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1764 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1765 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1766 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1767 | } |
| 1768 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1769 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1770 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1771 | * @phba: Pointer to HBA context object. |
| 1772 | * @pring: Pointer to driver SLI ring object. |
| 1773 | * @iocb: Pointer to iocb slot in the ring. |
| 1774 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1775 | * posted to firmware. |
| 1776 | * |
| 1777 | * This function is called with hbalock held to post a new iocb to |
| 1778 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1779 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1780 | * a completion call back for this iocb else the function will free the |
| 1781 | * iocb object. |
| 1782 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1783 | static void |
| 1784 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1785 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1786 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1787 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1788 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1789 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1790 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1791 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1792 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1793 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1794 | if (pring->ringno == LPFC_ELS_RING) { |
| 1795 | lpfc_debugfs_slow_ring_trc(phba, |
| 1796 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1797 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1798 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1799 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1800 | } |
| 1801 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | /* |
| 1803 | * Issue iocb command to adapter |
| 1804 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1805 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1806 | wmb(); |
| 1807 | pring->stats.iocb_cmd++; |
| 1808 | |
| 1809 | /* |
| 1810 | * If there is no completion routine to call, we can release the |
| 1811 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1812 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1813 | */ |
| 1814 | if (nextiocb->iocb_cmpl) |
| 1815 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1816 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1817 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | |
| 1819 | /* |
| 1820 | * Let the HBA know what IOCB slot will be the next one the |
| 1821 | * driver will put a command into. |
| 1822 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1823 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1824 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1825 | } |
| 1826 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1828 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1829 | * @phba: Pointer to HBA context object. |
| 1830 | * @pring: Pointer to driver SLI ring object. |
| 1831 | * |
| 1832 | * The caller is not required to hold any lock for calling this function. |
| 1833 | * This function updates the chip attention bits for the ring to inform firmware |
| 1834 | * that there are pending work to be done for this ring and requests an |
| 1835 | * interrupt when there is space available in the ring. This function is |
| 1836 | * called when the driver is unable to post more iocbs to the ring due |
| 1837 | * to unavailability of space in the ring. |
| 1838 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1839 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | { |
| 1842 | int ringno = pring->ringno; |
| 1843 | |
| 1844 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1845 | |
| 1846 | wmb(); |
| 1847 | |
| 1848 | /* |
| 1849 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1850 | * The HBA will tell us when an IOCB entry is available. |
| 1851 | */ |
| 1852 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1853 | readl(phba->CAregaddr); /* flush */ |
| 1854 | |
| 1855 | pring->stats.iocb_cmd_full++; |
| 1856 | } |
| 1857 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1858 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1859 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1860 | * @phba: Pointer to HBA context object. |
| 1861 | * @pring: Pointer to driver SLI ring object. |
| 1862 | * |
| 1863 | * This function updates the chip attention register bit for the |
| 1864 | * given ring to inform HBA that there is more work to be done |
| 1865 | * in this ring. The caller is not required to hold any lock. |
| 1866 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1867 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1868 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1869 | { |
| 1870 | int ringno = pring->ringno; |
| 1871 | |
| 1872 | /* |
| 1873 | * Tell the HBA that there is work to do in this ring. |
| 1874 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1875 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1876 | wmb(); |
| 1877 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1878 | readl(phba->CAregaddr); /* flush */ |
| 1879 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | } |
| 1881 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1882 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1883 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1884 | * @phba: Pointer to HBA context object. |
| 1885 | * @pring: Pointer to driver SLI ring object. |
| 1886 | * |
| 1887 | * This function is called with hbalock held to post pending iocbs |
| 1888 | * in the txq to the firmware. This function is called when driver |
| 1889 | * detects space available in the ring. |
| 1890 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1892 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | { |
| 1894 | IOCB_t *iocb; |
| 1895 | struct lpfc_iocbq *nextiocb; |
| 1896 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1897 | lockdep_assert_held(&phba->hbalock); |
| 1898 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1899 | /* |
| 1900 | * Check to see if: |
| 1901 | * (a) there is anything on the txq to send |
| 1902 | * (b) link is up |
| 1903 | * (c) link attention events can be processed (fcp ring only) |
| 1904 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1905 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1906 | |
| 1907 | if (lpfc_is_link_up(phba) && |
| 1908 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1909 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1910 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | |
| 1912 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1913 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1914 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1915 | |
| 1916 | if (iocb) |
| 1917 | lpfc_sli_update_ring(phba, pring); |
| 1918 | else |
| 1919 | lpfc_sli_update_full_ring(phba, pring); |
| 1920 | } |
| 1921 | |
| 1922 | return; |
| 1923 | } |
| 1924 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1925 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1926 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1927 | * @phba: Pointer to HBA context object. |
| 1928 | * @hbqno: HBQ number. |
| 1929 | * |
| 1930 | * This function is called with hbalock held to get the next |
| 1931 | * available slot for the given HBQ. If there is free slot |
| 1932 | * available for the HBQ it will return pointer to the next available |
| 1933 | * HBQ entry else it will return NULL. |
| 1934 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1935 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1936 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1937 | { |
| 1938 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1939 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1940 | lockdep_assert_held(&phba->hbalock); |
| 1941 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1942 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1943 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1944 | hbqp->next_hbqPutIdx = 0; |
| 1945 | |
| 1946 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1947 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1948 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1949 | |
| 1950 | hbqp->local_hbqGetIdx = getidx; |
| 1951 | |
| 1952 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1953 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1954 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1955 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1956 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1957 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1958 | hbqp->entry_count); |
| 1959 | |
| 1960 | phba->link_state = LPFC_HBA_ERROR; |
| 1961 | return NULL; |
| 1962 | } |
| 1963 | |
| 1964 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1965 | return NULL; |
| 1966 | } |
| 1967 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1968 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1969 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1970 | } |
| 1971 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1972 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1973 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1974 | * @phba: Pointer to HBA context object. |
| 1975 | * |
| 1976 | * This function is called with no lock held to free all the |
| 1977 | * hbq buffers while uninitializing the SLI interface. It also |
| 1978 | * frees the HBQ buffers returned by the firmware but not yet |
| 1979 | * processed by the upper layers. |
| 1980 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1981 | void |
| 1982 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1983 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1984 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1985 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1986 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1987 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1988 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1989 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1990 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1991 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1992 | for (i = 0; i < hbq_count; ++i) { |
| 1993 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1994 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1995 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1996 | list_del(&hbq_buf->dbuf.list); |
| 1997 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1998 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1999 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2000 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2001 | |
| 2002 | /* Mark the HBQs not in use */ |
| 2003 | phba->hbq_in_use = 0; |
| 2004 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2005 | } |
| 2006 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2007 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2008 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2009 | * @phba: Pointer to HBA context object. |
| 2010 | * @hbqno: HBQ number. |
| 2011 | * @hbq_buf: Pointer to HBQ buffer. |
| 2012 | * |
| 2013 | * This function is called with the hbalock held to post a |
| 2014 | * hbq buffer to the firmware. If the function finds an empty |
| 2015 | * slot in the HBQ, it will post the buffer. The function will return |
| 2016 | * pointer to the hbq entry if it successfully post the buffer |
| 2017 | * else it will return NULL. |
| 2018 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2019 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2020 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2021 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2022 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2023 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2024 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2029 | * @phba: Pointer to HBA context object. |
| 2030 | * @hbqno: HBQ number. |
| 2031 | * @hbq_buf: Pointer to HBQ buffer. |
| 2032 | * |
| 2033 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2034 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2035 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2036 | * it successfully post the buffer else it will return an error. |
| 2037 | **/ |
| 2038 | static int |
| 2039 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2040 | struct hbq_dmabuf *hbq_buf) |
| 2041 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2042 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2043 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2044 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2045 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2046 | /* Get next HBQ entry slot to use */ |
| 2047 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2048 | if (hbqe) { |
| 2049 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2050 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2051 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2052 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2053 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2054 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2055 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2056 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2057 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2058 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2059 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2060 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2061 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2062 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2063 | return 0; |
| 2064 | } else |
| 2065 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2066 | } |
| 2067 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2068 | /** |
| 2069 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2070 | * @phba: Pointer to HBA context object. |
| 2071 | * @hbqno: HBQ number. |
| 2072 | * @hbq_buf: Pointer to HBQ buffer. |
| 2073 | * |
| 2074 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2075 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2076 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2077 | **/ |
| 2078 | static int |
| 2079 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2080 | struct hbq_dmabuf *hbq_buf) |
| 2081 | { |
| 2082 | int rc; |
| 2083 | struct lpfc_rqe hrqe; |
| 2084 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2085 | struct lpfc_queue *hrq; |
| 2086 | struct lpfc_queue *drq; |
| 2087 | |
| 2088 | if (hbqno != LPFC_ELS_HBQ) |
| 2089 | return 1; |
| 2090 | hrq = phba->sli4_hba.hdr_rq; |
| 2091 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2092 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2093 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2094 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2095 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2096 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2097 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2098 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2099 | if (rc < 0) |
| 2100 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2101 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2102 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2103 | return 0; |
| 2104 | } |
| 2105 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2106 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2107 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2108 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2109 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2110 | .mask_count = 0, |
| 2111 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2112 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2113 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2114 | .init_count = 40, |
| 2115 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2116 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2117 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2118 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2119 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2120 | &lpfc_els_hbq, |
| 2121 | }; |
| 2122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2124 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2125 | * @phba: Pointer to HBA context object. |
| 2126 | * @hbqno: HBQ number. |
| 2127 | * @count: Number of HBQ buffers to be posted. |
| 2128 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2129 | * This function is called with no lock held to post more hbq buffers to the |
| 2130 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2131 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2132 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2133 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2134 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2135 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2136 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2137 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2138 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2139 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2140 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2141 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2142 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2143 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2144 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2145 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2146 | phba->hbqs[hbqno].buffer_count; |
| 2147 | if (!count) |
| 2148 | return 0; |
| 2149 | /* Allocate HBQ entries */ |
| 2150 | for (i = 0; i < count; i++) { |
| 2151 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2152 | if (!hbq_buffer) |
| 2153 | break; |
| 2154 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2155 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2156 | /* Check whether HBQ is still in use */ |
| 2157 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2158 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2159 | goto err; |
| 2160 | while (!list_empty(&hbq_buf_list)) { |
| 2161 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2162 | dbuf.list); |
| 2163 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2164 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2165 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2166 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2167 | posted++; |
| 2168 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2169 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2170 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2171 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2172 | return posted; |
| 2173 | err: |
| 2174 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2175 | while (!list_empty(&hbq_buf_list)) { |
| 2176 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2177 | dbuf.list); |
| 2178 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2179 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2180 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2181 | } |
| 2182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2183 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2184 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2185 | * @phba: Pointer to HBA context object. |
| 2186 | * @qno: HBQ number. |
| 2187 | * |
| 2188 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2189 | * is called with no lock held. The function returns the number of HBQ entries |
| 2190 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2191 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2192 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2193 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2194 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2195 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2196 | return 0; |
| 2197 | else |
| 2198 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2199 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2200 | } |
| 2201 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2202 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2203 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2204 | * @phba: Pointer to HBA context object. |
| 2205 | * @qno: HBQ queue number. |
| 2206 | * |
| 2207 | * This function is called from SLI initialization code path with |
| 2208 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2209 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2210 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2211 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2213 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2214 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2215 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2216 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2217 | else |
| 2218 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2219 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2220 | } |
| 2221 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2222 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2223 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2224 | * @phba: Pointer to HBA context object. |
| 2225 | * @hbqno: HBQ number. |
| 2226 | * |
| 2227 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2228 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2229 | **/ |
| 2230 | static struct hbq_dmabuf * |
| 2231 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2232 | { |
| 2233 | struct lpfc_dmabuf *d_buf; |
| 2234 | |
| 2235 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2236 | if (!d_buf) |
| 2237 | return NULL; |
| 2238 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2239 | } |
| 2240 | |
| 2241 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2242 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2243 | * @phba: Pointer to HBA context object. |
| 2244 | * @hbqno: HBQ number. |
| 2245 | * |
| 2246 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2247 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2248 | **/ |
| 2249 | static struct rqb_dmabuf * |
| 2250 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2251 | { |
| 2252 | struct lpfc_dmabuf *h_buf; |
| 2253 | struct lpfc_rqb *rqbp; |
| 2254 | |
| 2255 | rqbp = hrq->rqbp; |
| 2256 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2257 | struct lpfc_dmabuf, list); |
| 2258 | if (!h_buf) |
| 2259 | return NULL; |
| 2260 | rqbp->buffer_count--; |
| 2261 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2262 | } |
| 2263 | |
| 2264 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2265 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2266 | * @phba: Pointer to HBA context object. |
| 2267 | * @tag: Tag of the hbq buffer. |
| 2268 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2269 | * This function searches for the hbq buffer associated with the given tag in |
| 2270 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2271 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2272 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2273 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2274 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2275 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2276 | struct lpfc_dmabuf *d_buf; |
| 2277 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2278 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2279 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2280 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2281 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2282 | return NULL; |
| 2283 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2284 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2285 | 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] | 2286 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2287 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2288 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2289 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2290 | } |
| 2291 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2292 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2293 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2294 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2295 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2296 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2297 | } |
| 2298 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2299 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2300 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2301 | * @phba: Pointer to HBA context object. |
| 2302 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2303 | * |
| 2304 | * This function is called with hbalock. This function gives back |
| 2305 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2306 | * post the buffer, it will free the buffer. |
| 2307 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2308 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2309 | 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] | 2310 | { |
| 2311 | uint32_t hbqno; |
| 2312 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2313 | if (hbq_buffer) { |
| 2314 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2315 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2316 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2317 | } |
| 2318 | } |
| 2319 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2320 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2321 | * 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] | 2322 | * @mbxCommand: mailbox command code. |
| 2323 | * |
| 2324 | * This function is called by the mailbox event handler function to verify |
| 2325 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2326 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2327 | * and the mailbox event handler will take the HBA offline. |
| 2328 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | static int |
| 2330 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2331 | { |
| 2332 | uint8_t ret; |
| 2333 | |
| 2334 | switch (mbxCommand) { |
| 2335 | case MBX_LOAD_SM: |
| 2336 | case MBX_READ_NV: |
| 2337 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2338 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2339 | case MBX_RUN_BIU_DIAG: |
| 2340 | case MBX_INIT_LINK: |
| 2341 | case MBX_DOWN_LINK: |
| 2342 | case MBX_CONFIG_LINK: |
| 2343 | case MBX_CONFIG_RING: |
| 2344 | case MBX_RESET_RING: |
| 2345 | case MBX_READ_CONFIG: |
| 2346 | case MBX_READ_RCONFIG: |
| 2347 | case MBX_READ_SPARM: |
| 2348 | case MBX_READ_STATUS: |
| 2349 | case MBX_READ_RPI: |
| 2350 | case MBX_READ_XRI: |
| 2351 | case MBX_READ_REV: |
| 2352 | case MBX_READ_LNK_STAT: |
| 2353 | case MBX_REG_LOGIN: |
| 2354 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | case MBX_CLEAR_LA: |
| 2356 | case MBX_DUMP_MEMORY: |
| 2357 | case MBX_DUMP_CONTEXT: |
| 2358 | case MBX_RUN_DIAGS: |
| 2359 | case MBX_RESTART: |
| 2360 | case MBX_UPDATE_CFG: |
| 2361 | case MBX_DOWN_LOAD: |
| 2362 | case MBX_DEL_LD_ENTRY: |
| 2363 | case MBX_RUN_PROGRAM: |
| 2364 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2365 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2367 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2369 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2370 | case MBX_LOAD_AREA: |
| 2371 | case MBX_RUN_BIU_DIAG64: |
| 2372 | case MBX_CONFIG_PORT: |
| 2373 | case MBX_READ_SPARM64: |
| 2374 | case MBX_READ_RPI64: |
| 2375 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2376 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2377 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | case MBX_SET_DEBUG: |
| 2379 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2380 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2381 | case MBX_REG_VPI: |
| 2382 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2383 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2384 | case MBX_PORT_CAPABILITIES: |
| 2385 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2386 | case MBX_SLI4_CONFIG: |
| 2387 | case MBX_SLI4_REQ_FTRS: |
| 2388 | case MBX_REG_FCFI: |
| 2389 | case MBX_UNREG_FCFI: |
| 2390 | case MBX_REG_VFI: |
| 2391 | case MBX_UNREG_VFI: |
| 2392 | case MBX_INIT_VPI: |
| 2393 | case MBX_INIT_VFI: |
| 2394 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2395 | case MBX_READ_EVENT_LOG_STATUS: |
| 2396 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2397 | case MBX_SECURITY_MGMT: |
| 2398 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2399 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | ret = mbxCommand; |
| 2401 | break; |
| 2402 | default: |
| 2403 | ret = MBX_SHUTDOWN; |
| 2404 | break; |
| 2405 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2406 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2408 | |
| 2409 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2410 | * 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] | 2411 | * @phba: Pointer to HBA context object. |
| 2412 | * @pmboxq: Pointer to mailbox command. |
| 2413 | * |
| 2414 | * This is completion handler function for mailbox commands issued from |
| 2415 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2416 | * mailbox event handler function with no lock held. This function |
| 2417 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2418 | * of the mailbox. |
| 2419 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2420 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2421 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2423 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2424 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | |
| 2426 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2427 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | * continued running. |
| 2429 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2430 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2431 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2432 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2433 | if (pmbox_done) |
| 2434 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2435 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2436 | return; |
| 2437 | } |
| 2438 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2439 | |
| 2440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2441 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2442 | * @phba: Pointer to HBA context object. |
| 2443 | * @pmb: Pointer to mailbox object. |
| 2444 | * |
| 2445 | * This function is the default mailbox completion handler. It |
| 2446 | * frees the memory resources associated with the completed mailbox |
| 2447 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2448 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2449 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2450 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2451 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2452 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2453 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2455 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2456 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2457 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2458 | int rc; |
| 2459 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2460 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2461 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | if (mp) { |
| 2463 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2464 | kfree(mp); |
| 2465 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2466 | |
| 2467 | /* |
| 2468 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2469 | * is in re-discovery driver need to cleanup the RPI. |
| 2470 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2471 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2472 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2473 | !pmb->u.mb.mbxStatus) { |
| 2474 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2475 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2476 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2477 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2478 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2479 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2480 | if (rc != MBX_NOT_FINISHED) |
| 2481 | return; |
| 2482 | } |
| 2483 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2484 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2485 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2486 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2487 | shost = lpfc_shost_from_vport(vport); |
| 2488 | spin_lock_irq(shost->host_lock); |
| 2489 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2490 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2491 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2492 | } |
| 2493 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2494 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2495 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2496 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2497 | pmb->ctx_buf = NULL; |
| 2498 | pmb->ctx_ndlp = NULL; |
| 2499 | } |
| 2500 | |
| 2501 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2502 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2503 | |
| 2504 | /* Check to see if there are any deferred events to process */ |
| 2505 | if (ndlp) { |
| 2506 | lpfc_printf_vlog( |
| 2507 | vport, |
| 2508 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2509 | "1438 UNREG cmpl deferred mbox x%x " |
| 2510 | "on NPort x%x Data: x%x x%x %p\n", |
| 2511 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2512 | ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp); |
| 2513 | |
| 2514 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2515 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2516 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2517 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2518 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2519 | } else { |
| 2520 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2521 | } |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2522 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2523 | pmb->ctx_ndlp = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2524 | } |
| 2525 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2526 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2527 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2528 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2529 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2530 | "2860 SLI authentication is required " |
| 2531 | "for INIT_LINK but has not done yet\n"); |
| 2532 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2533 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2534 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2535 | else |
| 2536 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2537 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2538 | /** |
| 2539 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2540 | * @phba: Pointer to HBA context object. |
| 2541 | * @pmb: Pointer to mailbox object. |
| 2542 | * |
| 2543 | * This function is the unreg rpi mailbox completion handler. It |
| 2544 | * frees the memory resources associated with the completed mailbox |
| 2545 | * command. An additional refrenece is put on the ndlp to prevent |
| 2546 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2547 | * the unreg mailbox command completes, this routine puts the |
| 2548 | * reference back. |
| 2549 | * |
| 2550 | **/ |
| 2551 | void |
| 2552 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2553 | { |
| 2554 | struct lpfc_vport *vport = pmb->vport; |
| 2555 | struct lpfc_nodelist *ndlp; |
| 2556 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2557 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2558 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2559 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2560 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2561 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2562 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2563 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2564 | lpfc_printf_vlog( |
| 2565 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 2566 | "0010 UNREG_LOGIN vpi:%x " |
| 2567 | "rpi:%x DID:%x defer x%x flg x%x " |
| 2568 | "map:%x %p\n", |
| 2569 | vport->vpi, ndlp->nlp_rpi, |
| 2570 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2571 | ndlp->nlp_flag, |
| 2572 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2573 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2574 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2575 | |
| 2576 | /* Check to see if there are any deferred |
| 2577 | * events to process |
| 2578 | */ |
| 2579 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2580 | (ndlp->nlp_defer_did != |
| 2581 | NLP_EVT_NOTHING_PENDING)) { |
| 2582 | lpfc_printf_vlog( |
| 2583 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2584 | "4111 UNREG cmpl deferred " |
| 2585 | "clr x%x on " |
| 2586 | "NPort x%x Data: x%x %p\n", |
| 2587 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2588 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2589 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2590 | ndlp->nlp_defer_did = |
| 2591 | NLP_EVT_NOTHING_PENDING; |
| 2592 | lpfc_issue_els_plogi( |
| 2593 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2594 | } else { |
| 2595 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2596 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2597 | } |
| 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2602 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2604 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2605 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2606 | * @phba: Pointer to HBA context object. |
| 2607 | * |
| 2608 | * This function is called with no lock held. This function processes all |
| 2609 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2610 | * service routine processes mailbox completion interrupt and adds completed |
| 2611 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2612 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2613 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2614 | * function returns the mailbox commands to the upper layer by calling the |
| 2615 | * completion handler function of each mailbox. |
| 2616 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2617 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2618 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2620 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2622 | int rc; |
| 2623 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | |
| 2625 | phba->sli.slistat.mbox_event++; |
| 2626 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2627 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2628 | spin_lock_irq(&phba->hbalock); |
| 2629 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2630 | spin_unlock_irq(&phba->hbalock); |
| 2631 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2633 | do { |
| 2634 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2635 | if (pmb == NULL) |
| 2636 | break; |
| 2637 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2638 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2640 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2641 | if (pmb->vport) { |
| 2642 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2643 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2644 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2645 | (uint32_t)pmbox->mbxCommand, |
| 2646 | pmbox->un.varWords[0], |
| 2647 | pmbox->un.varWords[1]); |
| 2648 | } |
| 2649 | else { |
| 2650 | lpfc_debugfs_disc_trc(phba->pport, |
| 2651 | LPFC_DISC_TRC_MBOX, |
| 2652 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2653 | (uint32_t)pmbox->mbxCommand, |
| 2654 | pmbox->un.varWords[0], |
| 2655 | pmbox->un.varWords[1]); |
| 2656 | } |
| 2657 | } |
| 2658 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2659 | /* |
| 2660 | * It is a fatal error if unknown mbox command completion. |
| 2661 | */ |
| 2662 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2663 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2664 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2665 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2666 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2667 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2668 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2669 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2670 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2671 | pmb), |
| 2672 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2673 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2674 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | phba->work_hs = HS_FFER3; |
| 2676 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2677 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | } |
| 2679 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | if (pmbox->mbxStatus) { |
| 2681 | phba->sli.slistat.mbox_stat_err++; |
| 2682 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2683 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2684 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2685 | LOG_MBOX | LOG_SLI, |
| 2686 | "(%d):0305 Mbox cmd cmpl " |
| 2687 | "error - RETRYing Data: x%x " |
| 2688 | "(x%x/x%x) x%x x%x x%x\n", |
| 2689 | pmb->vport ? pmb->vport->vpi : 0, |
| 2690 | pmbox->mbxCommand, |
| 2691 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2692 | pmb), |
| 2693 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2694 | pmb), |
| 2695 | pmbox->mbxStatus, |
| 2696 | pmbox->un.varWords[0], |
| 2697 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | pmbox->mbxStatus = 0; |
| 2699 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2701 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2702 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2707 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2708 | "(%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] | 2709 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2710 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2711 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2712 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2713 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2714 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2715 | pmb->mbox_cmpl, |
| 2716 | *((uint32_t *) pmbox), |
| 2717 | pmbox->un.varWords[0], |
| 2718 | pmbox->un.varWords[1], |
| 2719 | pmbox->un.varWords[2], |
| 2720 | pmbox->un.varWords[3], |
| 2721 | pmbox->un.varWords[4], |
| 2722 | pmbox->un.varWords[5], |
| 2723 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2724 | pmbox->un.varWords[7], |
| 2725 | pmbox->un.varWords[8], |
| 2726 | pmbox->un.varWords[9], |
| 2727 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2729 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2731 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2732 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2734 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2735 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2736 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2737 | * @phba: Pointer to HBA context object. |
| 2738 | * @pring: Pointer to driver SLI ring object. |
| 2739 | * @tag: buffer tag. |
| 2740 | * |
| 2741 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2742 | * is set in the tag the buffer is posted for a particular exchange, |
| 2743 | * the function will return the buffer without replacing the buffer. |
| 2744 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2745 | * returns the buffer and also posts another buffer to the firmware. |
| 2746 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2747 | static struct lpfc_dmabuf * |
| 2748 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2749 | struct lpfc_sli_ring *pring, |
| 2750 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2751 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2752 | struct hbq_dmabuf *hbq_entry; |
| 2753 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2754 | if (tag & QUE_BUFTAG_BIT) |
| 2755 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2756 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2757 | if (!hbq_entry) |
| 2758 | return NULL; |
| 2759 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2760 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2761 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2762 | /** |
| 2763 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2764 | * @phba: Pointer to HBA context object. |
| 2765 | * @pring: Pointer to driver SLI ring object. |
| 2766 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2767 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2768 | * @fch_type: the type for the first frame of the sequence. |
| 2769 | * |
| 2770 | * This function is called with no lock held. This function uses the r_ctl and |
| 2771 | * type of the received sequence to find the correct callback function to call |
| 2772 | * to process the sequence. |
| 2773 | **/ |
| 2774 | static int |
| 2775 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2776 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2777 | uint32_t fch_type) |
| 2778 | { |
| 2779 | int i; |
| 2780 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2781 | switch (fch_type) { |
| 2782 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2783 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2784 | return 1; |
| 2785 | default: |
| 2786 | break; |
| 2787 | } |
| 2788 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2789 | /* unSolicited Responses */ |
| 2790 | if (pring->prt[0].profile) { |
| 2791 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2792 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2793 | saveq); |
| 2794 | return 1; |
| 2795 | } |
| 2796 | /* We must search, based on rctl / type |
| 2797 | for the right routine */ |
| 2798 | for (i = 0; i < pring->num_mask; i++) { |
| 2799 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2800 | (pring->prt[i].type == fch_type)) { |
| 2801 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2802 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2803 | (phba, pring, saveq); |
| 2804 | return 1; |
| 2805 | } |
| 2806 | } |
| 2807 | return 0; |
| 2808 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2809 | |
| 2810 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2811 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2812 | * @phba: Pointer to HBA context object. |
| 2813 | * @pring: Pointer to driver SLI ring object. |
| 2814 | * @saveq: Pointer to the unsolicited iocb. |
| 2815 | * |
| 2816 | * This function is called with no lock held by the ring event handler |
| 2817 | * when there is an unsolicited iocb posted to the response ring by the |
| 2818 | * firmware. This function gets the buffer associated with the iocbs |
| 2819 | * and calls the event handler for the ring. This function handles both |
| 2820 | * qring buffers and hbq buffers. |
| 2821 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2822 | * upper layer functions will free the iocb objects. |
| 2823 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | static int |
| 2825 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2826 | struct lpfc_iocbq *saveq) |
| 2827 | { |
| 2828 | IOCB_t * irsp; |
| 2829 | WORD5 * w5p; |
| 2830 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2831 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2832 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2834 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2835 | |
| 2836 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2837 | if (pring->lpfc_sli_rcv_async_status) |
| 2838 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2839 | else |
| 2840 | lpfc_printf_log(phba, |
| 2841 | KERN_WARNING, |
| 2842 | LOG_SLI, |
| 2843 | "0316 Ring %d handler: unexpected " |
| 2844 | "ASYNC_STATUS iocb received evt_code " |
| 2845 | "0x%x\n", |
| 2846 | pring->ringno, |
| 2847 | irsp->un.asyncstat.evt_code); |
| 2848 | return 1; |
| 2849 | } |
| 2850 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2851 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2852 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2853 | if (irsp->ulpBdeCount > 0) { |
| 2854 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2855 | irsp->un.ulpWord[3]); |
| 2856 | lpfc_in_buf_free(phba, dmzbuf); |
| 2857 | } |
| 2858 | |
| 2859 | if (irsp->ulpBdeCount > 1) { |
| 2860 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2861 | irsp->unsli3.sli3Words[3]); |
| 2862 | lpfc_in_buf_free(phba, dmzbuf); |
| 2863 | } |
| 2864 | |
| 2865 | if (irsp->ulpBdeCount > 2) { |
| 2866 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2867 | irsp->unsli3.sli3Words[7]); |
| 2868 | lpfc_in_buf_free(phba, dmzbuf); |
| 2869 | } |
| 2870 | |
| 2871 | return 1; |
| 2872 | } |
| 2873 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2874 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2875 | if (irsp->ulpBdeCount != 0) { |
| 2876 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2877 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2878 | if (!saveq->context2) |
| 2879 | lpfc_printf_log(phba, |
| 2880 | KERN_ERR, |
| 2881 | LOG_SLI, |
| 2882 | "0341 Ring %d Cannot find buffer for " |
| 2883 | "an unsolicited iocb. tag 0x%x\n", |
| 2884 | pring->ringno, |
| 2885 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2886 | } |
| 2887 | if (irsp->ulpBdeCount == 2) { |
| 2888 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2889 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2890 | if (!saveq->context3) |
| 2891 | lpfc_printf_log(phba, |
| 2892 | KERN_ERR, |
| 2893 | LOG_SLI, |
| 2894 | "0342 Ring %d Cannot find buffer for an" |
| 2895 | " unsolicited iocb. tag 0x%x\n", |
| 2896 | pring->ringno, |
| 2897 | irsp->unsli3.sli3Words[7]); |
| 2898 | } |
| 2899 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2900 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2901 | if (irsp->ulpBdeCount != 0) { |
| 2902 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2903 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2904 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2905 | lpfc_printf_log(phba, |
| 2906 | KERN_ERR, |
| 2907 | LOG_SLI, |
| 2908 | "0343 Ring %d Cannot find " |
| 2909 | "buffer for an unsolicited iocb" |
| 2910 | ". tag 0x%x\n", pring->ringno, |
| 2911 | irsp->un.ulpWord[3]); |
| 2912 | } |
| 2913 | if (irsp->ulpBdeCount == 2) { |
| 2914 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2915 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2916 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2917 | lpfc_printf_log(phba, |
| 2918 | KERN_ERR, |
| 2919 | LOG_SLI, |
| 2920 | "0344 Ring %d Cannot find " |
| 2921 | "buffer for an unsolicited " |
| 2922 | "iocb. tag 0x%x\n", |
| 2923 | pring->ringno, |
| 2924 | irsp->unsli3.sli3Words[7]); |
| 2925 | } |
| 2926 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2927 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2928 | if (irsp->ulpBdeCount != 0 && |
| 2929 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2930 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2931 | int found = 0; |
| 2932 | |
| 2933 | /* search continue save q for same XRI */ |
| 2934 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2935 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2936 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2937 | list_add_tail(&saveq->list, &iocbq->list); |
| 2938 | found = 1; |
| 2939 | break; |
| 2940 | } |
| 2941 | } |
| 2942 | if (!found) |
| 2943 | list_add_tail(&saveq->clist, |
| 2944 | &pring->iocb_continue_saveq); |
| 2945 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2946 | list_del_init(&iocbq->clist); |
| 2947 | saveq = iocbq; |
| 2948 | irsp = &(saveq->iocb); |
| 2949 | } else |
| 2950 | return 0; |
| 2951 | } |
| 2952 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2953 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2954 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2955 | Rctl = FC_RCTL_ELS_REQ; |
| 2956 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2957 | } else { |
| 2958 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2959 | Rctl = w5p->hcsw.Rctl; |
| 2960 | Type = w5p->hcsw.Type; |
| 2961 | |
| 2962 | /* Firmware Workaround */ |
| 2963 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2964 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2965 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2966 | Rctl = FC_RCTL_ELS_REQ; |
| 2967 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2968 | w5p->hcsw.Rctl = Rctl; |
| 2969 | w5p->hcsw.Type = Type; |
| 2970 | } |
| 2971 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2972 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2973 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2974 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2975 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2976 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2977 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2978 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2979 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | } |
| 2981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2982 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2983 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2984 | * @phba: Pointer to HBA context object. |
| 2985 | * @pring: Pointer to driver SLI ring object. |
| 2986 | * @prspiocb: Pointer to response iocb object. |
| 2987 | * |
| 2988 | * This function looks up the iocb_lookup table to get the command iocb |
| 2989 | * corresponding to the given response iocb using the iotag of the |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 2990 | * response iocb. This function is called with the hbalock held |
| 2991 | * for sli3 devices or the ring_lock for sli4 devices. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2992 | * This function returns the command iocb object if it finds the command |
| 2993 | * iocb else returns NULL. |
| 2994 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2996 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2997 | struct lpfc_sli_ring *pring, |
| 2998 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 3001 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 3002 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3003 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3004 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3005 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3006 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3007 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3008 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3009 | /* remove from txcmpl queue list */ |
| 3010 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3011 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3012 | pring->txcmplq_cnt--; |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3013 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3014 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | } |
| 3016 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3018 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3019 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3020 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3021 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | return NULL; |
| 3023 | } |
| 3024 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3025 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3026 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3027 | * @phba: Pointer to HBA context object. |
| 3028 | * @pring: Pointer to driver SLI ring object. |
| 3029 | * @iotag: IOCB tag. |
| 3030 | * |
| 3031 | * This function looks up the iocb_lookup table to get the command iocb |
| 3032 | * corresponding to the given iotag. This function is called with the |
| 3033 | * hbalock held. |
| 3034 | * This function returns the command iocb object if it finds the command |
| 3035 | * iocb else returns NULL. |
| 3036 | **/ |
| 3037 | static struct lpfc_iocbq * |
| 3038 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3039 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3040 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3041 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3042 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 3043 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3044 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3045 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3046 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3047 | /* remove from txcmpl queue list */ |
| 3048 | list_del_init(&cmd_iocb->list); |
| 3049 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3050 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3051 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3052 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3053 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3054 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3055 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3056 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3057 | "iocb_flag x%x\n", |
| 3058 | iotag, phba->sli.last_iotag, |
| 3059 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3060 | return NULL; |
| 3061 | } |
| 3062 | |
| 3063 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3064 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3065 | * @phba: Pointer to HBA context object. |
| 3066 | * @pring: Pointer to driver SLI ring object. |
| 3067 | * @saveq: Pointer to the response iocb to be processed. |
| 3068 | * |
| 3069 | * This function is called by the ring event handler for non-fcp |
| 3070 | * rings when there is a new response iocb in the response ring. |
| 3071 | * The caller is not required to hold any locks. This function |
| 3072 | * gets the command iocb associated with the response iocb and |
| 3073 | * calls the completion handler for the command iocb. If there |
| 3074 | * is no completion handler, the function will free the resources |
| 3075 | * associated with command iocb. If the response iocb is for |
| 3076 | * an already aborted command iocb, the status of the completion |
| 3077 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3078 | * This function always returns 1. |
| 3079 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3081 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | struct lpfc_iocbq *saveq) |
| 3083 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3084 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3085 | int rc = 1; |
| 3086 | unsigned long iflag; |
| 3087 | |
| 3088 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 3089 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3090 | spin_lock_irqsave(&pring->ring_lock, iflag); |
| 3091 | else |
| 3092 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3093 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 3094 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3095 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
| 3096 | else |
| 3097 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3098 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3099 | if (cmdiocbp) { |
| 3100 | if (cmdiocbp->iocb_cmpl) { |
| 3101 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3102 | * If an ELS command failed send an event to mgmt |
| 3103 | * application. |
| 3104 | */ |
| 3105 | if (saveq->iocb.ulpStatus && |
| 3106 | (pring->ringno == LPFC_ELS_RING) && |
| 3107 | (cmdiocbp->iocb.ulpCommand == |
| 3108 | CMD_ELS_REQUEST64_CR)) |
| 3109 | lpfc_send_els_failure_event(phba, |
| 3110 | cmdiocbp, saveq); |
| 3111 | |
| 3112 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3113 | * Post all ELS completions to the worker thread. |
| 3114 | * All other are passed to the completion callback. |
| 3115 | */ |
| 3116 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3117 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3118 | (cmdiocbp->iocb_flag & |
| 3119 | LPFC_DRIVER_ABORTED)) { |
| 3120 | spin_lock_irqsave(&phba->hbalock, |
| 3121 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3122 | cmdiocbp->iocb_flag &= |
| 3123 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3124 | spin_unlock_irqrestore(&phba->hbalock, |
| 3125 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3126 | saveq->iocb.ulpStatus = |
| 3127 | IOSTAT_LOCAL_REJECT; |
| 3128 | saveq->iocb.un.ulpWord[4] = |
| 3129 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3130 | |
| 3131 | /* Firmware could still be in progress |
| 3132 | * of DMAing payload, so don't free data |
| 3133 | * buffer till after a hbeat. |
| 3134 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3135 | spin_lock_irqsave(&phba->hbalock, |
| 3136 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3137 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3138 | spin_unlock_irqrestore(&phba->hbalock, |
| 3139 | iflag); |
| 3140 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3141 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3142 | if (saveq->iocb_flag & |
| 3143 | LPFC_EXCHANGE_BUSY) { |
| 3144 | /* Set cmdiocb flag for the |
| 3145 | * exchange busy so sgl (xri) |
| 3146 | * will not be released until |
| 3147 | * the abort xri is received |
| 3148 | * from hba. |
| 3149 | */ |
| 3150 | spin_lock_irqsave( |
| 3151 | &phba->hbalock, iflag); |
| 3152 | cmdiocbp->iocb_flag |= |
| 3153 | LPFC_EXCHANGE_BUSY; |
| 3154 | spin_unlock_irqrestore( |
| 3155 | &phba->hbalock, iflag); |
| 3156 | } |
| 3157 | if (cmdiocbp->iocb_flag & |
| 3158 | LPFC_DRIVER_ABORTED) { |
| 3159 | /* |
| 3160 | * Clear LPFC_DRIVER_ABORTED |
| 3161 | * bit in case it was driver |
| 3162 | * initiated abort. |
| 3163 | */ |
| 3164 | spin_lock_irqsave( |
| 3165 | &phba->hbalock, iflag); |
| 3166 | cmdiocbp->iocb_flag &= |
| 3167 | ~LPFC_DRIVER_ABORTED; |
| 3168 | spin_unlock_irqrestore( |
| 3169 | &phba->hbalock, iflag); |
| 3170 | cmdiocbp->iocb.ulpStatus = |
| 3171 | IOSTAT_LOCAL_REJECT; |
| 3172 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3173 | IOERR_ABORT_REQUESTED; |
| 3174 | /* |
| 3175 | * For SLI4, irsiocb contains |
| 3176 | * NO_XRI in sli_xritag, it |
| 3177 | * shall not affect releasing |
| 3178 | * sgl (xri) process. |
| 3179 | */ |
| 3180 | saveq->iocb.ulpStatus = |
| 3181 | IOSTAT_LOCAL_REJECT; |
| 3182 | saveq->iocb.un.ulpWord[4] = |
| 3183 | IOERR_SLI_ABORTED; |
| 3184 | spin_lock_irqsave( |
| 3185 | &phba->hbalock, iflag); |
| 3186 | saveq->iocb_flag |= |
| 3187 | LPFC_DELAY_MEM_FREE; |
| 3188 | spin_unlock_irqrestore( |
| 3189 | &phba->hbalock, iflag); |
| 3190 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3191 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3193 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3194 | } else |
| 3195 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3196 | } else { |
| 3197 | /* |
| 3198 | * Unknown initiating command based on the response iotag. |
| 3199 | * This could be the case on the ELS ring because of |
| 3200 | * lpfc_els_abort(). |
| 3201 | */ |
| 3202 | if (pring->ringno != LPFC_ELS_RING) { |
| 3203 | /* |
| 3204 | * Ring <ringno> handler: unexpected completion IoTag |
| 3205 | * <IoTag> |
| 3206 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3207 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3208 | "0322 Ring %d handler: " |
| 3209 | "unexpected completion IoTag x%x " |
| 3210 | "Data: x%x x%x x%x x%x\n", |
| 3211 | pring->ringno, |
| 3212 | saveq->iocb.ulpIoTag, |
| 3213 | saveq->iocb.ulpStatus, |
| 3214 | saveq->iocb.un.ulpWord[4], |
| 3215 | saveq->iocb.ulpCommand, |
| 3216 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | } |
| 3218 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3219 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3220 | return rc; |
| 3221 | } |
| 3222 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3223 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3224 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3225 | * @phba: Pointer to HBA context object. |
| 3226 | * @pring: Pointer to driver SLI ring object. |
| 3227 | * |
| 3228 | * This function is called from the iocb ring event handlers when |
| 3229 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3230 | * an error attention condition to the worker thread and the worker |
| 3231 | * thread will transition the HBA to offline state. |
| 3232 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3233 | static void |
| 3234 | 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] | 3235 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3236 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3237 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3238 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3239 | * rsp ring <portRspMax> |
| 3240 | */ |
| 3241 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3242 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3243 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3244 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3245 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3246 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3247 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3248 | |
| 3249 | /* |
| 3250 | * All error attention handlers are posted to |
| 3251 | * worker thread |
| 3252 | */ |
| 3253 | phba->work_ha |= HA_ERATT; |
| 3254 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3255 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3256 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3257 | |
| 3258 | return; |
| 3259 | } |
| 3260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3261 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3262 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3263 | * @ptr: Pointer to address of HBA context object. |
| 3264 | * |
| 3265 | * This function is invoked by the Error Attention polling timer when the |
| 3266 | * timer times out. It will check the SLI Error Attention register for |
| 3267 | * possible attention events. If so, it will post an Error Attention event |
| 3268 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3269 | * Error Attention polling timer for the next poll. |
| 3270 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3271 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3272 | { |
| 3273 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3274 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3275 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3276 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3277 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3278 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3279 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3280 | sli_intr = phba->sli.slistat.sli_intr; |
| 3281 | |
| 3282 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3283 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3284 | sli_intr); |
| 3285 | else |
| 3286 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3287 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3288 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3289 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3290 | phba->sli.slistat.sli_ips = cnt; |
| 3291 | |
| 3292 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3293 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3294 | /* Check chip HA register for error event */ |
| 3295 | eratt = lpfc_sli_check_eratt(phba); |
| 3296 | |
| 3297 | if (eratt) |
| 3298 | /* Tell the worker thread there is work to do */ |
| 3299 | lpfc_worker_wake_up(phba); |
| 3300 | else |
| 3301 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3302 | mod_timer(&phba->eratt_poll, |
| 3303 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3304 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3305 | return; |
| 3306 | } |
| 3307 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3310 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3311 | * @phba: Pointer to HBA context object. |
| 3312 | * @pring: Pointer to driver SLI ring object. |
| 3313 | * @mask: Host attention register mask for this ring. |
| 3314 | * |
| 3315 | * This function is called from the interrupt context when there is a ring |
| 3316 | * event for the fcp ring. The caller does not hold any lock. |
| 3317 | * 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] | 3318 | * 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] | 3319 | * LE bit set. The function will call the completion handler of the command iocb |
| 3320 | * if the response iocb indicates a completion for a command iocb or it is |
| 3321 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3322 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3323 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3324 | * to check it explicitly. |
| 3325 | */ |
| 3326 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3327 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3328 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3330 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3332 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3333 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3334 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3335 | uint32_t status; |
| 3336 | uint32_t portRspPut, portRspMax; |
| 3337 | int rc = 1; |
| 3338 | lpfc_iocb_type type; |
| 3339 | unsigned long iflag; |
| 3340 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3342 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3343 | pring->stats.iocb_event++; |
| 3344 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3345 | /* |
| 3346 | * The next available response entry should never exceed the maximum |
| 3347 | * entries. If it does, treat it as an adapter hardware error. |
| 3348 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3349 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3350 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3351 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3352 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3353 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | return 1; |
| 3355 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3356 | if (phba->fcp_ring_in_use) { |
| 3357 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3358 | return 1; |
| 3359 | } else |
| 3360 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | |
| 3362 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3363 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3364 | /* |
| 3365 | * Fetch an entry off the ring and copy it into a local data |
| 3366 | * structure. The copy involves a byte-swap since the |
| 3367 | * network byte order and pci byte orders are different. |
| 3368 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3369 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3370 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3371 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3372 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3373 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3374 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3375 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3376 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3377 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3378 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3379 | irsp = &rspiocbq.iocb; |
| 3380 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3382 | pring->stats.iocb_rsp++; |
| 3383 | rsp_cmpl++; |
| 3384 | |
| 3385 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3386 | /* |
| 3387 | * If resource errors reported from HBA, reduce |
| 3388 | * queuedepths of the SCSI device. |
| 3389 | */ |
| 3390 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3391 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3392 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3393 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3394 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3395 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3396 | } |
| 3397 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | /* Rsp ring <ringno> error: IOCB */ |
| 3399 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3400 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3401 | "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] | 3402 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3403 | irsp->un.ulpWord[0], |
| 3404 | irsp->un.ulpWord[1], |
| 3405 | irsp->un.ulpWord[2], |
| 3406 | irsp->un.ulpWord[3], |
| 3407 | irsp->un.ulpWord[4], |
| 3408 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3409 | *(uint32_t *)&irsp->un1, |
| 3410 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | switch (type) { |
| 3414 | case LPFC_ABORT_IOCB: |
| 3415 | case LPFC_SOL_IOCB: |
| 3416 | /* |
| 3417 | * Idle exchange closed via ABTS from port. No iocb |
| 3418 | * resources need to be recovered. |
| 3419 | */ |
| 3420 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3421 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3422 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3423 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3424 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3425 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3426 | break; |
| 3427 | } |
| 3428 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3429 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3430 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3431 | if (unlikely(!cmdiocbq)) |
| 3432 | break; |
| 3433 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3434 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3435 | if (cmdiocbq->iocb_cmpl) { |
| 3436 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3437 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3438 | &rspiocbq); |
| 3439 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3440 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3442 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3443 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3444 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3445 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3446 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | default: |
| 3448 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3449 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3450 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3451 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3452 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3453 | dev_warn(&((phba->pcidev)->dev), |
| 3454 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | phba->brd_no, adaptermsg); |
| 3456 | } else { |
| 3457 | /* Unknown IOCB command */ |
| 3458 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3459 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3460 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3461 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3462 | irsp->ulpStatus, |
| 3463 | irsp->ulpIoTag, |
| 3464 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 | } |
| 3466 | break; |
| 3467 | } |
| 3468 | |
| 3469 | /* |
| 3470 | * The response IOCB has been processed. Update the ring |
| 3471 | * pointer in SLIM. If the port response put pointer has not |
| 3472 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3473 | * response put pointer. |
| 3474 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3475 | writel(pring->sli.sli3.rspidx, |
| 3476 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3478 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3479 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3480 | } |
| 3481 | |
| 3482 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3483 | pring->stats.iocb_rsp_full++; |
| 3484 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3485 | writel(status, phba->CAregaddr); |
| 3486 | readl(phba->CAregaddr); |
| 3487 | } |
| 3488 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3489 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3490 | pring->stats.iocb_cmd_empty++; |
| 3491 | |
| 3492 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3493 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3494 | lpfc_sli_resume_iocb(phba, pring); |
| 3495 | |
| 3496 | if ((pring->lpfc_sli_cmd_available)) |
| 3497 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3498 | |
| 3499 | } |
| 3500 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3501 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3502 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | return rc; |
| 3504 | } |
| 3505 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3506 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3507 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3508 | * @phba: Pointer to HBA context object. |
| 3509 | * @pring: Pointer to driver SLI ring object. |
| 3510 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3511 | * |
| 3512 | * This function is called from the worker thread when there is a slow-path |
| 3513 | * response IOCB to process. This function chains all the response iocbs until |
| 3514 | * seeing the iocb with the LE bit set. The function will call |
| 3515 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3516 | * completion of a command iocb. The function will call the |
| 3517 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3518 | * The function frees the resources or calls the completion handler if this |
| 3519 | * iocb is an abort completion. The function returns NULL when the response |
| 3520 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3521 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3522 | * response iocb passed in. |
| 3523 | **/ |
| 3524 | static struct lpfc_iocbq * |
| 3525 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3526 | struct lpfc_iocbq *rspiocbp) |
| 3527 | { |
| 3528 | struct lpfc_iocbq *saveq; |
| 3529 | struct lpfc_iocbq *cmdiocbp; |
| 3530 | struct lpfc_iocbq *next_iocb; |
| 3531 | IOCB_t *irsp = NULL; |
| 3532 | uint32_t free_saveq; |
| 3533 | uint8_t iocb_cmd_type; |
| 3534 | lpfc_iocb_type type; |
| 3535 | unsigned long iflag; |
| 3536 | int rc; |
| 3537 | |
| 3538 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3539 | /* First add the response iocb to the countinueq list */ |
| 3540 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3541 | pring->iocb_continueq_cnt++; |
| 3542 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3543 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3544 | irsp = &rspiocbp->iocb; |
| 3545 | if (irsp->ulpLe) { |
| 3546 | /* |
| 3547 | * By default, the driver expects to free all resources |
| 3548 | * associated with this iocb completion. |
| 3549 | */ |
| 3550 | free_saveq = 1; |
| 3551 | saveq = list_get_first(&pring->iocb_continueq, |
| 3552 | struct lpfc_iocbq, list); |
| 3553 | irsp = &(saveq->iocb); |
| 3554 | list_del_init(&pring->iocb_continueq); |
| 3555 | pring->iocb_continueq_cnt = 0; |
| 3556 | |
| 3557 | pring->stats.iocb_rsp++; |
| 3558 | |
| 3559 | /* |
| 3560 | * If resource errors reported from HBA, reduce |
| 3561 | * queuedepths of the SCSI device. |
| 3562 | */ |
| 3563 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3564 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3565 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3566 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3567 | phba->lpfc_rampdown_queue_depth(phba); |
| 3568 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3569 | } |
| 3570 | |
| 3571 | if (irsp->ulpStatus) { |
| 3572 | /* Rsp ring <ringno> error: IOCB */ |
| 3573 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3574 | "0328 Rsp Ring %d error: " |
| 3575 | "IOCB Data: " |
| 3576 | "x%x x%x x%x x%x " |
| 3577 | "x%x x%x x%x x%x " |
| 3578 | "x%x x%x x%x x%x " |
| 3579 | "x%x x%x x%x x%x\n", |
| 3580 | pring->ringno, |
| 3581 | irsp->un.ulpWord[0], |
| 3582 | irsp->un.ulpWord[1], |
| 3583 | irsp->un.ulpWord[2], |
| 3584 | irsp->un.ulpWord[3], |
| 3585 | irsp->un.ulpWord[4], |
| 3586 | irsp->un.ulpWord[5], |
| 3587 | *(((uint32_t *) irsp) + 6), |
| 3588 | *(((uint32_t *) irsp) + 7), |
| 3589 | *(((uint32_t *) irsp) + 8), |
| 3590 | *(((uint32_t *) irsp) + 9), |
| 3591 | *(((uint32_t *) irsp) + 10), |
| 3592 | *(((uint32_t *) irsp) + 11), |
| 3593 | *(((uint32_t *) irsp) + 12), |
| 3594 | *(((uint32_t *) irsp) + 13), |
| 3595 | *(((uint32_t *) irsp) + 14), |
| 3596 | *(((uint32_t *) irsp) + 15)); |
| 3597 | } |
| 3598 | |
| 3599 | /* |
| 3600 | * Fetch the IOCB command type and call the correct completion |
| 3601 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3602 | * get freed back to the lpfc_iocb_list by the discovery |
| 3603 | * kernel thread. |
| 3604 | */ |
| 3605 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3606 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3607 | switch (type) { |
| 3608 | case LPFC_SOL_IOCB: |
| 3609 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3610 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3611 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3612 | break; |
| 3613 | |
| 3614 | case LPFC_UNSOL_IOCB: |
| 3615 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3616 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3617 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3618 | if (!rc) |
| 3619 | free_saveq = 0; |
| 3620 | break; |
| 3621 | |
| 3622 | case LPFC_ABORT_IOCB: |
| 3623 | cmdiocbp = NULL; |
| 3624 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3625 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3626 | saveq); |
| 3627 | if (cmdiocbp) { |
| 3628 | /* Call the specified completion routine */ |
| 3629 | if (cmdiocbp->iocb_cmpl) { |
| 3630 | spin_unlock_irqrestore(&phba->hbalock, |
| 3631 | iflag); |
| 3632 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3633 | saveq); |
| 3634 | spin_lock_irqsave(&phba->hbalock, |
| 3635 | iflag); |
| 3636 | } else |
| 3637 | __lpfc_sli_release_iocbq(phba, |
| 3638 | cmdiocbp); |
| 3639 | } |
| 3640 | break; |
| 3641 | |
| 3642 | case LPFC_UNKNOWN_IOCB: |
| 3643 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3644 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3645 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3646 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3647 | MAX_MSG_DATA); |
| 3648 | dev_warn(&((phba->pcidev)->dev), |
| 3649 | "lpfc%d: %s\n", |
| 3650 | phba->brd_no, adaptermsg); |
| 3651 | } else { |
| 3652 | /* Unknown IOCB command */ |
| 3653 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3654 | "0335 Unknown IOCB " |
| 3655 | "command Data: x%x " |
| 3656 | "x%x x%x x%x\n", |
| 3657 | irsp->ulpCommand, |
| 3658 | irsp->ulpStatus, |
| 3659 | irsp->ulpIoTag, |
| 3660 | irsp->ulpContext); |
| 3661 | } |
| 3662 | break; |
| 3663 | } |
| 3664 | |
| 3665 | if (free_saveq) { |
| 3666 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3667 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3668 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3669 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3670 | } |
| 3671 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3672 | } |
| 3673 | rspiocbp = NULL; |
| 3674 | } |
| 3675 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3676 | return rspiocbp; |
| 3677 | } |
| 3678 | |
| 3679 | /** |
| 3680 | * 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] | 3681 | * @phba: Pointer to HBA context object. |
| 3682 | * @pring: Pointer to driver SLI ring object. |
| 3683 | * @mask: Host attention register mask for this ring. |
| 3684 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3685 | * This routine wraps the actual slow_ring event process routine from the |
| 3686 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3687 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3688 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3689 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3690 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3692 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3693 | } |
| 3694 | |
| 3695 | /** |
| 3696 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3697 | * @phba: Pointer to HBA context object. |
| 3698 | * @pring: Pointer to driver SLI ring object. |
| 3699 | * @mask: Host attention register mask for this ring. |
| 3700 | * |
| 3701 | * This function is called from the worker thread when there is a ring event |
| 3702 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3703 | * remove each response iocb in the response ring and calls the handle |
| 3704 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3705 | **/ |
| 3706 | static void |
| 3707 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3708 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3709 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3710 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | IOCB_t *entry; |
| 3712 | IOCB_t *irsp = NULL; |
| 3713 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3716 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3718 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3719 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | pring->stats.iocb_event++; |
| 3721 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3722 | /* |
| 3723 | * The next available response entry should never exceed the maximum |
| 3724 | * entries. If it does, treat it as an adapter hardware error. |
| 3725 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3726 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3728 | if (portRspPut >= portRspMax) { |
| 3729 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3730 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | * rsp ring <portRspMax> |
| 3732 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3733 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3734 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3735 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3736 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3738 | phba->link_state = LPFC_HBA_ERROR; |
| 3739 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | |
| 3741 | phba->work_hs = HS_FFER3; |
| 3742 | lpfc_handle_eratt(phba); |
| 3743 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3744 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3748 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | /* |
| 3750 | * Build a completion list and call the appropriate handler. |
| 3751 | * The process is to get the next available response iocb, get |
| 3752 | * a free iocb from the list, copy the response data into the |
| 3753 | * free iocb, insert to the continuation list, and update the |
| 3754 | * next response index to slim. This process makes response |
| 3755 | * iocb's in the ring available to DMA as fast as possible but |
| 3756 | * pays a penalty for a copy operation. Since the iocb is |
| 3757 | * only 32 bytes, this penalty is considered small relative to |
| 3758 | * the PCI reads for register values and a slim write. When |
| 3759 | * the ulpLe field is set, the entire Command has been |
| 3760 | * received. |
| 3761 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3762 | entry = lpfc_resp_iocb(phba, pring); |
| 3763 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3764 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3765 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | if (rspiocbp == NULL) { |
| 3767 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3768 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | break; |
| 3770 | } |
| 3771 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3772 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3773 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | irsp = &rspiocbp->iocb; |
| 3775 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3776 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3777 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3779 | if (pring->ringno == LPFC_ELS_RING) { |
| 3780 | lpfc_debugfs_slow_ring_trc(phba, |
| 3781 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3782 | *(((uint32_t *) irsp) + 4), |
| 3783 | *(((uint32_t *) irsp) + 6), |
| 3784 | *(((uint32_t *) irsp) + 7)); |
| 3785 | } |
| 3786 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3787 | writel(pring->sli.sli3.rspidx, |
| 3788 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3790 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3791 | /* Handle the response IOCB */ |
| 3792 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3793 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3794 | |
| 3795 | /* |
| 3796 | * If the port response put pointer has not been updated, sync |
| 3797 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3798 | * response put pointer. |
| 3799 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3800 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3802 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3803 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3805 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | /* At least one response entry has been freed */ |
| 3807 | pring->stats.iocb_rsp_full++; |
| 3808 | /* SET RxRE_RSP in Chip Att register */ |
| 3809 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3810 | writel(status, phba->CAregaddr); |
| 3811 | readl(phba->CAregaddr); /* flush */ |
| 3812 | } |
| 3813 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3814 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3815 | pring->stats.iocb_cmd_empty++; |
| 3816 | |
| 3817 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3818 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 | lpfc_sli_resume_iocb(phba, pring); |
| 3820 | |
| 3821 | if ((pring->lpfc_sli_cmd_available)) |
| 3822 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3823 | |
| 3824 | } |
| 3825 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3826 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3827 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3828 | } |
| 3829 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3830 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3831 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3832 | * @phba: Pointer to HBA context object. |
| 3833 | * @pring: Pointer to driver SLI ring object. |
| 3834 | * @mask: Host attention register mask for this ring. |
| 3835 | * |
| 3836 | * This function is called from the worker thread when there is a pending |
| 3837 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3838 | * queue. The caller does not hold any lock. The function will remove each |
| 3839 | * response iocb from the response worker queue and calls the handle |
| 3840 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3841 | **/ |
| 3842 | static void |
| 3843 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3844 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3845 | { |
| 3846 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3847 | struct hbq_dmabuf *dmabuf; |
| 3848 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3849 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3850 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3851 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3852 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3853 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3854 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3855 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3856 | /* Get the response iocb from the head of work queue */ |
| 3857 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3858 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3859 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3860 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3861 | |
| 3862 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3863 | case CQE_CODE_COMPL_WQE: |
| 3864 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3865 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3866 | /* Translate ELS WCQE to response IOCBQ */ |
| 3867 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3868 | irspiocbq); |
| 3869 | if (irspiocbq) |
| 3870 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3871 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3872 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3873 | break; |
| 3874 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3875 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3876 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3877 | cq_event); |
| 3878 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3879 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3880 | break; |
| 3881 | default: |
| 3882 | break; |
| 3883 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3884 | |
| 3885 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 3886 | if (count == 64) |
| 3887 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3888 | } |
| 3889 | } |
| 3890 | |
| 3891 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3892 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3893 | * @phba: Pointer to HBA context object. |
| 3894 | * @pring: Pointer to driver SLI ring object. |
| 3895 | * |
| 3896 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3897 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3898 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3899 | * the return of this function. The caller is not required to hold any locks. |
| 3900 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3902 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3903 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3904 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3905 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3907 | if (pring->ringno == LPFC_ELS_RING) { |
| 3908 | lpfc_fabric_abort_hba(phba); |
| 3909 | } |
| 3910 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | /* Error everything on txq and txcmplq |
| 3912 | * First do the txq. |
| 3913 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3914 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3915 | spin_lock_irq(&pring->ring_lock); |
| 3916 | list_splice_init(&pring->txq, &completions); |
| 3917 | pring->txq_cnt = 0; |
| 3918 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3920 | spin_lock_irq(&phba->hbalock); |
| 3921 | /* Next issue ABTS for everything on the txcmplq */ |
| 3922 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3923 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3924 | spin_unlock_irq(&phba->hbalock); |
| 3925 | } else { |
| 3926 | spin_lock_irq(&phba->hbalock); |
| 3927 | list_splice_init(&pring->txq, &completions); |
| 3928 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3929 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3930 | /* Next issue ABTS for everything on the txcmplq */ |
| 3931 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3932 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3933 | spin_unlock_irq(&phba->hbalock); |
| 3934 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3935 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3936 | /* Cancel all the IOCBs from the completions list */ |
| 3937 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3938 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3939 | } |
| 3940 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3941 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3942 | * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring |
| 3943 | * @phba: Pointer to HBA context object. |
| 3944 | * @pring: Pointer to driver SLI ring object. |
| 3945 | * |
| 3946 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3947 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3948 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3949 | * the return of this function. The caller is not required to hold any locks. |
| 3950 | **/ |
| 3951 | void |
| 3952 | lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3953 | { |
| 3954 | LIST_HEAD(completions); |
| 3955 | struct lpfc_iocbq *iocb, *next_iocb; |
| 3956 | |
| 3957 | if (pring->ringno == LPFC_ELS_RING) |
| 3958 | lpfc_fabric_abort_hba(phba); |
| 3959 | |
| 3960 | spin_lock_irq(&phba->hbalock); |
| 3961 | /* Next issue ABTS for everything on the txcmplq */ |
| 3962 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3963 | lpfc_sli4_abort_nvme_io(phba, pring, iocb); |
| 3964 | spin_unlock_irq(&phba->hbalock); |
| 3965 | } |
| 3966 | |
| 3967 | |
| 3968 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3969 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3970 | * @phba: Pointer to HBA context object. |
| 3971 | * @pring: Pointer to driver SLI ring object. |
| 3972 | * |
| 3973 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3974 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3975 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3976 | * the return of this function. The caller is not required to hold any locks. |
| 3977 | **/ |
| 3978 | void |
| 3979 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3980 | { |
| 3981 | struct lpfc_sli *psli = &phba->sli; |
| 3982 | struct lpfc_sli_ring *pring; |
| 3983 | uint32_t i; |
| 3984 | |
| 3985 | /* Look on all the FCP Rings for the iotag */ |
| 3986 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3987 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 3988 | pring = phba->sli4_hba.hdwq[i].fcp_wq->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3989 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3990 | } |
| 3991 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3992 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3993 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3994 | } |
| 3995 | } |
| 3996 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3997 | /** |
| 3998 | * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings |
| 3999 | * @phba: Pointer to HBA context object. |
| 4000 | * |
| 4001 | * This function aborts all wqes in NVME rings. This function issues an |
| 4002 | * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in |
| 4003 | * the txcmplq is not guaranteed to complete before the return of this |
| 4004 | * function. The caller is not required to hold any locks. |
| 4005 | **/ |
| 4006 | void |
| 4007 | lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba) |
| 4008 | { |
| 4009 | struct lpfc_sli_ring *pring; |
| 4010 | uint32_t i; |
| 4011 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4012 | if ((phba->sli_rev < LPFC_SLI_REV4) || |
| 4013 | !(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4014 | return; |
| 4015 | |
| 4016 | /* Abort all IO on each NVME ring. */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4017 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 4018 | pring = phba->sli4_hba.hdwq[i].nvme_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4019 | lpfc_sli_abort_wqe_ring(phba, pring); |
| 4020 | } |
| 4021 | } |
| 4022 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4023 | |
| 4024 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4025 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4026 | * @phba: Pointer to HBA context object. |
| 4027 | * |
| 4028 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 4029 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 4030 | * for all the iocb commands in txcmplq, they will just be returned with |
| 4031 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4032 | * slot has been permanently disabled. |
| 4033 | **/ |
| 4034 | void |
| 4035 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 4036 | { |
| 4037 | LIST_HEAD(txq); |
| 4038 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4039 | struct lpfc_sli *psli = &phba->sli; |
| 4040 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4041 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4042 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4043 | |
| 4044 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4045 | /* Indicate the I/O queues are flushed */ |
| 4046 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4047 | spin_unlock_irq(&phba->hbalock); |
| 4048 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4049 | /* Look on all the FCP Rings for the iotag */ |
| 4050 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4051 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 4052 | pring = phba->sli4_hba.hdwq[i].fcp_wq->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4053 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4054 | spin_lock_irq(&pring->ring_lock); |
| 4055 | /* Retrieve everything on txq */ |
| 4056 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4057 | list_for_each_entry_safe(piocb, next_iocb, |
| 4058 | &pring->txcmplq, list) |
| 4059 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4060 | /* Retrieve everything on the txcmplq */ |
| 4061 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4062 | pring->txq_cnt = 0; |
| 4063 | pring->txcmplq_cnt = 0; |
| 4064 | spin_unlock_irq(&pring->ring_lock); |
| 4065 | |
| 4066 | /* Flush the txq */ |
| 4067 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4068 | IOSTAT_LOCAL_REJECT, |
| 4069 | IOERR_SLI_DOWN); |
| 4070 | /* Flush the txcmpq */ |
| 4071 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4072 | IOSTAT_LOCAL_REJECT, |
| 4073 | IOERR_SLI_DOWN); |
| 4074 | } |
| 4075 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4076 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4077 | |
| 4078 | spin_lock_irq(&phba->hbalock); |
| 4079 | /* Retrieve everything on txq */ |
| 4080 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4081 | list_for_each_entry_safe(piocb, next_iocb, |
| 4082 | &pring->txcmplq, list) |
| 4083 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4084 | /* Retrieve everything on the txcmplq */ |
| 4085 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4086 | pring->txq_cnt = 0; |
| 4087 | pring->txcmplq_cnt = 0; |
| 4088 | spin_unlock_irq(&phba->hbalock); |
| 4089 | |
| 4090 | /* Flush the txq */ |
| 4091 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4092 | IOERR_SLI_DOWN); |
| 4093 | /* Flush the txcmpq */ |
| 4094 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4095 | IOERR_SLI_DOWN); |
| 4096 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4100 | * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings |
| 4101 | * @phba: Pointer to HBA context object. |
| 4102 | * |
| 4103 | * This function flushes all wqes in the nvme rings and frees all resources |
| 4104 | * in the txcmplq. This function does not issue abort wqes for the IO |
| 4105 | * commands in txcmplq, they will just be returned with |
| 4106 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4107 | * slot has been permanently disabled. |
| 4108 | **/ |
| 4109 | void |
| 4110 | lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba) |
| 4111 | { |
| 4112 | LIST_HEAD(txcmplq); |
| 4113 | struct lpfc_sli_ring *pring; |
| 4114 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4115 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4116 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4117 | if ((phba->sli_rev < LPFC_SLI_REV4) || |
| 4118 | !(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4119 | return; |
| 4120 | |
| 4121 | /* Hint to other driver operations that a flush is in progress. */ |
| 4122 | spin_lock_irq(&phba->hbalock); |
| 4123 | phba->hba_flag |= HBA_NVME_IOQ_FLUSH; |
| 4124 | spin_unlock_irq(&phba->hbalock); |
| 4125 | |
| 4126 | /* Cycle through all NVME rings and complete each IO with |
| 4127 | * a local driver reason code. This is a flush so no |
| 4128 | * abort exchange to FW. |
| 4129 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4130 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 4131 | pring = phba->sli4_hba.hdwq[i].nvme_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4132 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4133 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4134 | list_for_each_entry_safe(piocb, next_iocb, |
| 4135 | &pring->txcmplq, list) |
| 4136 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
| 4137 | /* Retrieve everything on the txcmplq */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4138 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4139 | pring->txcmplq_cnt = 0; |
| 4140 | spin_unlock_irq(&pring->ring_lock); |
| 4141 | |
| 4142 | /* Flush the txcmpq &&&PAE */ |
| 4143 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4144 | IOSTAT_LOCAL_REJECT, |
| 4145 | IOERR_SLI_DOWN); |
| 4146 | } |
| 4147 | } |
| 4148 | |
| 4149 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4150 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4151 | * @phba: Pointer to HBA context object. |
| 4152 | * @mask: Bit mask to be checked. |
| 4153 | * |
| 4154 | * This function reads the host status register and compares |
| 4155 | * with the provided bit mask to check if HBA completed |
| 4156 | * the restart. This function will wait in a loop for the |
| 4157 | * HBA to complete restart. If the HBA does not restart within |
| 4158 | * 15 iterations, the function will reset the HBA again. The |
| 4159 | * function returns 1 when HBA fail to restart otherwise returns |
| 4160 | * zero. |
| 4161 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4162 | static int |
| 4163 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4165 | uint32_t status; |
| 4166 | int i = 0; |
| 4167 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4169 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4170 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4171 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4173 | /* |
| 4174 | * Check status register every 100ms for 5 retries, then every |
| 4175 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4176 | * every 2.5 sec for 4. |
| 4177 | * Break our of the loop if errors occurred during init. |
| 4178 | */ |
| 4179 | while (((status & mask) != mask) && |
| 4180 | !(status & HS_FFERM) && |
| 4181 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4183 | if (i <= 5) |
| 4184 | msleep(10); |
| 4185 | else if (i <= 10) |
| 4186 | msleep(500); |
| 4187 | else |
| 4188 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4190 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4191 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4192 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4193 | lpfc_sli_brdrestart(phba); |
| 4194 | } |
| 4195 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4196 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4197 | retval = 1; |
| 4198 | break; |
| 4199 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4200 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4201 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4202 | /* Check to see if any errors occurred during init */ |
| 4203 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4204 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4205 | "2751 Adapter failed to restart, " |
| 4206 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4207 | status, |
| 4208 | readl(phba->MBslimaddr + 0xa8), |
| 4209 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4210 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4211 | retval = 1; |
| 4212 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4214 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | } |
| 4216 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4217 | /** |
| 4218 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4219 | * @phba: Pointer to HBA context object. |
| 4220 | * @mask: Bit mask to be checked. |
| 4221 | * |
| 4222 | * This function checks the host status register to check if HBA is |
| 4223 | * ready. This function will wait in a loop for the HBA to be ready |
| 4224 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4225 | * function again. The function returns 1 when HBA fail to be ready |
| 4226 | * otherwise returns zero. |
| 4227 | **/ |
| 4228 | static int |
| 4229 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4230 | { |
| 4231 | uint32_t status; |
| 4232 | int retval = 0; |
| 4233 | |
| 4234 | /* Read the HBA Host Status Register */ |
| 4235 | status = lpfc_sli4_post_status_check(phba); |
| 4236 | |
| 4237 | if (status) { |
| 4238 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4239 | lpfc_sli_brdrestart(phba); |
| 4240 | status = lpfc_sli4_post_status_check(phba); |
| 4241 | } |
| 4242 | |
| 4243 | /* Check to see if any errors occurred during init */ |
| 4244 | if (status) { |
| 4245 | phba->link_state = LPFC_HBA_ERROR; |
| 4246 | retval = 1; |
| 4247 | } else |
| 4248 | phba->sli4_hba.intr_enable = 0; |
| 4249 | |
| 4250 | return retval; |
| 4251 | } |
| 4252 | |
| 4253 | /** |
| 4254 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4255 | * @phba: Pointer to HBA context object. |
| 4256 | * @mask: Bit mask to be checked. |
| 4257 | * |
| 4258 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4259 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4260 | **/ |
| 4261 | int |
| 4262 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4263 | { |
| 4264 | return phba->lpfc_sli_brdready(phba, mask); |
| 4265 | } |
| 4266 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4267 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4268 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4269 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4270 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4271 | * @phba: Pointer to HBA context object. |
| 4272 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4273 | * This function is called before resetting an HBA. This function is called |
| 4274 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4275 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4276 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4277 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4278 | uint32_t __iomem *resp_buf; |
| 4279 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4280 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4281 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4282 | int i; |
| 4283 | uint8_t hdrtype; |
| 4284 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4285 | lockdep_assert_held(&phba->hbalock); |
| 4286 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4287 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4288 | if (hdrtype != 0x80 || |
| 4289 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4290 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4291 | return; |
| 4292 | |
| 4293 | /* |
| 4294 | * Tell the other part of the chip to suspend temporarily all |
| 4295 | * its DMA activity. |
| 4296 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4297 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4298 | |
| 4299 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4300 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4301 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4302 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4303 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4305 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4306 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4307 | return; |
| 4308 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4309 | /* Clear Chip error bit */ |
| 4310 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4311 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | mbox = 0; |
| 4315 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4316 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4317 | |
| 4318 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4319 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4320 | writel(mbox, mbox_buf); |
| 4321 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4322 | for (i = 0; i < 50; i++) { |
| 4323 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4324 | return; |
| 4325 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4326 | mdelay(1); |
| 4327 | else |
| 4328 | break; |
| 4329 | } |
| 4330 | resp_data = 0; |
| 4331 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4332 | return; |
| 4333 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4334 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4335 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4336 | goto restore_hc; |
| 4337 | else |
| 4338 | goto clear_errat; |
| 4339 | } |
| 4340 | |
| 4341 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4342 | resp_data = 0; |
| 4343 | for (i = 0; i < 500; i++) { |
| 4344 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4345 | return; |
| 4346 | if (resp_data != mbox) |
| 4347 | mdelay(1); |
| 4348 | else |
| 4349 | break; |
| 4350 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4351 | |
| 4352 | clear_errat: |
| 4353 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4354 | while (++i < 500) { |
| 4355 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4356 | return; |
| 4357 | if (!(ha_copy & HA_ERATT)) |
| 4358 | mdelay(1); |
| 4359 | else |
| 4360 | break; |
| 4361 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4362 | |
| 4363 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4364 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4365 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4369 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4370 | writel(hc_copy, phba->HCregaddr); |
| 4371 | readl(phba->HCregaddr); /* flush */ |
| 4372 | } |
| 4373 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4374 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4375 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4376 | * @phba: Pointer to HBA context object. |
| 4377 | * |
| 4378 | * This function issues a kill_board mailbox command and waits for |
| 4379 | * the error attention interrupt. This function is called for stopping |
| 4380 | * the firmware processing. The caller is not required to hold any |
| 4381 | * locks. This function calls lpfc_hba_down_post function to free |
| 4382 | * any pending commands after the kill. The function will return 1 when it |
| 4383 | * fails to kill the board else will return 0. |
| 4384 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4385 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4386 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4387 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4388 | struct lpfc_sli *psli; |
| 4389 | LPFC_MBOXQ_t *pmb; |
| 4390 | uint32_t status; |
| 4391 | uint32_t ha_copy; |
| 4392 | int retval; |
| 4393 | int i = 0; |
| 4394 | |
| 4395 | psli = &phba->sli; |
| 4396 | |
| 4397 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4398 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4399 | "0329 Kill HBA Data: x%x x%x\n", |
| 4400 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4401 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4402 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4403 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4404 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4405 | |
| 4406 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4407 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4408 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4409 | spin_unlock_irq(&phba->hbalock); |
| 4410 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4411 | return 1; |
| 4412 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4413 | status &= ~HC_ERINT_ENA; |
| 4414 | writel(status, phba->HCregaddr); |
| 4415 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4416 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4417 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4418 | |
| 4419 | lpfc_kill_board(phba, pmb); |
| 4420 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4421 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4422 | |
| 4423 | if (retval != MBX_SUCCESS) { |
| 4424 | if (retval != MBX_BUSY) |
| 4425 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4426 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4427 | "2752 KILL_BOARD command failed retval %d\n", |
| 4428 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4429 | spin_lock_irq(&phba->hbalock); |
| 4430 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4431 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4432 | return 1; |
| 4433 | } |
| 4434 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4435 | spin_lock_irq(&phba->hbalock); |
| 4436 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4437 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4438 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4439 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4440 | |
| 4441 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4442 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4443 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4444 | * board is now undefined. |
| 4445 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4446 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4447 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4448 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4449 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4450 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4451 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4452 | } |
| 4453 | |
| 4454 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4455 | if (ha_copy & HA_ERATT) { |
| 4456 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4458 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4459 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4460 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4461 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4462 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4463 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4464 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4465 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4466 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4467 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4468 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4469 | } |
| 4470 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4471 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4472 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4473 | * @phba: Pointer to HBA context object. |
| 4474 | * |
| 4475 | * This function resets the HBA by writing HC_INITFF to the control |
| 4476 | * register. After the HBA resets, this function resets all the iocb ring |
| 4477 | * indices. This function disables PCI layer parity checking during |
| 4478 | * the reset. |
| 4479 | * This function returns 0 always. |
| 4480 | * The caller is not required to hold any locks. |
| 4481 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4482 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4483 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4484 | { |
| 4485 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4487 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4488 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4489 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4490 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4491 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4492 | /* Reset HBA */ |
| 4493 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4494 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4495 | (phba->pport) ? phba->pport->port_state : 0, |
| 4496 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4497 | |
| 4498 | /* perform board reset */ |
| 4499 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4500 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4501 | if (phba->pport) { |
| 4502 | phba->pport->fc_myDID = 0; |
| 4503 | phba->pport->fc_prevDID = 0; |
| 4504 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4505 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4506 | /* Turn off parity checking and serr during the physical reset */ |
| 4507 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4508 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4509 | (cfg_value & |
| 4510 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4511 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4512 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4513 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4514 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4515 | writel(HC_INITFF, phba->HCregaddr); |
| 4516 | mdelay(1); |
| 4517 | readl(phba->HCregaddr); /* flush */ |
| 4518 | writel(0, phba->HCregaddr); |
| 4519 | readl(phba->HCregaddr); /* flush */ |
| 4520 | |
| 4521 | /* Restore PCI cmd register */ |
| 4522 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4523 | |
| 4524 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4525 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4526 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4527 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4528 | pring->sli.sli3.rspidx = 0; |
| 4529 | pring->sli.sli3.next_cmdidx = 0; |
| 4530 | pring->sli.sli3.local_getidx = 0; |
| 4531 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4532 | pring->missbufcnt = 0; |
| 4533 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4534 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4535 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4536 | return 0; |
| 4537 | } |
| 4538 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4539 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4540 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4541 | * @phba: Pointer to HBA context object. |
| 4542 | * |
| 4543 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4544 | * checking during resets the device. The caller is not required to hold |
| 4545 | * any locks. |
| 4546 | * |
| 4547 | * This function returns 0 always. |
| 4548 | **/ |
| 4549 | int |
| 4550 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4551 | { |
| 4552 | struct lpfc_sli *psli = &phba->sli; |
| 4553 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4554 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4555 | |
| 4556 | /* Reset HBA */ |
| 4557 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4558 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4559 | phba->pport->port_state, psli->sli_flag, |
| 4560 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4561 | |
| 4562 | /* perform board reset */ |
| 4563 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4564 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4565 | phba->pport->fc_myDID = 0; |
| 4566 | phba->pport->fc_prevDID = 0; |
| 4567 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4568 | spin_lock_irq(&phba->hbalock); |
| 4569 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4570 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4571 | spin_unlock_irq(&phba->hbalock); |
| 4572 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4573 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4574 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4575 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4576 | return rc; |
| 4577 | } |
| 4578 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4579 | /* Now physically reset the device */ |
| 4580 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4581 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4582 | |
| 4583 | /* Turn off parity checking and serr during the physical reset */ |
| 4584 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4585 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4586 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4587 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4588 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4589 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4590 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4591 | /* Restore PCI cmd register */ |
| 4592 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4593 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4594 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | /** |
| 4598 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4599 | * @phba: Pointer to HBA context object. |
| 4600 | * |
| 4601 | * This function is called in the SLI initialization code path to |
| 4602 | * restart the HBA. The caller is not required to hold any lock. |
| 4603 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4604 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4605 | * function to free any pending commands. The function enables |
| 4606 | * POST only during the first initialization. The function returns zero. |
| 4607 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4608 | * command before the return of this function. |
| 4609 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4610 | static int |
| 4611 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4612 | { |
| 4613 | MAILBOX_t *mb; |
| 4614 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4615 | volatile uint32_t word0; |
| 4616 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4617 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4618 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4620 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4621 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4622 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4623 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4624 | psli = &phba->sli; |
| 4625 | |
| 4626 | /* Restart HBA */ |
| 4627 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4628 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4629 | (phba->pport) ? phba->pport->port_state : 0, |
| 4630 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4631 | |
| 4632 | word0 = 0; |
| 4633 | mb = (MAILBOX_t *) &word0; |
| 4634 | mb->mbxCommand = MBX_RESTART; |
| 4635 | mb->mbxHc = 1; |
| 4636 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4637 | lpfc_reset_barrier(phba); |
| 4638 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4639 | to_slim = phba->MBslimaddr; |
| 4640 | writel(*(uint32_t *) mb, to_slim); |
| 4641 | readl(to_slim); /* flush */ |
| 4642 | |
| 4643 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4644 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4645 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4646 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4647 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4648 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4649 | writel(*(uint32_t *) mb, to_slim); |
| 4650 | readl(to_slim); /* flush */ |
| 4651 | |
| 4652 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4653 | if (phba->pport) |
| 4654 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4655 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4656 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4657 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4658 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4659 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4660 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4661 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4662 | /* Give the INITFF and Post time to settle. */ |
| 4663 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4664 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4665 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4666 | if (hba_aer_enabled) |
| 4667 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4668 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4669 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4670 | |
| 4671 | return 0; |
| 4672 | } |
| 4673 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4674 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4675 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4676 | * @phba: Pointer to HBA context object. |
| 4677 | * |
| 4678 | * This function is called in the SLI initialization code path to restart |
| 4679 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4680 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4681 | * free any pending commands. |
| 4682 | **/ |
| 4683 | static int |
| 4684 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4685 | { |
| 4686 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4687 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4688 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4689 | |
| 4690 | /* Restart HBA */ |
| 4691 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4692 | "0296 Restart HBA Data: x%x x%x\n", |
| 4693 | phba->pport->port_state, psli->sli_flag); |
| 4694 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4695 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4696 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4697 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4698 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 4699 | if (rc) |
| 4700 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4701 | |
| 4702 | spin_lock_irq(&phba->hbalock); |
| 4703 | phba->pport->stopped = 0; |
| 4704 | phba->link_state = LPFC_INIT_START; |
| 4705 | phba->hba_flag = 0; |
| 4706 | spin_unlock_irq(&phba->hbalock); |
| 4707 | |
| 4708 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4709 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4710 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4711 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4712 | if (hba_aer_enabled) |
| 4713 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4714 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4715 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4716 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4717 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4718 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | /** |
| 4722 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4723 | * @phba: Pointer to HBA context object. |
| 4724 | * |
| 4725 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4726 | * API jump table function pointer from the lpfc_hba struct. |
| 4727 | **/ |
| 4728 | int |
| 4729 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4730 | { |
| 4731 | return phba->lpfc_sli_brdrestart(phba); |
| 4732 | } |
| 4733 | |
| 4734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4735 | * 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] | 4736 | * @phba: Pointer to HBA context object. |
| 4737 | * |
| 4738 | * This function is called after a HBA restart to wait for successful |
| 4739 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4740 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4741 | * iteration, the function will restart the HBA again. The function returns |
| 4742 | * zero if HBA successfully restarted else returns negative error code. |
| 4743 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4744 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4746 | { |
| 4747 | uint32_t status, i = 0; |
| 4748 | |
| 4749 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4750 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4751 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | |
| 4753 | /* Check status register to see what current state is */ |
| 4754 | i = 0; |
| 4755 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4756 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4757 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4758 | * retries, then every 1 sec for 50 retires for a total of |
| 4759 | * ~60 seconds before reset the board again and check every |
| 4760 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4761 | * board ready is required by the Falcon FIPS zeroization |
| 4762 | * complete, and any reset the board in between shall cause |
| 4763 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4764 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4765 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4766 | /* Adapter failed to init, timeout, status reg |
| 4767 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4768 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4769 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4770 | "timeout, status reg x%x, " |
| 4771 | "FW Data: A8 x%x AC x%x\n", status, |
| 4772 | readl(phba->MBslimaddr + 0xa8), |
| 4773 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4774 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4775 | return -ETIMEDOUT; |
| 4776 | } |
| 4777 | |
| 4778 | /* Check to see if any errors occurred during init */ |
| 4779 | if (status & HS_FFERM) { |
| 4780 | /* ERROR: During chipset initialization */ |
| 4781 | /* Adapter failed to init, chipset, status reg |
| 4782 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4784 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4785 | "chipset, status reg x%x, " |
| 4786 | "FW Data: A8 x%x AC x%x\n", status, |
| 4787 | readl(phba->MBslimaddr + 0xa8), |
| 4788 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4789 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4790 | return -EIO; |
| 4791 | } |
| 4792 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4793 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4794 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4795 | else if (i <= 100) |
| 4796 | msleep(100); |
| 4797 | else |
| 4798 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4800 | if (i == 150) { |
| 4801 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4802 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4803 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4804 | } |
| 4805 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4806 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4807 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | /* Check to see if any errors occurred during init */ |
| 4811 | if (status & HS_FFERM) { |
| 4812 | /* ERROR: During chipset initialization */ |
| 4813 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4814 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4815 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4816 | "status reg x%x, " |
| 4817 | "FW Data: A8 x%x AC x%x\n", status, |
| 4818 | readl(phba->MBslimaddr + 0xa8), |
| 4819 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4820 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4821 | return -EIO; |
| 4822 | } |
| 4823 | |
| 4824 | /* Clear all interrupt enable conditions */ |
| 4825 | writel(0, phba->HCregaddr); |
| 4826 | readl(phba->HCregaddr); /* flush */ |
| 4827 | |
| 4828 | /* setup host attn register */ |
| 4829 | writel(0xffffffff, phba->HAregaddr); |
| 4830 | readl(phba->HAregaddr); /* flush */ |
| 4831 | return 0; |
| 4832 | } |
| 4833 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4834 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4835 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4836 | * |
| 4837 | * This function calculates and returns the number of HBQs required to be |
| 4838 | * configured. |
| 4839 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4840 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4841 | lpfc_sli_hbq_count(void) |
| 4842 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4843 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4844 | } |
| 4845 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4846 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4847 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4848 | * |
| 4849 | * This function adds the number of hbq entries in every HBQ to get |
| 4850 | * the total number of hbq entries required for the HBA and returns |
| 4851 | * the total count. |
| 4852 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4853 | static int |
| 4854 | lpfc_sli_hbq_entry_count(void) |
| 4855 | { |
| 4856 | int hbq_count = lpfc_sli_hbq_count(); |
| 4857 | int count = 0; |
| 4858 | int i; |
| 4859 | |
| 4860 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4861 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4862 | return count; |
| 4863 | } |
| 4864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4865 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4866 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4867 | * |
| 4868 | * This function calculates amount of memory required for all hbq entries |
| 4869 | * to be configured and returns the total memory required. |
| 4870 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4871 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4872 | lpfc_sli_hbq_size(void) |
| 4873 | { |
| 4874 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4875 | } |
| 4876 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4877 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4878 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4879 | * @phba: Pointer to HBA context object. |
| 4880 | * |
| 4881 | * This function is called during the SLI initialization to configure |
| 4882 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4883 | * required to hold any locks. This function will return zero if successful |
| 4884 | * else it will return negative error code. |
| 4885 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4886 | static int |
| 4887 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4888 | { |
| 4889 | int hbq_count = lpfc_sli_hbq_count(); |
| 4890 | LPFC_MBOXQ_t *pmb; |
| 4891 | MAILBOX_t *pmbox; |
| 4892 | uint32_t hbqno; |
| 4893 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4894 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4895 | /* Get a Mailbox buffer to setup mailbox |
| 4896 | * commands for HBA initialization |
| 4897 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4898 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4899 | |
| 4900 | if (!pmb) |
| 4901 | return -ENOMEM; |
| 4902 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4903 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4904 | |
| 4905 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4906 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4907 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4908 | |
| 4909 | hbq_entry_index = 0; |
| 4910 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4911 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4912 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4913 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4914 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4915 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4916 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4917 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4918 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4919 | |
| 4920 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4921 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4922 | mbxStatus <status>, ring <num> */ |
| 4923 | |
| 4924 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4925 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4926 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4927 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4928 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4929 | pmbox->mbxStatus, hbqno); |
| 4930 | |
| 4931 | phba->link_state = LPFC_HBA_ERROR; |
| 4932 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4933 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4934 | } |
| 4935 | } |
| 4936 | phba->hbq_count = hbq_count; |
| 4937 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4938 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4939 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4940 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4941 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4942 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4943 | return 0; |
| 4944 | } |
| 4945 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4946 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4947 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4948 | * @phba: Pointer to HBA context object. |
| 4949 | * |
| 4950 | * This function is called during the SLI initialization to configure |
| 4951 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4952 | * required to hold any locks. This function will return zero if successful |
| 4953 | * else it will return negative error code. |
| 4954 | **/ |
| 4955 | static int |
| 4956 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4957 | { |
| 4958 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4959 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4960 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4961 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4962 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4963 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4964 | return 0; |
| 4965 | } |
| 4966 | |
| 4967 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4968 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4969 | * @phba: Pointer to HBA context object. |
| 4970 | * @sli_mode: sli mode - 2/3 |
| 4971 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4972 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4973 | * to issue config_port mailbox command. This function restarts the |
| 4974 | * HBA firmware and issues a config_port mailbox command to configure |
| 4975 | * the SLI interface in the sli mode specified by sli_mode |
| 4976 | * variable. The caller is not required to hold any locks. |
| 4977 | * The function returns 0 if successful, else returns negative error |
| 4978 | * code. |
| 4979 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4980 | int |
| 4981 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4982 | { |
| 4983 | LPFC_MBOXQ_t *pmb; |
| 4984 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4985 | |
| 4986 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4987 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4988 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | return -ENOMEM; |
| 4990 | } |
| 4991 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4992 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4993 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4994 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4995 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4996 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4997 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4998 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4999 | rc = lpfc_sli_chipset_init(phba); |
| 5000 | if (rc) |
| 5001 | break; |
| 5002 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5003 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 5004 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5005 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5006 | resetcount++; |
| 5007 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5008 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 5009 | * value of 0 means the call was successful. Any other |
| 5010 | * nonzero value is a failure, but if ERESTART is returned, |
| 5011 | * the driver may reset the HBA and try again. |
| 5012 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5013 | rc = lpfc_config_port_prep(phba); |
| 5014 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5015 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5016 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5017 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5018 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5019 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5020 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5021 | lpfc_config_port(phba, pmb); |
| 5022 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5023 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 5024 | LPFC_SLI3_HBQ_ENABLED | |
| 5025 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5026 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5027 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5028 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5029 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5030 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5031 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5032 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5033 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5034 | spin_unlock_irq(&phba->hbalock); |
| 5035 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5036 | } else { |
| 5037 | /* Allow asynchronous mailbox command to go through */ |
| 5038 | spin_lock_irq(&phba->hbalock); |
| 5039 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 5040 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5041 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5042 | |
| 5043 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 5044 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 5045 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5046 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5047 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5048 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5049 | if (!done) { |
| 5050 | rc = -EINVAL; |
| 5051 | goto do_prep_failed; |
| 5052 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5053 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 5054 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5055 | rc = -ENXIO; |
| 5056 | goto do_prep_failed; |
| 5057 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5058 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5059 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5060 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5061 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5062 | phba->max_vpi : phba->max_vports; |
| 5063 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5064 | } else |
| 5065 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5066 | phba->fips_level = 0; |
| 5067 | phba->fips_spec_rev = 0; |
| 5068 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5069 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5070 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 5071 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 5072 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5073 | "2850 Security Crypto Active. FIPS x%d " |
| 5074 | "(Spec Rev: x%d)", |
| 5075 | phba->fips_level, phba->fips_spec_rev); |
| 5076 | } |
| 5077 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 5078 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5079 | "2856 Config Port Security Crypto " |
| 5080 | "Error: x%x ", |
| 5081 | pmb->u.mb.un.varCfgPort.sec_err); |
| 5082 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5083 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5084 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5085 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5086 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5087 | |
| 5088 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5089 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5090 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5091 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5092 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5093 | phba->cfg_enable_bg = 0; |
| 5094 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5095 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5096 | "0443 Adapter did not grant " |
| 5097 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5098 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5099 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5100 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5101 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5102 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5103 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5104 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5105 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5106 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5107 | return rc; |
| 5108 | } |
| 5109 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5110 | |
| 5111 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5112 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5113 | * @phba: Pointer to HBA context object. |
| 5114 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5115 | * This function is the main SLI initialization function. This function |
| 5116 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5117 | * error attention handler code. Caller is not required to hold any |
| 5118 | * locks. This function issues config_port mailbox command to configure |
| 5119 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5120 | * calls the config_port_post function to issue init_link mailbox |
| 5121 | * command and to start the discovery. The function will return zero |
| 5122 | * if successful, else it will return negative error code. |
| 5123 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5124 | int |
| 5125 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5126 | { |
| 5127 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5128 | int mode = 3, i; |
| 5129 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5130 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5131 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5132 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5133 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5135 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5136 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5137 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5138 | break; |
| 5139 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5140 | mode = 2; |
| 5141 | break; |
| 5142 | case 0: |
| 5143 | case 3: |
| 5144 | break; |
| 5145 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5146 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5147 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 5148 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5149 | |
| 5150 | break; |
| 5151 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5152 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5153 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5154 | rc = lpfc_sli_config_port(phba, mode); |
| 5155 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5156 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5158 | "1820 Unable to select SLI-3. " |
| 5159 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5160 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5161 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 5162 | else if (rc && mode == 2) |
| 5163 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5164 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | goto lpfc_sli_hba_setup_error; |
| 5166 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5167 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5168 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5169 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5170 | if (!rc) { |
| 5171 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5172 | "2709 This device supports " |
| 5173 | "Advanced Error Reporting (AER)\n"); |
| 5174 | spin_lock_irq(&phba->hbalock); |
| 5175 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5176 | spin_unlock_irq(&phba->hbalock); |
| 5177 | } else { |
| 5178 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5179 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5180 | "Advanced Error Reporting (AER): %d\n", |
| 5181 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5182 | phba->cfg_aer_support = 0; |
| 5183 | } |
| 5184 | } |
| 5185 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5186 | if (phba->sli_rev == 3) { |
| 5187 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5188 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5189 | } else { |
| 5190 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5191 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5192 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5196 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5197 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5198 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5199 | |
| 5200 | if (rc) |
| 5201 | goto lpfc_sli_hba_setup_error; |
| 5202 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5203 | /* Initialize VPIs. */ |
| 5204 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5205 | /* |
| 5206 | * The VPI bitmask and physical ID array are allocated |
| 5207 | * and initialized once only - at driver load. A port |
| 5208 | * reset doesn't need to reinitialize this memory. |
| 5209 | */ |
| 5210 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5211 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5212 | phba->vpi_bmask = kcalloc(longs, |
| 5213 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5214 | GFP_KERNEL); |
| 5215 | if (!phba->vpi_bmask) { |
| 5216 | rc = -ENOMEM; |
| 5217 | goto lpfc_sli_hba_setup_error; |
| 5218 | } |
| 5219 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5220 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5221 | sizeof(uint16_t), |
| 5222 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5223 | if (!phba->vpi_ids) { |
| 5224 | kfree(phba->vpi_bmask); |
| 5225 | rc = -ENOMEM; |
| 5226 | goto lpfc_sli_hba_setup_error; |
| 5227 | } |
| 5228 | for (i = 0; i < phba->max_vpi; i++) |
| 5229 | phba->vpi_ids[i] = i; |
| 5230 | } |
| 5231 | } |
| 5232 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5233 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5234 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5235 | rc = lpfc_sli_hbq_setup(phba); |
| 5236 | if (rc) |
| 5237 | goto lpfc_sli_hba_setup_error; |
| 5238 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5239 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5240 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5241 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | |
| 5243 | rc = lpfc_config_port_post(phba); |
| 5244 | if (rc) |
| 5245 | goto lpfc_sli_hba_setup_error; |
| 5246 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5247 | return rc; |
| 5248 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5249 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5250 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 5251 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5252 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5253 | return rc; |
| 5254 | } |
| 5255 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5256 | /** |
| 5257 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5258 | * @phba: Pointer to HBA context object. |
| 5259 | * @mboxq: mailbox pointer. |
| 5260 | * This function issue a dump mailbox command to read config region |
| 5261 | * 23 and parse the records in the region and populate driver |
| 5262 | * data structure. |
| 5263 | **/ |
| 5264 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5265 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5266 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5267 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5268 | struct lpfc_dmabuf *mp; |
| 5269 | struct lpfc_mqe *mqe; |
| 5270 | uint32_t data_length; |
| 5271 | int rc; |
| 5272 | |
| 5273 | /* Program the default value of vlan_id and fc_map */ |
| 5274 | phba->valid_vlan = 0; |
| 5275 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5276 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5277 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5278 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5279 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5280 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5281 | return -ENOMEM; |
| 5282 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5283 | mqe = &mboxq->u.mqe; |
| 5284 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5285 | rc = -ENOMEM; |
| 5286 | goto out_free_mboxq; |
| 5287 | } |
| 5288 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5289 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5290 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5291 | |
| 5292 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5293 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5294 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5295 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5296 | "CQ: x%x x%x x%x x%x\n", |
| 5297 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5298 | bf_get(lpfc_mqe_command, mqe), |
| 5299 | bf_get(lpfc_mqe_status, mqe), |
| 5300 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5301 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5302 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5303 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5304 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5305 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5306 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5307 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5308 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5309 | mboxq->mcqe.word0, |
| 5310 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5311 | mboxq->mcqe.trailer); |
| 5312 | |
| 5313 | if (rc) { |
| 5314 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5315 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5316 | rc = -EIO; |
| 5317 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5318 | } |
| 5319 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5320 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5321 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5322 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5323 | rc = -EIO; |
| 5324 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5325 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5326 | |
| 5327 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5328 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5329 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5330 | rc = 0; |
| 5331 | |
| 5332 | out_free_mboxq: |
| 5333 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5334 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | /** |
| 5338 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5339 | * @phba: pointer to lpfc hba data structure. |
| 5340 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5341 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5342 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5343 | * On output, the number of data bytes in @vpd. |
| 5344 | * |
| 5345 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5346 | * addition, this routine gets the port vpd data. |
| 5347 | * |
| 5348 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5349 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5350 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5351 | **/ |
| 5352 | static int |
| 5353 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5354 | uint8_t *vpd, uint32_t *vpd_size) |
| 5355 | { |
| 5356 | int rc = 0; |
| 5357 | uint32_t dma_size; |
| 5358 | struct lpfc_dmabuf *dmabuf; |
| 5359 | struct lpfc_mqe *mqe; |
| 5360 | |
| 5361 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5362 | if (!dmabuf) |
| 5363 | return -ENOMEM; |
| 5364 | |
| 5365 | /* |
| 5366 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5367 | * mailbox command. |
| 5368 | */ |
| 5369 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 5370 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 5371 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5372 | if (!dmabuf->virt) { |
| 5373 | kfree(dmabuf); |
| 5374 | return -ENOMEM; |
| 5375 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5376 | |
| 5377 | /* |
| 5378 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5379 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5380 | * in SLI3. This code corrects the conflicts. |
| 5381 | */ |
| 5382 | lpfc_read_rev(phba, mboxq); |
| 5383 | mqe = &mboxq->u.mqe; |
| 5384 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5385 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5386 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5387 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5388 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5389 | |
| 5390 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5391 | if (rc) { |
| 5392 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5393 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5394 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5395 | return -EIO; |
| 5396 | } |
| 5397 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5398 | /* |
| 5399 | * The available vpd length cannot be bigger than the |
| 5400 | * DMA buffer passed to the port. Catch the less than |
| 5401 | * case and update the caller's size. |
| 5402 | */ |
| 5403 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5404 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5405 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5406 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5407 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5408 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5409 | dmabuf->virt, dmabuf->phys); |
| 5410 | kfree(dmabuf); |
| 5411 | return 0; |
| 5412 | } |
| 5413 | |
| 5414 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5415 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5416 | * @phba: pointer to lpfc hba data structure. |
| 5417 | * |
| 5418 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5419 | * is attached to. |
| 5420 | * |
| 5421 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5422 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5423 | * otherwise - failed to retrieve physical port name |
| 5424 | **/ |
| 5425 | static int |
| 5426 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5427 | { |
| 5428 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5429 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5430 | struct lpfc_controller_attribute *cntl_attr; |
| 5431 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5432 | void *virtaddr = NULL; |
| 5433 | uint32_t alloclen, reqlen; |
| 5434 | uint32_t shdr_status, shdr_add_status; |
| 5435 | union lpfc_sli4_cfg_shdr *shdr; |
| 5436 | char cport_name = 0; |
| 5437 | int rc; |
| 5438 | |
| 5439 | /* We assume nothing at this point */ |
| 5440 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5441 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5442 | |
| 5443 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5444 | if (!mboxq) |
| 5445 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5446 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5447 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5448 | lpfc_sli4_read_config(phba); |
| 5449 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5450 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5451 | |
| 5452 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5453 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5454 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5455 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5456 | LPFC_SLI4_MBX_NEMBED); |
| 5457 | if (alloclen < reqlen) { |
| 5458 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5459 | "3084 Allocated DMA memory size (%d) is " |
| 5460 | "less than the requested DMA memory size " |
| 5461 | "(%d)\n", alloclen, reqlen); |
| 5462 | rc = -ENOMEM; |
| 5463 | goto out_free_mboxq; |
| 5464 | } |
| 5465 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5466 | virtaddr = mboxq->sge_array->addr[0]; |
| 5467 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5468 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5469 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5470 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5471 | if (shdr_status || shdr_add_status || rc) { |
| 5472 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5473 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5474 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5475 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5476 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5477 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5478 | rc, shdr_status, shdr_add_status); |
| 5479 | rc = -ENXIO; |
| 5480 | goto out_free_mboxq; |
| 5481 | } |
| 5482 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5483 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5484 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5485 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5486 | phba->sli4_hba.lnk_info.lnk_no = |
| 5487 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5488 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5489 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5490 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5491 | phba->sli4_hba.lnk_info.lnk_no); |
| 5492 | |
| 5493 | retrieve_ppname: |
| 5494 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5495 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5496 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5497 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5498 | LPFC_SLI4_MBX_EMBED); |
| 5499 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5500 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5501 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5502 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5503 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5504 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5505 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5506 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5507 | if (shdr_status || shdr_add_status || rc) { |
| 5508 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5509 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5510 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5511 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5512 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5513 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5514 | rc, shdr_status, shdr_add_status); |
| 5515 | rc = -ENXIO; |
| 5516 | goto out_free_mboxq; |
| 5517 | } |
| 5518 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5519 | case LPFC_LINK_NUMBER_0: |
| 5520 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5521 | &get_port_name->u.response); |
| 5522 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5523 | break; |
| 5524 | case LPFC_LINK_NUMBER_1: |
| 5525 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5526 | &get_port_name->u.response); |
| 5527 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5528 | break; |
| 5529 | case LPFC_LINK_NUMBER_2: |
| 5530 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5531 | &get_port_name->u.response); |
| 5532 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5533 | break; |
| 5534 | case LPFC_LINK_NUMBER_3: |
| 5535 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5536 | &get_port_name->u.response); |
| 5537 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5538 | break; |
| 5539 | default: |
| 5540 | break; |
| 5541 | } |
| 5542 | |
| 5543 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5544 | phba->Port[0] = cport_name; |
| 5545 | phba->Port[1] = '\0'; |
| 5546 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5547 | "3091 SLI get port name: %s\n", phba->Port); |
| 5548 | } |
| 5549 | |
| 5550 | out_free_mboxq: |
| 5551 | if (rc != MBX_TIMEOUT) { |
| 5552 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5553 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5554 | else |
| 5555 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5556 | } |
| 5557 | return rc; |
| 5558 | } |
| 5559 | |
| 5560 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5561 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5562 | * @phba: pointer to lpfc hba data structure. |
| 5563 | * |
| 5564 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5565 | * event queues |
| 5566 | **/ |
| 5567 | static void |
| 5568 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5569 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5570 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5571 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5572 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5573 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5574 | sli4_hba->sli4_cq_release(sli4_hba->mbx_cq, LPFC_QUEUE_REARM); |
| 5575 | sli4_hba->sli4_cq_release(sli4_hba->els_cq, LPFC_QUEUE_REARM); |
| 5576 | if (sli4_hba->nvmels_cq) |
| 5577 | sli4_hba->sli4_cq_release(sli4_hba->nvmels_cq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5578 | LPFC_QUEUE_REARM); |
| 5579 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5580 | qp = sli4_hba->hdwq; |
| 5581 | if (sli4_hba->hdwq) { |
| 5582 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
| 5583 | sli4_hba->sli4_cq_release(qp[qidx].fcp_cq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5584 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5585 | sli4_hba->sli4_cq_release(qp[qidx].nvme_cq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5586 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5587 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5588 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 5589 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5590 | sli4_hba->sli4_eq_release(qp[qidx].hba_eq, |
| 5591 | LPFC_QUEUE_REARM); |
| 5592 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5593 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5594 | if (phba->nvmet_support) { |
| 5595 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5596 | sli4_hba->sli4_cq_release( |
| 5597 | sli4_hba->nvmet_cqset[qidx], |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5598 | LPFC_QUEUE_REARM); |
| 5599 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5600 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5604 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5605 | * @phba: Pointer to HBA context object. |
| 5606 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5607 | * @extnt_count: buffer to hold port available extent count. |
| 5608 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5609 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5610 | * This function calls the port and retrievs the number of available |
| 5611 | * extents and their size for a particular extent type. |
| 5612 | * |
| 5613 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5614 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5615 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5616 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5617 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5618 | { |
| 5619 | int rc = 0; |
| 5620 | uint32_t length; |
| 5621 | uint32_t mbox_tmo; |
| 5622 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5623 | LPFC_MBOXQ_t *mbox; |
| 5624 | |
| 5625 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5626 | if (!mbox) |
| 5627 | return -ENOMEM; |
| 5628 | |
| 5629 | /* Find out how many extents are available for this resource type */ |
| 5630 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5631 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5632 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5633 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5634 | length, LPFC_SLI4_MBX_EMBED); |
| 5635 | |
| 5636 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5637 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5638 | LPFC_SLI4_MBX_EMBED); |
| 5639 | if (unlikely(rc)) { |
| 5640 | rc = -EIO; |
| 5641 | goto err_exit; |
| 5642 | } |
| 5643 | |
| 5644 | if (!phba->sli4_hba.intr_enable) |
| 5645 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5646 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5647 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5648 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5649 | } |
| 5650 | if (unlikely(rc)) { |
| 5651 | rc = -EIO; |
| 5652 | goto err_exit; |
| 5653 | } |
| 5654 | |
| 5655 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5656 | if (bf_get(lpfc_mbox_hdr_status, |
| 5657 | &rsrc_info->header.cfg_shdr.response)) { |
| 5658 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5659 | "2930 Failed to get resource extents " |
| 5660 | "Status 0x%x Add'l Status 0x%x\n", |
| 5661 | bf_get(lpfc_mbox_hdr_status, |
| 5662 | &rsrc_info->header.cfg_shdr.response), |
| 5663 | bf_get(lpfc_mbox_hdr_add_status, |
| 5664 | &rsrc_info->header.cfg_shdr.response)); |
| 5665 | rc = -EIO; |
| 5666 | goto err_exit; |
| 5667 | } |
| 5668 | |
| 5669 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5670 | &rsrc_info->u.rsp); |
| 5671 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5672 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5673 | |
| 5674 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5675 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5676 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5677 | |
| 5678 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5679 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5680 | return rc; |
| 5681 | } |
| 5682 | |
| 5683 | /** |
| 5684 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5685 | * @phba: Pointer to HBA context object. |
| 5686 | * @type: The extent type to check. |
| 5687 | * |
| 5688 | * This function reads the current available extents from the port and checks |
| 5689 | * if the extent count or extent size has changed since the last access. |
| 5690 | * Callers use this routine post port reset to understand if there is a |
| 5691 | * extent reprovisioning requirement. |
| 5692 | * |
| 5693 | * Returns: |
| 5694 | * -Error: error indicates problem. |
| 5695 | * 1: Extent count or size has changed. |
| 5696 | * 0: No changes. |
| 5697 | **/ |
| 5698 | static int |
| 5699 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5700 | { |
| 5701 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5702 | uint16_t size_diff, rsrc_ext_size; |
| 5703 | int rc = 0; |
| 5704 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5705 | struct list_head *rsrc_blk_list = NULL; |
| 5706 | |
| 5707 | size_diff = 0; |
| 5708 | curr_ext_cnt = 0; |
| 5709 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5710 | &rsrc_ext_cnt, |
| 5711 | &rsrc_ext_size); |
| 5712 | if (unlikely(rc)) |
| 5713 | return -EIO; |
| 5714 | |
| 5715 | switch (type) { |
| 5716 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5717 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5718 | break; |
| 5719 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5720 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5721 | break; |
| 5722 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5723 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5724 | break; |
| 5725 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5726 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5727 | break; |
| 5728 | default: |
| 5729 | break; |
| 5730 | } |
| 5731 | |
| 5732 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5733 | curr_ext_cnt++; |
| 5734 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5735 | size_diff++; |
| 5736 | } |
| 5737 | |
| 5738 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5739 | rc = 1; |
| 5740 | |
| 5741 | return rc; |
| 5742 | } |
| 5743 | |
| 5744 | /** |
| 5745 | * lpfc_sli4_cfg_post_extnts - |
| 5746 | * @phba: Pointer to HBA context object. |
| 5747 | * @extnt_cnt - number of available extents. |
| 5748 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5749 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5750 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5751 | * |
| 5752 | * This function executes the extents allocation request. It also |
| 5753 | * takes care of the amount of memory needed to allocate or get the |
| 5754 | * allocated extents. It is the caller's responsibility to evaluate |
| 5755 | * the response. |
| 5756 | * |
| 5757 | * Returns: |
| 5758 | * -Error: Error value describes the condition found. |
| 5759 | * 0: if successful |
| 5760 | **/ |
| 5761 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5762 | 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] | 5763 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5764 | { |
| 5765 | int rc = 0; |
| 5766 | uint32_t req_len; |
| 5767 | uint32_t emb_len; |
| 5768 | uint32_t alloc_len, mbox_tmo; |
| 5769 | |
| 5770 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5771 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5772 | |
| 5773 | /* |
| 5774 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5775 | * accounts for extents-specific word. |
| 5776 | */ |
| 5777 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5778 | sizeof(uint32_t); |
| 5779 | |
| 5780 | /* |
| 5781 | * Presume the allocation and response will fit into an embedded |
| 5782 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5783 | */ |
| 5784 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5785 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5786 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5787 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5788 | sizeof(uint32_t); |
| 5789 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5790 | } |
| 5791 | |
| 5792 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5793 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5794 | req_len, *emb); |
| 5795 | if (alloc_len < req_len) { |
| 5796 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5797 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5798 | "less than the requested DMA memory " |
| 5799 | "size (x%x)\n", alloc_len, req_len); |
| 5800 | return -ENOMEM; |
| 5801 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5802 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5803 | if (unlikely(rc)) |
| 5804 | return -EIO; |
| 5805 | |
| 5806 | if (!phba->sli4_hba.intr_enable) |
| 5807 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5808 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5809 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5810 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5811 | } |
| 5812 | |
| 5813 | if (unlikely(rc)) |
| 5814 | rc = -EIO; |
| 5815 | return rc; |
| 5816 | } |
| 5817 | |
| 5818 | /** |
| 5819 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5820 | * @phba: Pointer to HBA context object. |
| 5821 | * @type: The resource extent type to allocate. |
| 5822 | * |
| 5823 | * This function allocates the number of elements for the specified |
| 5824 | * resource type. |
| 5825 | **/ |
| 5826 | static int |
| 5827 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5828 | { |
| 5829 | bool emb = false; |
| 5830 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5831 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5832 | uint16_t *ids; |
| 5833 | int i, rc; |
| 5834 | unsigned long longs; |
| 5835 | unsigned long *bmask; |
| 5836 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5837 | LPFC_MBOXQ_t *mbox; |
| 5838 | uint32_t length; |
| 5839 | struct lpfc_id_range *id_array = NULL; |
| 5840 | void *virtaddr = NULL; |
| 5841 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5842 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5843 | struct list_head *ext_blk_list; |
| 5844 | |
| 5845 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5846 | &rsrc_cnt, |
| 5847 | &rsrc_size); |
| 5848 | if (unlikely(rc)) |
| 5849 | return -EIO; |
| 5850 | |
| 5851 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5852 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5853 | "3009 No available Resource Extents " |
| 5854 | "for resource type 0x%x: Count: 0x%x, " |
| 5855 | "Size 0x%x\n", type, rsrc_cnt, |
| 5856 | rsrc_size); |
| 5857 | return -ENOMEM; |
| 5858 | } |
| 5859 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5860 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5861 | "2903 Post resource extents type-0x%x: " |
| 5862 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5863 | |
| 5864 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5865 | if (!mbox) |
| 5866 | return -ENOMEM; |
| 5867 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5868 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5869 | if (unlikely(rc)) { |
| 5870 | rc = -EIO; |
| 5871 | goto err_exit; |
| 5872 | } |
| 5873 | |
| 5874 | /* |
| 5875 | * Figure out where the response is located. Then get local pointers |
| 5876 | * to the response data. The port does not guarantee to respond to |
| 5877 | * all extents counts request so update the local variable with the |
| 5878 | * allocated count from the port. |
| 5879 | */ |
| 5880 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5881 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5882 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5883 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5884 | } else { |
| 5885 | virtaddr = mbox->sge_array->addr[0]; |
| 5886 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5887 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5888 | id_array = &n_rsrc->id; |
| 5889 | } |
| 5890 | |
| 5891 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5892 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5893 | |
| 5894 | /* |
| 5895 | * Based on the resource size and count, correct the base and max |
| 5896 | * resource values. |
| 5897 | */ |
| 5898 | length = sizeof(struct lpfc_rsrc_blks); |
| 5899 | switch (type) { |
| 5900 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5901 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5902 | sizeof(unsigned long), |
| 5903 | GFP_KERNEL); |
| 5904 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5905 | rc = -ENOMEM; |
| 5906 | goto err_exit; |
| 5907 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5908 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5909 | sizeof(uint16_t), |
| 5910 | GFP_KERNEL); |
| 5911 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5912 | kfree(phba->sli4_hba.rpi_bmask); |
| 5913 | rc = -ENOMEM; |
| 5914 | goto err_exit; |
| 5915 | } |
| 5916 | |
| 5917 | /* |
| 5918 | * The next_rpi was initialized with the maximum available |
| 5919 | * count but the port may allocate a smaller number. Catch |
| 5920 | * that case and update the next_rpi. |
| 5921 | */ |
| 5922 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5923 | |
| 5924 | /* Initialize local ptrs for common extent processing later. */ |
| 5925 | bmask = phba->sli4_hba.rpi_bmask; |
| 5926 | ids = phba->sli4_hba.rpi_ids; |
| 5927 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5928 | break; |
| 5929 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5930 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5931 | GFP_KERNEL); |
| 5932 | if (unlikely(!phba->vpi_bmask)) { |
| 5933 | rc = -ENOMEM; |
| 5934 | goto err_exit; |
| 5935 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5936 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5937 | GFP_KERNEL); |
| 5938 | if (unlikely(!phba->vpi_ids)) { |
| 5939 | kfree(phba->vpi_bmask); |
| 5940 | rc = -ENOMEM; |
| 5941 | goto err_exit; |
| 5942 | } |
| 5943 | |
| 5944 | /* Initialize local ptrs for common extent processing later. */ |
| 5945 | bmask = phba->vpi_bmask; |
| 5946 | ids = phba->vpi_ids; |
| 5947 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5948 | break; |
| 5949 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5950 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5951 | sizeof(unsigned long), |
| 5952 | GFP_KERNEL); |
| 5953 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5954 | rc = -ENOMEM; |
| 5955 | goto err_exit; |
| 5956 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5957 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5958 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5959 | sizeof(uint16_t), |
| 5960 | GFP_KERNEL); |
| 5961 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5962 | kfree(phba->sli4_hba.xri_bmask); |
| 5963 | rc = -ENOMEM; |
| 5964 | goto err_exit; |
| 5965 | } |
| 5966 | |
| 5967 | /* Initialize local ptrs for common extent processing later. */ |
| 5968 | bmask = phba->sli4_hba.xri_bmask; |
| 5969 | ids = phba->sli4_hba.xri_ids; |
| 5970 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5971 | break; |
| 5972 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5973 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5974 | sizeof(unsigned long), |
| 5975 | GFP_KERNEL); |
| 5976 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5977 | rc = -ENOMEM; |
| 5978 | goto err_exit; |
| 5979 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5980 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5981 | sizeof(uint16_t), |
| 5982 | GFP_KERNEL); |
| 5983 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5984 | kfree(phba->sli4_hba.vfi_bmask); |
| 5985 | rc = -ENOMEM; |
| 5986 | goto err_exit; |
| 5987 | } |
| 5988 | |
| 5989 | /* Initialize local ptrs for common extent processing later. */ |
| 5990 | bmask = phba->sli4_hba.vfi_bmask; |
| 5991 | ids = phba->sli4_hba.vfi_ids; |
| 5992 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5993 | break; |
| 5994 | default: |
| 5995 | /* Unsupported Opcode. Fail call. */ |
| 5996 | id_array = NULL; |
| 5997 | bmask = NULL; |
| 5998 | ids = NULL; |
| 5999 | ext_blk_list = NULL; |
| 6000 | goto err_exit; |
| 6001 | } |
| 6002 | |
| 6003 | /* |
| 6004 | * Complete initializing the extent configuration with the |
| 6005 | * allocated ids assigned to this function. The bitmask serves |
| 6006 | * as an index into the array and manages the available ids. The |
| 6007 | * array just stores the ids communicated to the port via the wqes. |
| 6008 | */ |
| 6009 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 6010 | if ((i % 2) == 0) |
| 6011 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 6012 | &id_array[k]); |
| 6013 | else |
| 6014 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 6015 | &id_array[k]); |
| 6016 | |
| 6017 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 6018 | if (unlikely(!rsrc_blks)) { |
| 6019 | rc = -ENOMEM; |
| 6020 | kfree(bmask); |
| 6021 | kfree(ids); |
| 6022 | goto err_exit; |
| 6023 | } |
| 6024 | rsrc_blks->rsrc_start = rsrc_id; |
| 6025 | rsrc_blks->rsrc_size = rsrc_size; |
| 6026 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6027 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6028 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6029 | phba->sli4_hba.io_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6030 | lpfc_sli4_get_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6031 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6032 | |
| 6033 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6034 | ids[j] = rsrc_id; |
| 6035 | rsrc_id++; |
| 6036 | j++; |
| 6037 | } |
| 6038 | /* Entire word processed. Get next word.*/ |
| 6039 | if ((i % 2) == 1) |
| 6040 | k++; |
| 6041 | } |
| 6042 | err_exit: |
| 6043 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6044 | return rc; |
| 6045 | } |
| 6046 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6047 | |
| 6048 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6049 | /** |
| 6050 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6051 | * @phba: Pointer to HBA context object. |
| 6052 | * @type: the extent's type. |
| 6053 | * |
| 6054 | * This function deallocates all extents of a particular resource type. |
| 6055 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6056 | * is the caller's responsibility to release all kernel memory resources. |
| 6057 | **/ |
| 6058 | static int |
| 6059 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6060 | { |
| 6061 | int rc; |
| 6062 | uint32_t length, mbox_tmo = 0; |
| 6063 | LPFC_MBOXQ_t *mbox; |
| 6064 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6065 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6066 | |
| 6067 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6068 | if (!mbox) |
| 6069 | return -ENOMEM; |
| 6070 | |
| 6071 | /* |
| 6072 | * This function sends an embedded mailbox because it only sends the |
| 6073 | * the resource type. All extents of this type are released by the |
| 6074 | * port. |
| 6075 | */ |
| 6076 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6077 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6078 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6079 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6080 | length, LPFC_SLI4_MBX_EMBED); |
| 6081 | |
| 6082 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6083 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6084 | LPFC_SLI4_MBX_EMBED); |
| 6085 | if (unlikely(rc)) { |
| 6086 | rc = -EIO; |
| 6087 | goto out_free_mbox; |
| 6088 | } |
| 6089 | if (!phba->sli4_hba.intr_enable) |
| 6090 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6091 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6092 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6093 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6094 | } |
| 6095 | if (unlikely(rc)) { |
| 6096 | rc = -EIO; |
| 6097 | goto out_free_mbox; |
| 6098 | } |
| 6099 | |
| 6100 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6101 | if (bf_get(lpfc_mbox_hdr_status, |
| 6102 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 6103 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6104 | "2919 Failed to release resource extents " |
| 6105 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6106 | "Resource memory not released.\n", |
| 6107 | type, |
| 6108 | bf_get(lpfc_mbox_hdr_status, |
| 6109 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6110 | bf_get(lpfc_mbox_hdr_add_status, |
| 6111 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6112 | rc = -EIO; |
| 6113 | goto out_free_mbox; |
| 6114 | } |
| 6115 | |
| 6116 | /* Release kernel memory resources for the specific type. */ |
| 6117 | switch (type) { |
| 6118 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6119 | kfree(phba->vpi_bmask); |
| 6120 | kfree(phba->vpi_ids); |
| 6121 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6122 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6123 | &phba->lpfc_vpi_blk_list, list) { |
| 6124 | list_del_init(&rsrc_blk->list); |
| 6125 | kfree(rsrc_blk); |
| 6126 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6127 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6128 | break; |
| 6129 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6130 | kfree(phba->sli4_hba.xri_bmask); |
| 6131 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6132 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6133 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6134 | list_del_init(&rsrc_blk->list); |
| 6135 | kfree(rsrc_blk); |
| 6136 | } |
| 6137 | break; |
| 6138 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6139 | kfree(phba->sli4_hba.vfi_bmask); |
| 6140 | kfree(phba->sli4_hba.vfi_ids); |
| 6141 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6142 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6143 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6144 | list_del_init(&rsrc_blk->list); |
| 6145 | kfree(rsrc_blk); |
| 6146 | } |
| 6147 | break; |
| 6148 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6149 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6150 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6151 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6152 | list_del_init(&rsrc_blk->list); |
| 6153 | kfree(rsrc_blk); |
| 6154 | } |
| 6155 | break; |
| 6156 | default: |
| 6157 | break; |
| 6158 | } |
| 6159 | |
| 6160 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6161 | |
| 6162 | out_free_mbox: |
| 6163 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6164 | return rc; |
| 6165 | } |
| 6166 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6167 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6168 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6169 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6170 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6171 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6172 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6173 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6174 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6175 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6176 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6177 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6178 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6179 | switch (feature) { |
| 6180 | case LPFC_SET_UE_RECOVERY: |
| 6181 | bf_set(lpfc_mbx_set_feature_UER, |
| 6182 | &mbox->u.mqe.un.set_feature, 1); |
| 6183 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6184 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6185 | break; |
| 6186 | case LPFC_SET_MDS_DIAGS: |
| 6187 | bf_set(lpfc_mbx_set_feature_mds, |
| 6188 | &mbox->u.mqe.un.set_feature, 1); |
| 6189 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6190 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6191 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6192 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6193 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6194 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6195 | |
| 6196 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6197 | } |
| 6198 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6199 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6200 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6201 | * @phba: Pointer to HBA context object. |
| 6202 | * |
| 6203 | * Disable FW logging into host memory on the adapter. To |
| 6204 | * be done before reading logs from the host memory. |
| 6205 | **/ |
| 6206 | void |
| 6207 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6208 | { |
| 6209 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6210 | |
| 6211 | ras_fwlog->ras_active = false; |
| 6212 | |
| 6213 | /* Disable FW logging to host memory */ |
| 6214 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6215 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
| 6216 | } |
| 6217 | |
| 6218 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6219 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6220 | * @phba: Pointer to HBA context object. |
| 6221 | * |
| 6222 | * This function is called to free memory allocated for RAS FW logging |
| 6223 | * support in the driver. |
| 6224 | **/ |
| 6225 | void |
| 6226 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6227 | { |
| 6228 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6229 | struct lpfc_dmabuf *dmabuf, *next; |
| 6230 | |
| 6231 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6232 | list_for_each_entry_safe(dmabuf, next, |
| 6233 | &ras_fwlog->fwlog_buff_list, |
| 6234 | list) { |
| 6235 | list_del(&dmabuf->list); |
| 6236 | dma_free_coherent(&phba->pcidev->dev, |
| 6237 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6238 | dmabuf->virt, dmabuf->phys); |
| 6239 | kfree(dmabuf); |
| 6240 | } |
| 6241 | } |
| 6242 | |
| 6243 | if (ras_fwlog->lwpd.virt) { |
| 6244 | dma_free_coherent(&phba->pcidev->dev, |
| 6245 | sizeof(uint32_t) * 2, |
| 6246 | ras_fwlog->lwpd.virt, |
| 6247 | ras_fwlog->lwpd.phys); |
| 6248 | ras_fwlog->lwpd.virt = NULL; |
| 6249 | } |
| 6250 | |
| 6251 | ras_fwlog->ras_active = false; |
| 6252 | } |
| 6253 | |
| 6254 | /** |
| 6255 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6256 | * @phba: Pointer to HBA context object. |
| 6257 | * @fwlog_buff_count: Count of buffers to be created. |
| 6258 | * |
| 6259 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6260 | * to update FW log is posted to the adapter. |
| 6261 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6262 | * Size of each buffer posted to FW is 64K. |
| 6263 | **/ |
| 6264 | |
| 6265 | static int |
| 6266 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6267 | uint32_t fwlog_buff_count) |
| 6268 | { |
| 6269 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6270 | struct lpfc_dmabuf *dmabuf; |
| 6271 | int rc = 0, i = 0; |
| 6272 | |
| 6273 | /* Initialize List */ |
| 6274 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6275 | |
| 6276 | /* Allocate memory for the LWPD */ |
| 6277 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6278 | sizeof(uint32_t) * 2, |
| 6279 | &ras_fwlog->lwpd.phys, |
| 6280 | GFP_KERNEL); |
| 6281 | if (!ras_fwlog->lwpd.virt) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6282 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6283 | "6185 LWPD Memory Alloc Failed\n"); |
| 6284 | |
| 6285 | return -ENOMEM; |
| 6286 | } |
| 6287 | |
| 6288 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6289 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6290 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6291 | GFP_KERNEL); |
| 6292 | if (!dmabuf) { |
| 6293 | rc = -ENOMEM; |
| 6294 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6295 | "6186 Memory Alloc failed FW logging"); |
| 6296 | goto free_mem; |
| 6297 | } |
| 6298 | |
Sabyasachi Gupta | 359d0ac | 2018-11-18 20:08:48 +0530 | [diff] [blame] | 6299 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6300 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6301 | &dmabuf->phys, |
| 6302 | GFP_KERNEL); |
| 6303 | if (!dmabuf->virt) { |
| 6304 | kfree(dmabuf); |
| 6305 | rc = -ENOMEM; |
| 6306 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6307 | "6187 DMA Alloc Failed FW logging"); |
| 6308 | goto free_mem; |
| 6309 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6310 | dmabuf->buffer_tag = i; |
| 6311 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6312 | } |
| 6313 | |
| 6314 | free_mem: |
| 6315 | if (rc) |
| 6316 | lpfc_sli4_ras_dma_free(phba); |
| 6317 | |
| 6318 | return rc; |
| 6319 | } |
| 6320 | |
| 6321 | /** |
| 6322 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6323 | * @phba: pointer to lpfc hba data structure. |
| 6324 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 6325 | * |
| 6326 | * Completion handler for driver's RAS MBX command to the device. |
| 6327 | **/ |
| 6328 | static void |
| 6329 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6330 | { |
| 6331 | MAILBOX_t *mb; |
| 6332 | union lpfc_sli4_cfg_shdr *shdr; |
| 6333 | uint32_t shdr_status, shdr_add_status; |
| 6334 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6335 | |
| 6336 | mb = &pmb->u.mb; |
| 6337 | |
| 6338 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6339 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6340 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6341 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6342 | |
| 6343 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6344 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6345 | "6188 FW LOG mailbox " |
| 6346 | "completed with status x%x add_status x%x," |
| 6347 | " mbx status x%x\n", |
| 6348 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6349 | |
| 6350 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6351 | goto disable_ras; |
| 6352 | } |
| 6353 | |
| 6354 | ras_fwlog->ras_active = true; |
| 6355 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6356 | |
| 6357 | return; |
| 6358 | |
| 6359 | disable_ras: |
| 6360 | /* Free RAS DMA memory */ |
| 6361 | lpfc_sli4_ras_dma_free(phba); |
| 6362 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6363 | } |
| 6364 | |
| 6365 | /** |
| 6366 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6367 | * @phba: pointer to lpfc hba data structure. |
| 6368 | * @fwlog_level: Logging verbosity level. |
| 6369 | * @fwlog_enable: Enable/Disable logging. |
| 6370 | * |
| 6371 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6372 | * memory. |
| 6373 | **/ |
| 6374 | int |
| 6375 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6376 | uint32_t fwlog_level, |
| 6377 | uint32_t fwlog_enable) |
| 6378 | { |
| 6379 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6380 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6381 | struct lpfc_dmabuf *dmabuf; |
| 6382 | LPFC_MBOXQ_t *mbox; |
| 6383 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6384 | int rc = 0; |
| 6385 | |
| 6386 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6387 | phba->cfg_ras_fwlog_buffsize); |
| 6388 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6389 | |
| 6390 | /* |
| 6391 | * If re-enabling FW logging support use earlier allocated |
| 6392 | * DMA buffers while posting MBX command. |
| 6393 | **/ |
| 6394 | if (!ras_fwlog->lwpd.virt) { |
| 6395 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6396 | if (rc) { |
| 6397 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6398 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6399 | return rc; |
| 6400 | } |
| 6401 | } |
| 6402 | |
| 6403 | /* Setup Mailbox command */ |
| 6404 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6405 | if (!mbox) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6406 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6407 | "6190 RAS MBX Alloc Failed"); |
| 6408 | rc = -ENOMEM; |
| 6409 | goto mem_free; |
| 6410 | } |
| 6411 | |
| 6412 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6413 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6414 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6415 | |
| 6416 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6417 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6418 | len, LPFC_SLI4_MBX_EMBED); |
| 6419 | |
| 6420 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6421 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6422 | fwlog_enable); |
| 6423 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6424 | ras_fwlog->fw_loglevel); |
| 6425 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6426 | ras_fwlog->fw_buffcount); |
| 6427 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6428 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6429 | |
| 6430 | /* Update DMA buffer address */ |
| 6431 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6432 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6433 | |
| 6434 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6435 | putPaddrLow(dmabuf->phys); |
| 6436 | |
| 6437 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 6438 | putPaddrHigh(dmabuf->phys); |
| 6439 | } |
| 6440 | |
| 6441 | /* Update LPWD address */ |
| 6442 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 6443 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 6444 | |
| 6445 | mbox->vport = phba->pport; |
| 6446 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 6447 | |
| 6448 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6449 | |
| 6450 | if (rc == MBX_NOT_FINISHED) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6452 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6453 | "status %d mbxStatus : x%x", rc, |
| 6454 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 6455 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6456 | rc = -EIO; |
| 6457 | goto mem_free; |
| 6458 | } else |
| 6459 | rc = 0; |
| 6460 | mem_free: |
| 6461 | if (rc) |
| 6462 | lpfc_sli4_ras_dma_free(phba); |
| 6463 | |
| 6464 | return rc; |
| 6465 | } |
| 6466 | |
| 6467 | /** |
| 6468 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 6469 | * @phba: Pointer to HBA context object. |
| 6470 | * |
| 6471 | * Check if RAS is supported on the adapter and initialize it. |
| 6472 | **/ |
| 6473 | void |
| 6474 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 6475 | { |
| 6476 | /* Check RAS FW Log needs to be enabled or not */ |
| 6477 | if (lpfc_check_fwlog_support(phba)) |
| 6478 | return; |
| 6479 | |
| 6480 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 6481 | LPFC_RAS_ENABLE_LOGGING); |
| 6482 | } |
| 6483 | |
| 6484 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6485 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6486 | * @phba: Pointer to HBA context object. |
| 6487 | * |
| 6488 | * This function allocates all SLI4 resource identifiers. |
| 6489 | **/ |
| 6490 | int |
| 6491 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6492 | { |
| 6493 | int i, rc, error = 0; |
| 6494 | uint16_t count, base; |
| 6495 | unsigned long longs; |
| 6496 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6497 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6498 | 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] | 6499 | if (phba->sli4_hba.extents_in_use) { |
| 6500 | /* |
| 6501 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6502 | * resource extent count must be read and allocated before |
| 6503 | * provisioning the resource id arrays. |
| 6504 | */ |
| 6505 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6506 | LPFC_IDX_RSRC_RDY) { |
| 6507 | /* |
| 6508 | * Extent-based resources are set - the driver could |
| 6509 | * be in a port reset. Figure out if any corrective |
| 6510 | * actions need to be taken. |
| 6511 | */ |
| 6512 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6513 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6514 | if (rc != 0) |
| 6515 | error++; |
| 6516 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6517 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6518 | if (rc != 0) |
| 6519 | error++; |
| 6520 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6521 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6522 | if (rc != 0) |
| 6523 | error++; |
| 6524 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6525 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6526 | if (rc != 0) |
| 6527 | error++; |
| 6528 | |
| 6529 | /* |
| 6530 | * It's possible that the number of resources |
| 6531 | * provided to this port instance changed between |
| 6532 | * resets. Detect this condition and reallocate |
| 6533 | * resources. Otherwise, there is no action. |
| 6534 | */ |
| 6535 | if (error) { |
| 6536 | lpfc_printf_log(phba, KERN_INFO, |
| 6537 | LOG_MBOX | LOG_INIT, |
| 6538 | "2931 Detected extent resource " |
| 6539 | "change. Reallocating all " |
| 6540 | "extents.\n"); |
| 6541 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6542 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6543 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6544 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6545 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6546 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6547 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6548 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6549 | } else |
| 6550 | return 0; |
| 6551 | } |
| 6552 | |
| 6553 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6554 | if (unlikely(rc)) |
| 6555 | goto err_exit; |
| 6556 | |
| 6557 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6558 | if (unlikely(rc)) |
| 6559 | goto err_exit; |
| 6560 | |
| 6561 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6562 | if (unlikely(rc)) |
| 6563 | goto err_exit; |
| 6564 | |
| 6565 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6566 | if (unlikely(rc)) |
| 6567 | goto err_exit; |
| 6568 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6569 | LPFC_IDX_RSRC_RDY); |
| 6570 | return rc; |
| 6571 | } else { |
| 6572 | /* |
| 6573 | * The port does not support resource extents. The XRI, VPI, |
| 6574 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6575 | * Just allocate the bitmasks and provision the resource id |
| 6576 | * arrays. If a port reset is active, the resources don't |
| 6577 | * need any action - just exit. |
| 6578 | */ |
| 6579 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6580 | LPFC_IDX_RSRC_RDY) { |
| 6581 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6582 | lpfc_sli4_remove_rpis(phba); |
| 6583 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6584 | /* RPIs. */ |
| 6585 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6586 | if (count <= 0) { |
| 6587 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6588 | "3279 Invalid provisioning of " |
| 6589 | "rpi:%d\n", count); |
| 6590 | rc = -EINVAL; |
| 6591 | goto err_exit; |
| 6592 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6593 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6594 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6595 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6596 | sizeof(unsigned long), |
| 6597 | GFP_KERNEL); |
| 6598 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6599 | rc = -ENOMEM; |
| 6600 | goto err_exit; |
| 6601 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6602 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6603 | GFP_KERNEL); |
| 6604 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6605 | rc = -ENOMEM; |
| 6606 | goto free_rpi_bmask; |
| 6607 | } |
| 6608 | |
| 6609 | for (i = 0; i < count; i++) |
| 6610 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6611 | |
| 6612 | /* VPIs. */ |
| 6613 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6614 | if (count <= 0) { |
| 6615 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6616 | "3280 Invalid provisioning of " |
| 6617 | "vpi:%d\n", count); |
| 6618 | rc = -EINVAL; |
| 6619 | goto free_rpi_ids; |
| 6620 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6621 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6622 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6623 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6624 | GFP_KERNEL); |
| 6625 | if (unlikely(!phba->vpi_bmask)) { |
| 6626 | rc = -ENOMEM; |
| 6627 | goto free_rpi_ids; |
| 6628 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6629 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6630 | GFP_KERNEL); |
| 6631 | if (unlikely(!phba->vpi_ids)) { |
| 6632 | rc = -ENOMEM; |
| 6633 | goto free_vpi_bmask; |
| 6634 | } |
| 6635 | |
| 6636 | for (i = 0; i < count; i++) |
| 6637 | phba->vpi_ids[i] = base + i; |
| 6638 | |
| 6639 | /* XRIs. */ |
| 6640 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6641 | if (count <= 0) { |
| 6642 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6643 | "3281 Invalid provisioning of " |
| 6644 | "xri:%d\n", count); |
| 6645 | rc = -EINVAL; |
| 6646 | goto free_vpi_ids; |
| 6647 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6648 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6649 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6650 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6651 | sizeof(unsigned long), |
| 6652 | GFP_KERNEL); |
| 6653 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6654 | rc = -ENOMEM; |
| 6655 | goto free_vpi_ids; |
| 6656 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6657 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6658 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6659 | GFP_KERNEL); |
| 6660 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6661 | rc = -ENOMEM; |
| 6662 | goto free_xri_bmask; |
| 6663 | } |
| 6664 | |
| 6665 | for (i = 0; i < count; i++) |
| 6666 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6667 | |
| 6668 | /* VFIs. */ |
| 6669 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6670 | if (count <= 0) { |
| 6671 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6672 | "3282 Invalid provisioning of " |
| 6673 | "vfi:%d\n", count); |
| 6674 | rc = -EINVAL; |
| 6675 | goto free_xri_ids; |
| 6676 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6677 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6678 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6679 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6680 | sizeof(unsigned long), |
| 6681 | GFP_KERNEL); |
| 6682 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6683 | rc = -ENOMEM; |
| 6684 | goto free_xri_ids; |
| 6685 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6686 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6687 | GFP_KERNEL); |
| 6688 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6689 | rc = -ENOMEM; |
| 6690 | goto free_vfi_bmask; |
| 6691 | } |
| 6692 | |
| 6693 | for (i = 0; i < count; i++) |
| 6694 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6695 | |
| 6696 | /* |
| 6697 | * Mark all resources ready. An HBA reset doesn't need |
| 6698 | * to reset the initialization. |
| 6699 | */ |
| 6700 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6701 | LPFC_IDX_RSRC_RDY); |
| 6702 | return 0; |
| 6703 | } |
| 6704 | |
| 6705 | free_vfi_bmask: |
| 6706 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6707 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6708 | free_xri_ids: |
| 6709 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6710 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6711 | free_xri_bmask: |
| 6712 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6713 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6714 | free_vpi_ids: |
| 6715 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6716 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6717 | free_vpi_bmask: |
| 6718 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6719 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6720 | free_rpi_ids: |
| 6721 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6722 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6723 | free_rpi_bmask: |
| 6724 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6725 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6726 | err_exit: |
| 6727 | return rc; |
| 6728 | } |
| 6729 | |
| 6730 | /** |
| 6731 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6732 | * @phba: Pointer to HBA context object. |
| 6733 | * |
| 6734 | * This function allocates the number of elements for the specified |
| 6735 | * resource type. |
| 6736 | **/ |
| 6737 | int |
| 6738 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6739 | { |
| 6740 | if (phba->sli4_hba.extents_in_use) { |
| 6741 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6742 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6743 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6744 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6745 | } else { |
| 6746 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6747 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6748 | kfree(phba->vpi_ids); |
| 6749 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6750 | kfree(phba->sli4_hba.xri_bmask); |
| 6751 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6752 | kfree(phba->sli4_hba.vfi_bmask); |
| 6753 | kfree(phba->sli4_hba.vfi_ids); |
| 6754 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6755 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6756 | } |
| 6757 | |
| 6758 | return 0; |
| 6759 | } |
| 6760 | |
| 6761 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6762 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6763 | * @phba: Pointer to HBA context object. |
| 6764 | * @type: The resource extent type. |
| 6765 | * @extnt_count: buffer to hold port extent count response |
| 6766 | * @extnt_size: buffer to hold port extent size response. |
| 6767 | * |
| 6768 | * This function calls the port to read the host allocated extents |
| 6769 | * for a particular type. |
| 6770 | **/ |
| 6771 | int |
| 6772 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6773 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6774 | { |
| 6775 | bool emb; |
| 6776 | int rc = 0; |
| 6777 | uint16_t curr_blks = 0; |
| 6778 | uint32_t req_len, emb_len; |
| 6779 | uint32_t alloc_len, mbox_tmo; |
| 6780 | struct list_head *blk_list_head; |
| 6781 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6782 | LPFC_MBOXQ_t *mbox; |
| 6783 | void *virtaddr = NULL; |
| 6784 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6785 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6786 | union lpfc_sli4_cfg_shdr *shdr; |
| 6787 | |
| 6788 | switch (type) { |
| 6789 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6790 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6791 | break; |
| 6792 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6793 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6794 | break; |
| 6795 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6796 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6797 | break; |
| 6798 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6799 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6800 | break; |
| 6801 | default: |
| 6802 | return -EIO; |
| 6803 | } |
| 6804 | |
| 6805 | /* Count the number of extents currently allocatd for this type. */ |
| 6806 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6807 | if (curr_blks == 0) { |
| 6808 | /* |
| 6809 | * The GET_ALLOCATED mailbox does not return the size, |
| 6810 | * just the count. The size should be just the size |
| 6811 | * stored in the current allocated block and all sizes |
| 6812 | * for an extent type are the same so set the return |
| 6813 | * value now. |
| 6814 | */ |
| 6815 | *extnt_size = rsrc_blk->rsrc_size; |
| 6816 | } |
| 6817 | curr_blks++; |
| 6818 | } |
| 6819 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6820 | /* |
| 6821 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6822 | * accounts for extents-specific word. |
| 6823 | */ |
| 6824 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6825 | sizeof(uint32_t); |
| 6826 | |
| 6827 | /* |
| 6828 | * Presume the allocation and response will fit into an embedded |
| 6829 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6830 | */ |
| 6831 | emb = LPFC_SLI4_MBX_EMBED; |
| 6832 | req_len = emb_len; |
| 6833 | if (req_len > emb_len) { |
| 6834 | req_len = curr_blks * sizeof(uint16_t) + |
| 6835 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6836 | sizeof(uint32_t); |
| 6837 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6838 | } |
| 6839 | |
| 6840 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6841 | if (!mbox) |
| 6842 | return -ENOMEM; |
| 6843 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6844 | |
| 6845 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6846 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6847 | req_len, emb); |
| 6848 | if (alloc_len < req_len) { |
| 6849 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6850 | "2983 Allocated DMA memory size (x%x) is " |
| 6851 | "less than the requested DMA memory " |
| 6852 | "size (x%x)\n", alloc_len, req_len); |
| 6853 | rc = -ENOMEM; |
| 6854 | goto err_exit; |
| 6855 | } |
| 6856 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6857 | if (unlikely(rc)) { |
| 6858 | rc = -EIO; |
| 6859 | goto err_exit; |
| 6860 | } |
| 6861 | |
| 6862 | if (!phba->sli4_hba.intr_enable) |
| 6863 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6864 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6865 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6866 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6867 | } |
| 6868 | |
| 6869 | if (unlikely(rc)) { |
| 6870 | rc = -EIO; |
| 6871 | goto err_exit; |
| 6872 | } |
| 6873 | |
| 6874 | /* |
| 6875 | * Figure out where the response is located. Then get local pointers |
| 6876 | * to the response data. The port does not guarantee to respond to |
| 6877 | * all extents counts request so update the local variable with the |
| 6878 | * allocated count from the port. |
| 6879 | */ |
| 6880 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6881 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6882 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6883 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6884 | } else { |
| 6885 | virtaddr = mbox->sge_array->addr[0]; |
| 6886 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6887 | shdr = &n_rsrc->cfg_shdr; |
| 6888 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6889 | } |
| 6890 | |
| 6891 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6892 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6893 | "2984 Failed to read allocated resources " |
| 6894 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6895 | type, |
| 6896 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6897 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6898 | rc = -EIO; |
| 6899 | goto err_exit; |
| 6900 | } |
| 6901 | err_exit: |
| 6902 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6903 | return rc; |
| 6904 | } |
| 6905 | |
| 6906 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6907 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6908 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6909 | * @pring: Pointer to driver SLI ring object. |
| 6910 | * @sgl_list: linked link of sgl buffers to post |
| 6911 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6912 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6913 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6914 | * repost them to the port by using SGL block post. This is needed after a |
| 6915 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6916 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6917 | * 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] | 6918 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6919 | * mailbox command for posting. |
| 6920 | * |
| 6921 | * Returns: 0 = success, non-zero failure. |
| 6922 | **/ |
| 6923 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6924 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6925 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6926 | { |
| 6927 | struct lpfc_sglq *sglq_entry = NULL; |
| 6928 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6929 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6930 | int status, total_cnt; |
| 6931 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6932 | int last_xritag = NO_XRI; |
| 6933 | LIST_HEAD(prep_sgl_list); |
| 6934 | LIST_HEAD(blck_sgl_list); |
| 6935 | LIST_HEAD(allc_sgl_list); |
| 6936 | LIST_HEAD(post_sgl_list); |
| 6937 | LIST_HEAD(free_sgl_list); |
| 6938 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6939 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6940 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6941 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6942 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6943 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6944 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6945 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6946 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6947 | &allc_sgl_list, list) { |
| 6948 | list_del_init(&sglq_entry->list); |
| 6949 | block_cnt++; |
| 6950 | if ((last_xritag != NO_XRI) && |
| 6951 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6952 | /* a hole in xri block, form a sgl posting block */ |
| 6953 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6954 | post_cnt = block_cnt - 1; |
| 6955 | /* prepare list for next posting block */ |
| 6956 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6957 | block_cnt = 1; |
| 6958 | } else { |
| 6959 | /* prepare list for next posting block */ |
| 6960 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6961 | /* enough sgls for non-embed sgl mbox command */ |
| 6962 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6963 | list_splice_init(&prep_sgl_list, |
| 6964 | &blck_sgl_list); |
| 6965 | post_cnt = block_cnt; |
| 6966 | block_cnt = 0; |
| 6967 | } |
| 6968 | } |
| 6969 | num_posted++; |
| 6970 | |
| 6971 | /* keep track of last sgl's xritag */ |
| 6972 | last_xritag = sglq_entry->sli4_xritag; |
| 6973 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6974 | /* end of repost sgl list condition for buffers */ |
| 6975 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6976 | if (post_cnt == 0) { |
| 6977 | list_splice_init(&prep_sgl_list, |
| 6978 | &blck_sgl_list); |
| 6979 | post_cnt = block_cnt; |
| 6980 | } else if (block_cnt == 1) { |
| 6981 | status = lpfc_sli4_post_sgl(phba, |
| 6982 | sglq_entry->phys, 0, |
| 6983 | sglq_entry->sli4_xritag); |
| 6984 | if (!status) { |
| 6985 | /* successful, put sgl to posted list */ |
| 6986 | list_add_tail(&sglq_entry->list, |
| 6987 | &post_sgl_list); |
| 6988 | } else { |
| 6989 | /* Failure, put sgl to free list */ |
| 6990 | lpfc_printf_log(phba, KERN_WARNING, |
| 6991 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6992 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6993 | "sgl, xritag:x%x\n", |
| 6994 | sglq_entry->sli4_xritag); |
| 6995 | list_add_tail(&sglq_entry->list, |
| 6996 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6997 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6998 | } |
| 6999 | } |
| 7000 | } |
| 7001 | |
| 7002 | /* continue until a nembed page worth of sgls */ |
| 7003 | if (post_cnt == 0) |
| 7004 | continue; |
| 7005 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7006 | /* post the buffer list sgls as a block */ |
| 7007 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 7008 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7009 | |
| 7010 | if (!status) { |
| 7011 | /* success, put sgl list to posted sgl list */ |
| 7012 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 7013 | } else { |
| 7014 | /* Failure, put sgl list to free sgl list */ |
| 7015 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 7016 | struct lpfc_sglq, |
| 7017 | list); |
| 7018 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7019 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7020 | "xritag:x%x-x%x\n", |
| 7021 | sglq_entry_first->sli4_xritag, |
| 7022 | (sglq_entry_first->sli4_xritag + |
| 7023 | post_cnt - 1)); |
| 7024 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7025 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7026 | } |
| 7027 | |
| 7028 | /* don't reset xirtag due to hole in xri block */ |
| 7029 | if (block_cnt == 0) |
| 7030 | last_xritag = NO_XRI; |
| 7031 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7032 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7033 | post_cnt = 0; |
| 7034 | } |
| 7035 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7036 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7037 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7038 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7039 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7040 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7041 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7042 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7043 | list_splice_init(&post_sgl_list, sgl_list); |
| 7044 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7045 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7046 | } else { |
| 7047 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7048 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7049 | return -EIO; |
| 7050 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7051 | |
| 7052 | /* return the number of XRIs actually posted */ |
| 7053 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7054 | } |
| 7055 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7056 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7057 | * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7058 | * @phba: pointer to lpfc hba data structure. |
| 7059 | * |
| 7060 | * This routine walks the list of nvme buffers that have been allocated and |
| 7061 | * repost them to the port by using SGL block post. This is needed after a |
| 7062 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 7063 | * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7064 | * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7065 | * |
| 7066 | * Returns: 0 = success, non-zero failure. |
| 7067 | **/ |
| 7068 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7069 | lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7070 | { |
| 7071 | LIST_HEAD(post_nblist); |
| 7072 | int num_posted, rc = 0; |
| 7073 | |
| 7074 | /* get all NVME buffers need to repost to a local list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7075 | lpfc_io_buf_flush(phba, &post_nblist); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7076 | |
| 7077 | /* post the list of nvme buffer sgls to port if available */ |
| 7078 | if (!list_empty(&post_nblist)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7079 | num_posted = lpfc_sli4_post_io_sgl_list( |
| 7080 | phba, &post_nblist, phba->sli4_hba.io_xri_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7081 | /* failed to post any nvme buffer, return error */ |
| 7082 | if (num_posted == 0) |
| 7083 | rc = -EIO; |
| 7084 | } |
| 7085 | return rc; |
| 7086 | } |
| 7087 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7088 | void |
| 7089 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7090 | { |
| 7091 | uint32_t len; |
| 7092 | |
| 7093 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7094 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7095 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7096 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7097 | LPFC_SLI4_MBX_EMBED); |
| 7098 | |
| 7099 | 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] | 7100 | mbox->u.mqe.un.set_host_data.param_len = |
| 7101 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7102 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 7103 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7104 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7105 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7106 | } |
| 7107 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7108 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7109 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7110 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7111 | { |
| 7112 | int rc, i; |
| 7113 | struct lpfc_rqe hrqe; |
| 7114 | struct lpfc_rqe drqe; |
| 7115 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7116 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7117 | struct rqb_dmabuf *rqb_buffer; |
| 7118 | LIST_HEAD(rqb_buf_list); |
| 7119 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7120 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7121 | rqbp = hrq->rqbp; |
| 7122 | for (i = 0; i < count; i++) { |
| 7123 | /* IF RQ is already full, don't bother */ |
| 7124 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 7125 | break; |
| 7126 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7127 | if (!rqb_buffer) |
| 7128 | break; |
| 7129 | rqb_buffer->hrq = hrq; |
| 7130 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7131 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7132 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7133 | } |
| 7134 | while (!list_empty(&rqb_buf_list)) { |
| 7135 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7136 | hbuf.list); |
| 7137 | |
| 7138 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7139 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7140 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7141 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7142 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7143 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7144 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7145 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7146 | "DRQ %x %x\n", |
| 7147 | hrq->queue_id, |
| 7148 | hrq->host_index, |
| 7149 | hrq->hba_index, |
| 7150 | hrq->entry_count, |
| 7151 | drq->host_index, |
| 7152 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7153 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7154 | } else { |
| 7155 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7156 | &rqbp->rqb_buffer_list); |
| 7157 | rqbp->buffer_count++; |
| 7158 | } |
| 7159 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7160 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7161 | return 1; |
| 7162 | } |
| 7163 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7164 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7165 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7166 | * @phba: Pointer to HBA context object. |
| 7167 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7168 | * This function is the main SLI4 device initialization PCI function. This |
| 7169 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7170 | * HBA error attention handler code. Caller is not required to hold any |
| 7171 | * locks. |
| 7172 | **/ |
| 7173 | int |
| 7174 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7175 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7176 | int rc, i, cnt, len; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7177 | LPFC_MBOXQ_t *mboxq; |
| 7178 | struct lpfc_mqe *mqe; |
| 7179 | uint8_t *vpd; |
| 7180 | uint32_t vpd_size; |
| 7181 | uint32_t ftr_rsp = 0; |
| 7182 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7183 | struct lpfc_vport *vport = phba->pport; |
| 7184 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7185 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7186 | |
| 7187 | /* Perform a PCI function reset to start from clean */ |
| 7188 | rc = lpfc_pci_function_reset(phba); |
| 7189 | if (unlikely(rc)) |
| 7190 | return -ENODEV; |
| 7191 | |
| 7192 | /* Check the HBA Host Status Register for readyness */ |
| 7193 | rc = lpfc_sli4_post_status_check(phba); |
| 7194 | if (unlikely(rc)) |
| 7195 | return -ENODEV; |
| 7196 | else { |
| 7197 | spin_lock_irq(&phba->hbalock); |
| 7198 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7199 | spin_unlock_irq(&phba->hbalock); |
| 7200 | } |
| 7201 | |
| 7202 | /* |
| 7203 | * Allocate a single mailbox container for initializing the |
| 7204 | * port. |
| 7205 | */ |
| 7206 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7207 | if (!mboxq) |
| 7208 | return -ENOMEM; |
| 7209 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7210 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7211 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7212 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7213 | if (!vpd) { |
| 7214 | rc = -ENOMEM; |
| 7215 | goto out_free_mbox; |
| 7216 | } |
| 7217 | |
| 7218 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7219 | if (unlikely(rc)) { |
| 7220 | kfree(vpd); |
| 7221 | goto out_free_mbox; |
| 7222 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7223 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7224 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7225 | 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] | 7226 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7227 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7228 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7229 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7230 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7231 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7232 | |
| 7233 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7234 | LPFC_DCBX_CEE_MODE) |
| 7235 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7236 | else |
| 7237 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7238 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7239 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 7240 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7241 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7242 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7243 | "0376 READ_REV Error. SLI Level %d " |
| 7244 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7245 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7246 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7247 | kfree(vpd); |
| 7248 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7249 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7250 | |
| 7251 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7252 | * Continue initialization with default values even if driver failed |
| 7253 | * to read FCoE param config regions, only read parameters if the |
| 7254 | * board is FCoE |
| 7255 | */ |
| 7256 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7257 | lpfc_sli4_read_fcoe_params(phba)) |
| 7258 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7259 | "2570 Failed to read FCoE parameters\n"); |
| 7260 | |
| 7261 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7262 | * Retrieve sli4 device physical port name, failure of doing it |
| 7263 | * is considered as non-fatal. |
| 7264 | */ |
| 7265 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7266 | if (!rc) |
| 7267 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7268 | "3080 Successful retrieving SLI4 device " |
| 7269 | "physical port name: %s.\n", phba->Port); |
| 7270 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7271 | /* |
| 7272 | * Evaluate the read rev and vpd data. Populate the driver |
| 7273 | * state with the results. If this routine fails, the failure |
| 7274 | * is not fatal as the driver will use generic values. |
| 7275 | */ |
| 7276 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7277 | if (unlikely(!rc)) { |
| 7278 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7279 | "0377 Error %d parsing vpd. " |
| 7280 | "Using defaults.\n", rc); |
| 7281 | rc = 0; |
| 7282 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7283 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7284 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7285 | /* Save information as VPD data */ |
| 7286 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7287 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7288 | |
| 7289 | /* |
| 7290 | * This is because first G7 ASIC doesn't support the standard |
| 7291 | * 0x5a NVME cmd descriptor type/subtype |
| 7292 | */ |
| 7293 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7294 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7295 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7296 | (phba->vpd.rev.smRev == 0) && |
| 7297 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7298 | phba->cfg_nvme_embed_cmd = 0; |
| 7299 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7300 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7301 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7302 | &mqe->un.read_rev); |
| 7303 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7304 | &mqe->un.read_rev); |
| 7305 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7306 | &mqe->un.read_rev); |
| 7307 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7308 | &mqe->un.read_rev); |
| 7309 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7310 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7311 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7312 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7313 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7314 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7315 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7316 | "(%d):0380 READ_REV Status x%x " |
| 7317 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7318 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7319 | bf_get(lpfc_mqe_status, mqe), |
| 7320 | phba->vpd.rev.opFwName, |
| 7321 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7322 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7323 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7324 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 7325 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 7326 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 7327 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7328 | "3362 LUN queue depth changed from %d to %d\n", |
| 7329 | phba->pport->cfg_lun_queue_depth, rc); |
| 7330 | phba->pport->cfg_lun_queue_depth = rc; |
| 7331 | } |
| 7332 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7333 | 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] | 7334 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7335 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7336 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7337 | if (rc == MBX_SUCCESS) { |
| 7338 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7339 | /* Set 1Sec interval to detect UE */ |
| 7340 | phba->eratt_poll_interval = 1; |
| 7341 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7342 | lpfc_mbx_set_feature_UESR, |
| 7343 | &mboxq->u.mqe.un.set_feature); |
| 7344 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7345 | lpfc_mbx_set_feature_UERP, |
| 7346 | &mboxq->u.mqe.un.set_feature); |
| 7347 | } |
| 7348 | } |
| 7349 | |
| 7350 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7351 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7352 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7353 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7354 | if (rc != MBX_SUCCESS) |
| 7355 | phba->mds_diags_support = 0; |
| 7356 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7357 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7358 | /* |
| 7359 | * Discover the port's supported feature set and match it against the |
| 7360 | * hosts requests. |
| 7361 | */ |
| 7362 | lpfc_request_features(phba, mboxq); |
| 7363 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7364 | if (unlikely(rc)) { |
| 7365 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7366 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7367 | } |
| 7368 | |
| 7369 | /* |
| 7370 | * The port must support FCP initiator mode as this is the |
| 7371 | * only mode running in the host. |
| 7372 | */ |
| 7373 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7374 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7375 | "0378 No support for fcpi mode.\n"); |
| 7376 | ftr_rsp++; |
| 7377 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7378 | |
| 7379 | /* Performance Hints are ONLY for FCoE */ |
| 7380 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7381 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7382 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7383 | else |
| 7384 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7385 | } |
| 7386 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7387 | /* |
| 7388 | * If the port cannot support the host's requested features |
| 7389 | * then turn off the global config parameters to disable the |
| 7390 | * feature in the driver. This is not a fatal error. |
| 7391 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7392 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7393 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7394 | phba->cfg_enable_bg = 0; |
| 7395 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7396 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7397 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7398 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7399 | |
| 7400 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7401 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7402 | ftr_rsp++; |
| 7403 | |
| 7404 | if (ftr_rsp) { |
| 7405 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7406 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7407 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7408 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7409 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7410 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7411 | phba->cfg_enable_bg = 0; |
| 7412 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7413 | phba->cfg_enable_npiv = 0; |
| 7414 | } |
| 7415 | |
| 7416 | /* These SLI3 features are assumed in SLI4 */ |
| 7417 | spin_lock_irq(&phba->hbalock); |
| 7418 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7419 | spin_unlock_irq(&phba->hbalock); |
| 7420 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7421 | /* |
| 7422 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7423 | * calls depends on these resources to complete port setup. |
| 7424 | */ |
| 7425 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7426 | if (rc) { |
| 7427 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7428 | "2920 Failed to alloc Resource IDs " |
| 7429 | "rc = x%x\n", rc); |
| 7430 | goto out_free_mbox; |
| 7431 | } |
| 7432 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7433 | lpfc_set_host_data(phba, mboxq); |
| 7434 | |
| 7435 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7436 | if (rc) { |
| 7437 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7438 | "2134 Failed to set host os driver version %x", |
| 7439 | rc); |
| 7440 | } |
| 7441 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7442 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7443 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7444 | if (rc) { |
| 7445 | phba->link_state = LPFC_HBA_ERROR; |
| 7446 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7447 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7448 | } |
| 7449 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7450 | mboxq->vport = vport; |
| 7451 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7452 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7453 | if (rc == MBX_SUCCESS) { |
| 7454 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7455 | rc = 0; |
| 7456 | } |
| 7457 | |
| 7458 | /* |
| 7459 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7460 | * it to the mbuf pool. |
| 7461 | */ |
| 7462 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7463 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7464 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7465 | if (unlikely(rc)) { |
| 7466 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7467 | "0382 READ_SPARAM command failed " |
| 7468 | "status %d, mbxStatus x%x\n", |
| 7469 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7470 | phba->link_state = LPFC_HBA_ERROR; |
| 7471 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7472 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7473 | } |
| 7474 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7475 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7476 | |
| 7477 | /* Update the fc_host data structures with new wwn. */ |
| 7478 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7479 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7480 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7481 | /* Create all the SLI4 queues */ |
| 7482 | rc = lpfc_sli4_queue_create(phba); |
| 7483 | if (rc) { |
| 7484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7485 | "3089 Failed to allocate queues\n"); |
| 7486 | rc = -ENODEV; |
| 7487 | goto out_free_mbox; |
| 7488 | } |
| 7489 | /* Set up all the queues to the device */ |
| 7490 | rc = lpfc_sli4_queue_setup(phba); |
| 7491 | if (unlikely(rc)) { |
| 7492 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7493 | "0381 Error %d during queue setup.\n ", rc); |
| 7494 | goto out_stop_timers; |
| 7495 | } |
| 7496 | /* Initialize the driver internal SLI layer lists. */ |
| 7497 | lpfc_sli4_setup(phba); |
| 7498 | lpfc_sli4_queue_init(phba); |
| 7499 | |
| 7500 | /* update host els xri-sgl sizes and mappings */ |
| 7501 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7502 | if (unlikely(rc)) { |
| 7503 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7504 | "1400 Failed to update xri-sgl size and " |
| 7505 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7506 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7507 | } |
| 7508 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7509 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7510 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7511 | phba->sli4_hba.els_xri_cnt); |
| 7512 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7513 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7514 | "0582 Error %d during els sgl post " |
| 7515 | "operation\n", rc); |
| 7516 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7517 | goto out_destroy_queue; |
| 7518 | } |
| 7519 | phba->sli4_hba.els_xri_cnt = rc; |
| 7520 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7521 | if (phba->nvmet_support) { |
| 7522 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7523 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7524 | if (unlikely(rc)) { |
| 7525 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7526 | "6308 Failed to update nvmet-sgl size " |
| 7527 | "and mapping: %d\n", rc); |
| 7528 | goto out_destroy_queue; |
| 7529 | } |
| 7530 | |
| 7531 | /* register the nvmet sgl pool to the port */ |
| 7532 | rc = lpfc_sli4_repost_sgl_list( |
| 7533 | phba, |
| 7534 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7535 | phba->sli4_hba.nvmet_xri_cnt); |
| 7536 | if (unlikely(rc < 0)) { |
| 7537 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7538 | "3117 Error %d during nvmet " |
| 7539 | "sgl post\n", rc); |
| 7540 | rc = -ENODEV; |
| 7541 | goto out_destroy_queue; |
| 7542 | } |
| 7543 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7544 | |
| 7545 | cnt = phba->cfg_iocb_cnt * 1024; |
| 7546 | /* We need 1 iocbq for every SGL, for IO processing */ |
| 7547 | cnt += phba->sli4_hba.nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7548 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7549 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7550 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7551 | if (unlikely(rc)) { |
| 7552 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7553 | "6082 Failed to update nvme-sgl size " |
| 7554 | "and mapping: %d\n", rc); |
| 7555 | goto out_destroy_queue; |
| 7556 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7557 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7558 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7559 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7560 | if (unlikely(rc)) { |
| 7561 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7562 | "6116 Error %d during nvme sgl post " |
| 7563 | "operation\n", rc); |
| 7564 | /* Some NVME buffers were moved to abort nvme list */ |
| 7565 | /* A pci function reset will repost them */ |
| 7566 | rc = -ENODEV; |
| 7567 | goto out_destroy_queue; |
| 7568 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7569 | cnt = phba->cfg_iocb_cnt * 1024; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7570 | } |
| 7571 | |
| 7572 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7573 | /* Initialize and populate the iocb list per host */ |
| 7574 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7575 | "2821 initialize iocb list %d total %d\n", |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7576 | phba->cfg_iocb_cnt, cnt); |
| 7577 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7578 | if (rc) { |
| 7579 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7580 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7581 | goto out_destroy_queue; |
| 7582 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7583 | } |
| 7584 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7585 | if (phba->nvmet_support) |
| 7586 | lpfc_nvmet_create_targetport(phba); |
| 7587 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7588 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7589 | /* Post initial buffers to all RQs created */ |
| 7590 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7591 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7592 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7593 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7594 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7595 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7596 | rqbp->buffer_count = 0; |
| 7597 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7598 | lpfc_post_rq_buffer( |
| 7599 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7600 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7601 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7602 | } |
| 7603 | } |
| 7604 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7605 | /* Post the rpi header region to the device. */ |
| 7606 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7607 | if (unlikely(rc)) { |
| 7608 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7609 | "0393 Error %d during rpi post operation\n", |
| 7610 | rc); |
| 7611 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7612 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7613 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7614 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7615 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7616 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7617 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7618 | /* |
| 7619 | * The FC Port needs to register FCFI (index 0) |
| 7620 | */ |
| 7621 | lpfc_reg_fcfi(phba, mboxq); |
| 7622 | mboxq->vport = phba->pport; |
| 7623 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7624 | if (rc != MBX_SUCCESS) |
| 7625 | goto out_unset_queue; |
| 7626 | rc = 0; |
| 7627 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7628 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7629 | } else { |
| 7630 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7631 | |
| 7632 | /* First register the FCFI */ |
| 7633 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7634 | mboxq->vport = phba->pport; |
| 7635 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7636 | if (rc != MBX_SUCCESS) |
| 7637 | goto out_unset_queue; |
| 7638 | rc = 0; |
| 7639 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7640 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7641 | |
| 7642 | /* Next register the MRQs */ |
| 7643 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7644 | mboxq->vport = phba->pport; |
| 7645 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7646 | if (rc != MBX_SUCCESS) |
| 7647 | goto out_unset_queue; |
| 7648 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7649 | } |
| 7650 | /* Check if the port is configured to be disabled */ |
| 7651 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7652 | } |
| 7653 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7654 | /* Don't post more new bufs if repost already recovered |
| 7655 | * the nvme sgls. |
| 7656 | */ |
| 7657 | if (phba->nvmet_support == 0) { |
| 7658 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 7659 | len = lpfc_new_io_buf( |
| 7660 | phba, phba->sli4_hba.io_xri_max); |
| 7661 | if (len == 0) { |
| 7662 | rc = -ENOMEM; |
| 7663 | goto out_unset_queue; |
| 7664 | } |
| 7665 | |
| 7666 | if (phba->cfg_xri_rebalancing) |
| 7667 | lpfc_create_multixri_pools(phba); |
| 7668 | } |
| 7669 | } else { |
| 7670 | phba->cfg_xri_rebalancing = 0; |
| 7671 | } |
| 7672 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7673 | /* Arm the CQs and then EQs on device */ |
| 7674 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7675 | |
| 7676 | /* Indicate device interrupt mode */ |
| 7677 | phba->sli4_hba.intr_enable = 1; |
| 7678 | |
| 7679 | /* Allow asynchronous mailbox command to go through */ |
| 7680 | spin_lock_irq(&phba->hbalock); |
| 7681 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7682 | spin_unlock_irq(&phba->hbalock); |
| 7683 | |
| 7684 | /* Post receive buffers to the device */ |
| 7685 | lpfc_sli4_rb_setup(phba); |
| 7686 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7687 | /* Reset HBA FCF states after HBA reset */ |
| 7688 | phba->fcf.fcf_flag = 0; |
| 7689 | phba->fcf.current_rec.flag = 0; |
| 7690 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7691 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7692 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7693 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7694 | |
| 7695 | /* Start heart beat timer */ |
| 7696 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7697 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7698 | phba->hb_outstanding = 0; |
| 7699 | phba->last_completion_time = jiffies; |
| 7700 | |
| 7701 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7702 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7703 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7704 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7705 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7706 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7707 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7708 | if (!rc) { |
| 7709 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7710 | "2829 This device supports " |
| 7711 | "Advanced Error Reporting (AER)\n"); |
| 7712 | spin_lock_irq(&phba->hbalock); |
| 7713 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7714 | spin_unlock_irq(&phba->hbalock); |
| 7715 | } else { |
| 7716 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7717 | "2830 This device does not support " |
| 7718 | "Advanced Error Reporting (AER)\n"); |
| 7719 | phba->cfg_aer_support = 0; |
| 7720 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7721 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7722 | } |
| 7723 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7724 | /* |
| 7725 | * The port is ready, set the host's link state to LINK_DOWN |
| 7726 | * in preparation for link interrupts. |
| 7727 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7728 | spin_lock_irq(&phba->hbalock); |
| 7729 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7730 | |
| 7731 | /* Check if physical ports are trunked */ |
| 7732 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 7733 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 7734 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 7735 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 7736 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 7737 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 7738 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 7739 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7740 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7741 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7742 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7743 | (phba->hba_flag & LINK_DISABLED)) { |
| 7744 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7745 | "3103 Adapter Link is disabled.\n"); |
| 7746 | lpfc_down_link(phba, mboxq); |
| 7747 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7748 | if (rc != MBX_SUCCESS) { |
| 7749 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7750 | "3104 Adapter failed to issue " |
| 7751 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7752 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7753 | } |
| 7754 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7755 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7756 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7757 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7758 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7759 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7760 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7761 | } |
| 7762 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7763 | return rc; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7764 | out_io_buff_free: |
| 7765 | /* Free allocated IO Buffers */ |
| 7766 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7767 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7768 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7769 | lpfc_sli4_queue_unset(phba); |
| 7770 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7771 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7772 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7773 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7774 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7775 | out_free_mbox: |
| 7776 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7777 | return rc; |
| 7778 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7779 | |
| 7780 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7781 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7782 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7783 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7784 | * This is the callback function for mailbox timer. The mailbox |
| 7785 | * timer is armed when a new mailbox command is issued and the timer |
| 7786 | * is deleted when the mailbox complete. The function is called by |
| 7787 | * the kernel timer code when a mailbox does not complete within |
| 7788 | * expected time. This function wakes up the worker thread to |
| 7789 | * process the mailbox timeout and returns. All the processing is |
| 7790 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7791 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7792 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7793 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7794 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7795 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7796 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7797 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7798 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7799 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7800 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7801 | if (!tmo_posted) |
| 7802 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7803 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7804 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7805 | if (!tmo_posted) |
| 7806 | lpfc_worker_wake_up(phba); |
| 7807 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7808 | } |
| 7809 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7810 | /** |
| 7811 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7812 | * are pending |
| 7813 | * @phba: Pointer to HBA context object. |
| 7814 | * |
| 7815 | * This function checks if any mailbox completions are present on the mailbox |
| 7816 | * completion queue. |
| 7817 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7818 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7819 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7820 | { |
| 7821 | |
| 7822 | uint32_t idx; |
| 7823 | struct lpfc_queue *mcq; |
| 7824 | struct lpfc_mcqe *mcqe; |
| 7825 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7826 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7827 | |
| 7828 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7829 | return false; |
| 7830 | |
| 7831 | /* Check for completions on mailbox completion queue */ |
| 7832 | |
| 7833 | mcq = phba->sli4_hba.mbx_cq; |
| 7834 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7835 | qe_valid = mcq->qe_valid; |
| 7836 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe) == qe_valid) { |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7837 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 7838 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7839 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7840 | pending_completions = true; |
| 7841 | break; |
| 7842 | } |
| 7843 | idx = (idx + 1) % mcq->entry_count; |
| 7844 | if (mcq->hba_index == idx) |
| 7845 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7846 | |
| 7847 | /* if the index wrapped around, toggle the valid bit */ |
| 7848 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 7849 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7850 | } |
| 7851 | return pending_completions; |
| 7852 | |
| 7853 | } |
| 7854 | |
| 7855 | /** |
| 7856 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7857 | * that were missed. |
| 7858 | * @phba: Pointer to HBA context object. |
| 7859 | * |
| 7860 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7861 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7862 | * checks to see if mbox completions are on the mailbox completion queue |
| 7863 | * and will process all the completions associated with the eq for the |
| 7864 | * mailbox completion queue. |
| 7865 | **/ |
| 7866 | bool |
| 7867 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7868 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7869 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7870 | uint32_t eqidx; |
| 7871 | struct lpfc_queue *fpeq = NULL; |
| 7872 | struct lpfc_eqe *eqe; |
| 7873 | bool mbox_pending; |
| 7874 | |
| 7875 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7876 | return false; |
| 7877 | |
| 7878 | /* Find the eq associated with the mcq */ |
| 7879 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 7880 | if (sli4_hba->hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 7881 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 7882 | if (sli4_hba->hdwq[eqidx].hba_eq->queue_id == |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7883 | sli4_hba->mbx_cq->assoc_qid) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 7884 | fpeq = sli4_hba->hdwq[eqidx].hba_eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7885 | break; |
| 7886 | } |
| 7887 | if (!fpeq) |
| 7888 | return false; |
| 7889 | |
| 7890 | /* Turn off interrupts from this EQ */ |
| 7891 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7892 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7893 | |
| 7894 | /* Check to see if a mbox completion is pending */ |
| 7895 | |
| 7896 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7897 | |
| 7898 | /* |
| 7899 | * If a mbox completion is pending, process all the events on EQ |
| 7900 | * associated with the mbox completion queue (this could include |
| 7901 | * mailbox commands, async events, els commands, receive queue data |
| 7902 | * and fcp commands) |
| 7903 | */ |
| 7904 | |
| 7905 | if (mbox_pending) |
| 7906 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 7907 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 7908 | fpeq->EQ_processed++; |
| 7909 | } |
| 7910 | |
| 7911 | /* Always clear and re-arm the EQ */ |
| 7912 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7913 | sli4_hba->sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7914 | |
| 7915 | return mbox_pending; |
| 7916 | |
| 7917 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7918 | |
| 7919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7920 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7921 | * @phba: Pointer to HBA context object. |
| 7922 | * |
| 7923 | * This function is called from worker thread when a mailbox command times out. |
| 7924 | * The caller is not required to hold any locks. This function will reset the |
| 7925 | * HBA and recover all the pending commands. |
| 7926 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7927 | void |
| 7928 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7929 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7930 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7931 | MAILBOX_t *mb = NULL; |
| 7932 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7933 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7934 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7935 | /* If the mailbox completed, process the completion and return */ |
| 7936 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7937 | return; |
| 7938 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7939 | if (pmbox != NULL) |
| 7940 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7941 | /* Check the pmbox pointer first. There is a race condition |
| 7942 | * between the mbox timeout handler getting executed in the |
| 7943 | * worklist and the mailbox actually completing. When this |
| 7944 | * race condition occurs, the mbox_active will be NULL. |
| 7945 | */ |
| 7946 | spin_lock_irq(&phba->hbalock); |
| 7947 | if (pmbox == NULL) { |
| 7948 | lpfc_printf_log(phba, KERN_WARNING, |
| 7949 | LOG_MBOX | LOG_SLI, |
| 7950 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7951 | "exiting\n"); |
| 7952 | spin_unlock_irq(&phba->hbalock); |
| 7953 | return; |
| 7954 | } |
| 7955 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7956 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7957 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7958 | "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] | 7959 | mb->mbxCommand, |
| 7960 | phba->pport->port_state, |
| 7961 | phba->sli.sli_flag, |
| 7962 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7963 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7964 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7965 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7966 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7967 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7968 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7969 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7970 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7971 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7972 | spin_lock_irq(&phba->hbalock); |
| 7973 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7974 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7975 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7976 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 7977 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7978 | |
| 7979 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 7980 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7981 | |
| 7982 | /* Reset the HBA device */ |
| 7983 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7984 | } |
| 7985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7986 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7987 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7988 | * @phba: Pointer to HBA context object. |
| 7989 | * @pmbox: Pointer to mailbox object. |
| 7990 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7991 | * |
| 7992 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7993 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 7994 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7995 | * The mailbox command can be submitted in polling mode, in which case |
| 7996 | * this function will wait in a polling loop for the completion of the |
| 7997 | * mailbox. |
| 7998 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 7999 | * function will submit the command and returns immediately without waiting |
| 8000 | * for the mailbox completion. The no_wait is supported only when HBA |
| 8001 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 8002 | * The SLI interface allows only one mailbox pending at a time. If the |
| 8003 | * mailbox is issued in polling mode and there is already a mailbox |
| 8004 | * pending, then the function will return an error. If the mailbox is issued |
| 8005 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 8006 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 8007 | * The sli layer owns the mailbox object until the completion of mailbox |
| 8008 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 8009 | * return codes the caller owns the mailbox command after the return of |
| 8010 | * the function. |
| 8011 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8012 | static int |
| 8013 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 8014 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8015 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8016 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8017 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8018 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8019 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8020 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8021 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8022 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8023 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8024 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8025 | int processing_queue = 0; |
| 8026 | |
| 8027 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8028 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8029 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8030 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8031 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8032 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8033 | return MBX_SUCCESS; |
| 8034 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8035 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8036 | pmbox = lpfc_mbox_get(phba); |
| 8037 | if (!pmbox) { |
| 8038 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8039 | return MBX_SUCCESS; |
| 8040 | } |
| 8041 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8042 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8043 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8044 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8045 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8046 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8047 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8048 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8049 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8050 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8051 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8052 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8053 | } |
| 8054 | } |
| 8055 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8056 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8057 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8058 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8059 | goto out_not_finished; |
| 8060 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8061 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8062 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8063 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8064 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8065 | goto out_not_finished; |
| 8066 | } |
| 8067 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8068 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8069 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8070 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8071 | status = MBX_SUCCESS; |
| 8072 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8073 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8074 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8075 | |
| 8076 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8077 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8078 | "(%d):0311 Mailbox command x%x cannot " |
| 8079 | "issue Data: x%x x%x\n", |
| 8080 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8081 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8082 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8083 | } |
| 8084 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8085 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8086 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8087 | !(hc_copy & HC_MBINT_ENA)) { |
| 8088 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8089 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8090 | "(%d):2528 Mailbox command x%x cannot " |
| 8091 | "issue Data: x%x x%x\n", |
| 8092 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8093 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8094 | goto out_not_finished; |
| 8095 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8096 | } |
| 8097 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8098 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8099 | /* Polling for a mbox command when another one is already active |
| 8100 | * is not allowed in SLI. Also, the driver must have established |
| 8101 | * SLI2 mode to queue and process multiple mbox commands. |
| 8102 | */ |
| 8103 | |
| 8104 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8105 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8106 | |
| 8107 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8108 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8109 | "(%d):2529 Mailbox command x%x " |
| 8110 | "cannot issue Data: x%x x%x\n", |
| 8111 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8112 | pmbox->u.mb.mbxCommand, |
| 8113 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8114 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8115 | } |
| 8116 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8117 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8118 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8119 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8120 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8121 | "(%d):2530 Mailbox command x%x " |
| 8122 | "cannot issue Data: x%x x%x\n", |
| 8123 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8124 | pmbox->u.mb.mbxCommand, |
| 8125 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8126 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8127 | } |
| 8128 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8129 | /* Another mailbox command is still being processed, queue this |
| 8130 | * command to be processed later. |
| 8131 | */ |
| 8132 | lpfc_mbox_put(phba, pmbox); |
| 8133 | |
| 8134 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8135 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8136 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8137 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8138 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8139 | mbx->mbxCommand, |
| 8140 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8141 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8142 | |
| 8143 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8144 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8145 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8146 | if (pmbox->vport) { |
| 8147 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8148 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8149 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8150 | (uint32_t)mbx->mbxCommand, |
| 8151 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8152 | } |
| 8153 | else { |
| 8154 | lpfc_debugfs_disc_trc(phba->pport, |
| 8155 | LPFC_DISC_TRC_MBOX, |
| 8156 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8157 | (uint32_t)mbx->mbxCommand, |
| 8158 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8159 | } |
| 8160 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8161 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8162 | } |
| 8163 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8164 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8165 | |
| 8166 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8167 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8168 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8169 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8170 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8171 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8172 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8173 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8174 | "(%d):2531 Mailbox command x%x " |
| 8175 | "cannot issue Data: x%x x%x\n", |
| 8176 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8177 | pmbox->u.mb.mbxCommand, |
| 8178 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8179 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8180 | } |
| 8181 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8182 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8183 | 1000); |
| 8184 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8185 | } |
| 8186 | |
| 8187 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8188 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8189 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8190 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8191 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8192 | mbx->mbxCommand, |
| 8193 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8194 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8195 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8196 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8197 | if (pmbox->vport) { |
| 8198 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8199 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8200 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8201 | (uint32_t)mbx->mbxCommand, |
| 8202 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8203 | } |
| 8204 | else { |
| 8205 | lpfc_debugfs_disc_trc(phba->pport, |
| 8206 | LPFC_DISC_TRC_MBOX, |
| 8207 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8208 | (uint32_t)mbx->mbxCommand, |
| 8209 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8210 | } |
| 8211 | } |
| 8212 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8213 | psli->slistat.mbox_cmd++; |
| 8214 | evtctr = psli->slistat.mbox_event; |
| 8215 | |
| 8216 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8217 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8218 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8219 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8220 | /* Populate mbox extension offset word. */ |
| 8221 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8222 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8223 | = (uint8_t *)phba->mbox_ext |
| 8224 | - (uint8_t *)phba->mbox; |
| 8225 | } |
| 8226 | |
| 8227 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8228 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8229 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8230 | (uint8_t *)phba->mbox_ext, |
| 8231 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8232 | } |
| 8233 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8234 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8235 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8236 | /* Populate mbox extension offset word. */ |
| 8237 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8238 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8239 | = MAILBOX_HBA_EXT_OFFSET; |
| 8240 | |
| 8241 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8242 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8243 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8244 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8245 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8246 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8247 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8248 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8249 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8250 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8251 | |
| 8252 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8253 | word */ |
| 8254 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8255 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8256 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8257 | |
| 8258 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8259 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8260 | to_slim = phba->MBslimaddr; |
| 8261 | writel(ldata, to_slim); |
| 8262 | readl(to_slim); /* flush */ |
| 8263 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8264 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8265 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8266 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8267 | } |
| 8268 | |
| 8269 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8270 | |
| 8271 | switch (flag) { |
| 8272 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8273 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8274 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8275 | /* Interrupt board to do it */ |
| 8276 | writel(CA_MBATT, phba->CAregaddr); |
| 8277 | readl(phba->CAregaddr); /* flush */ |
| 8278 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8279 | break; |
| 8280 | |
| 8281 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8282 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8283 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8284 | /* Interrupt board to do it */ |
| 8285 | writel(CA_MBATT, phba->CAregaddr); |
| 8286 | readl(phba->CAregaddr); /* flush */ |
| 8287 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8288 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8289 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8290 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8291 | word0 = le32_to_cpu(word0); |
| 8292 | } else { |
| 8293 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8294 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8295 | spin_unlock_irqrestore(&phba->hbalock, |
| 8296 | drvr_flag); |
| 8297 | goto out_not_finished; |
| 8298 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8299 | } |
| 8300 | |
| 8301 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8302 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8303 | spin_unlock_irqrestore(&phba->hbalock, |
| 8304 | drvr_flag); |
| 8305 | goto out_not_finished; |
| 8306 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8307 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8308 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8309 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8310 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8311 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8312 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8313 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8314 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8315 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8316 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8317 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8318 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8319 | } |
| 8320 | |
| 8321 | /* Check if we took a mbox interrupt while we were |
| 8322 | polling */ |
| 8323 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8324 | && (evtctr != psli->slistat.mbox_event)) |
| 8325 | break; |
| 8326 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8327 | if (i++ > 10) { |
| 8328 | spin_unlock_irqrestore(&phba->hbalock, |
| 8329 | drvr_flag); |
| 8330 | msleep(1); |
| 8331 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8332 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8333 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8334 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8335 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8336 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8337 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8338 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8339 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8340 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8341 | /* Check real SLIM for any errors */ |
| 8342 | slimword0 = readl(phba->MBslimaddr); |
| 8343 | slimmb = (MAILBOX_t *) & slimword0; |
| 8344 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8345 | && slimmb->mbxStatus) { |
| 8346 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8347 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8348 | word0 = slimword0; |
| 8349 | } |
| 8350 | } |
| 8351 | } else { |
| 8352 | /* First copy command data */ |
| 8353 | word0 = readl(phba->MBslimaddr); |
| 8354 | } |
| 8355 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8356 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8357 | spin_unlock_irqrestore(&phba->hbalock, |
| 8358 | drvr_flag); |
| 8359 | goto out_not_finished; |
| 8360 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8361 | } |
| 8362 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8363 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8364 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8365 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8366 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8367 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8368 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8369 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8370 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8371 | pmbox->out_ext_byte_len); |
| 8372 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8373 | } else { |
| 8374 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8375 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8376 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8377 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8378 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8379 | lpfc_memcpy_from_slim( |
| 8380 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8381 | phba->MBslimaddr + |
| 8382 | MAILBOX_HBA_EXT_OFFSET, |
| 8383 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | writel(HA_MBATT, phba->HAregaddr); |
| 8388 | readl(phba->HAregaddr); /* flush */ |
| 8389 | |
| 8390 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8391 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8392 | } |
| 8393 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8394 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8395 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8396 | |
| 8397 | out_not_finished: |
| 8398 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8399 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8400 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8401 | } |
| 8402 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8403 | } |
| 8404 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8405 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8406 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8407 | * @phba: Pointer to HBA context object. |
| 8408 | * |
| 8409 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8410 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8411 | * possible outstanding mailbox command before return. |
| 8412 | * |
| 8413 | * Returns: |
| 8414 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8415 | * the outstanding mailbox command timed out. |
| 8416 | **/ |
| 8417 | static int |
| 8418 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8419 | { |
| 8420 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8421 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8422 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8423 | |
| 8424 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8425 | spin_lock_irq(&phba->hbalock); |
| 8426 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8427 | /* Determine how long we might wait for the active mailbox |
| 8428 | * command to be gracefully completed by firmware. |
| 8429 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8430 | if (phba->sli.mbox_active) |
| 8431 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8432 | phba->sli.mbox_active) * |
| 8433 | 1000) + jiffies; |
| 8434 | spin_unlock_irq(&phba->hbalock); |
| 8435 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8436 | /* Make sure the mailbox is really active */ |
| 8437 | if (timeout) |
| 8438 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8439 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8440 | /* Wait for the outstnading mailbox command to complete */ |
| 8441 | while (phba->sli.mbox_active) { |
| 8442 | /* Check active mailbox complete status every 2ms */ |
| 8443 | msleep(2); |
| 8444 | if (time_after(jiffies, timeout)) { |
| 8445 | /* Timeout, marked the outstanding cmd not complete */ |
| 8446 | rc = 1; |
| 8447 | break; |
| 8448 | } |
| 8449 | } |
| 8450 | |
| 8451 | /* Can not cleanly block async mailbox command, fails it */ |
| 8452 | if (rc) { |
| 8453 | spin_lock_irq(&phba->hbalock); |
| 8454 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8455 | spin_unlock_irq(&phba->hbalock); |
| 8456 | } |
| 8457 | return rc; |
| 8458 | } |
| 8459 | |
| 8460 | /** |
| 8461 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8462 | * @phba: Pointer to HBA context object. |
| 8463 | * |
| 8464 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8465 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8466 | * that there is no outstanding mailbox command before resuming posting |
| 8467 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8468 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8469 | * mailbox command posting. |
| 8470 | **/ |
| 8471 | static void |
| 8472 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8473 | { |
| 8474 | struct lpfc_sli *psli = &phba->sli; |
| 8475 | |
| 8476 | spin_lock_irq(&phba->hbalock); |
| 8477 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8478 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8479 | spin_unlock_irq(&phba->hbalock); |
| 8480 | return; |
| 8481 | } |
| 8482 | |
| 8483 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8484 | * successful or timeout, after timing-out the outstanding mailbox |
| 8485 | * command shall always be removed, so just unblock posting async |
| 8486 | * mailbox command and resume |
| 8487 | */ |
| 8488 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8489 | spin_unlock_irq(&phba->hbalock); |
| 8490 | |
| 8491 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 8492 | lpfc_worker_wake_up(phba); |
| 8493 | } |
| 8494 | |
| 8495 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8496 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8497 | * @phba: Pointer to HBA context object. |
| 8498 | * @mboxq: Pointer to mailbox object. |
| 8499 | * |
| 8500 | * The function waits for the bootstrap mailbox register ready bit from |
| 8501 | * port for twice the regular mailbox command timeout value. |
| 8502 | * |
| 8503 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8504 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8505 | **/ |
| 8506 | static int |
| 8507 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8508 | { |
| 8509 | uint32_t db_ready; |
| 8510 | unsigned long timeout; |
| 8511 | struct lpfc_register bmbx_reg; |
| 8512 | |
| 8513 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8514 | * 1000) + jiffies; |
| 8515 | |
| 8516 | do { |
| 8517 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8518 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8519 | if (!db_ready) |
| 8520 | msleep(2); |
| 8521 | |
| 8522 | if (time_after(jiffies, timeout)) |
| 8523 | return MBXERR_ERROR; |
| 8524 | } while (!db_ready); |
| 8525 | |
| 8526 | return 0; |
| 8527 | } |
| 8528 | |
| 8529 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8530 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8531 | * @phba: Pointer to HBA context object. |
| 8532 | * @mboxq: Pointer to mailbox object. |
| 8533 | * |
| 8534 | * The function posts a mailbox to the port. The mailbox is expected |
| 8535 | * to be comletely filled in and ready for the port to operate on it. |
| 8536 | * This routine executes a synchronous completion operation on the |
| 8537 | * mailbox by polling for its completion. |
| 8538 | * |
| 8539 | * The caller must not be holding any locks when calling this routine. |
| 8540 | * |
| 8541 | * Returns: |
| 8542 | * MBX_SUCCESS - mailbox posted successfully |
| 8543 | * Any of the MBX error values. |
| 8544 | **/ |
| 8545 | static int |
| 8546 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8547 | { |
| 8548 | int rc = MBX_SUCCESS; |
| 8549 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8550 | uint32_t mcqe_status; |
| 8551 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8552 | struct lpfc_sli *psli = &phba->sli; |
| 8553 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8554 | struct lpfc_bmbx_create *mbox_rgn; |
| 8555 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8556 | |
| 8557 | /* |
| 8558 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8559 | * at a time and there is no queueing provided. |
| 8560 | */ |
| 8561 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8562 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8563 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8564 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8565 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8566 | "cannot issue Data: x%x x%x\n", |
| 8567 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8568 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8569 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8570 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8571 | psli->sli_flag, MBX_POLL); |
| 8572 | return MBXERR_ERROR; |
| 8573 | } |
| 8574 | /* The server grabs the token and owns it until release */ |
| 8575 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8576 | phba->sli.mbox_active = mboxq; |
| 8577 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8578 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8579 | /* wait for bootstrap mbox register for readyness */ |
| 8580 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8581 | if (rc) |
| 8582 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8583 | /* |
| 8584 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8585 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8586 | * the bmbx mailbox region. |
| 8587 | */ |
| 8588 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8589 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8590 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8591 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8592 | |
| 8593 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8594 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8595 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8596 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8597 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8598 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8599 | if (rc) |
| 8600 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8601 | |
| 8602 | /* Post the low mailbox dma address to the port. */ |
| 8603 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8604 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8605 | /* wait for bootstrap mbox register for low address write done */ |
| 8606 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8607 | if (rc) |
| 8608 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8609 | |
| 8610 | /* |
| 8611 | * Read the CQ to ensure the mailbox has completed. |
| 8612 | * If so, update the mailbox status so that the upper layers |
| 8613 | * can complete the request normally. |
| 8614 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8615 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8616 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8617 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8618 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8619 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8620 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8621 | /* |
| 8622 | * When the CQE status indicates a failure and the mailbox status |
| 8623 | * indicates success then copy the CQE status into the mailbox status |
| 8624 | * (and prefix it with x4000). |
| 8625 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8626 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8627 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8628 | bf_set(lpfc_mqe_status, mb, |
| 8629 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8630 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8631 | } else |
| 8632 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8633 | |
| 8634 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8635 | "(%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] | 8636 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8637 | " 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] | 8638 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8639 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8640 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8641 | bf_get(lpfc_mqe_status, mb), |
| 8642 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8643 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8644 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8645 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8646 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8647 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8648 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8649 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8650 | mboxq->mcqe.trailer); |
| 8651 | exit: |
| 8652 | /* We are holding the token, no needed for lock when release */ |
| 8653 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8654 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8655 | phba->sli.mbox_active = NULL; |
| 8656 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8657 | return rc; |
| 8658 | } |
| 8659 | |
| 8660 | /** |
| 8661 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8662 | * @phba: Pointer to HBA context object. |
| 8663 | * @pmbox: Pointer to mailbox object. |
| 8664 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8665 | * |
| 8666 | * This function is called by discovery code and HBA management code to submit |
| 8667 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8668 | * |
| 8669 | * Return codes the caller owns the mailbox command after the return of the |
| 8670 | * function. |
| 8671 | **/ |
| 8672 | static int |
| 8673 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8674 | uint32_t flag) |
| 8675 | { |
| 8676 | struct lpfc_sli *psli = &phba->sli; |
| 8677 | unsigned long iflags; |
| 8678 | int rc; |
| 8679 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8680 | /* dump from issue mailbox command if setup */ |
| 8681 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8682 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8683 | rc = lpfc_mbox_dev_check(phba); |
| 8684 | if (unlikely(rc)) { |
| 8685 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8686 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8687 | "cannot issue Data: x%x x%x\n", |
| 8688 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8689 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8690 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8691 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8692 | psli->sli_flag, flag); |
| 8693 | goto out_not_finished; |
| 8694 | } |
| 8695 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8696 | /* Detect polling mode and jump to a handler */ |
| 8697 | if (!phba->sli4_hba.intr_enable) { |
| 8698 | if (flag == MBX_POLL) |
| 8699 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8700 | else |
| 8701 | rc = -EIO; |
| 8702 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8703 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8704 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8705 | "(x%x/x%x) failure: " |
| 8706 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8707 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8708 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8709 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8710 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8711 | mboxq), |
| 8712 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8713 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8714 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8715 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8716 | bf_get(lpfc_mcqe_ext_status, |
| 8717 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8718 | psli->sli_flag, flag); |
| 8719 | return rc; |
| 8720 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8721 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8722 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8723 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8724 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8725 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8726 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8727 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8728 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8729 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8730 | /* Try to block the asynchronous mailbox posting */ |
| 8731 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8732 | if (!rc) { |
| 8733 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8734 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8735 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8736 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8737 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8738 | "(%d):2597 Sync Mailbox command " |
| 8739 | "x%x (x%x/x%x) failure: " |
| 8740 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8741 | "Data: x%x x%x\n,", |
| 8742 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8743 | mboxq->u.mb.mbxCommand, |
| 8744 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8745 | mboxq), |
| 8746 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8747 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8748 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8749 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8750 | bf_get(lpfc_mcqe_ext_status, |
| 8751 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8752 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8753 | /* Unblock the async mailbox posting afterward */ |
| 8754 | lpfc_sli4_async_mbox_unblock(phba); |
| 8755 | } |
| 8756 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8757 | } |
| 8758 | |
| 8759 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8760 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8761 | if (rc) { |
| 8762 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8763 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8764 | "cannot issue Data: x%x x%x\n", |
| 8765 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8766 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8767 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8768 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8769 | psli->sli_flag, flag); |
| 8770 | goto out_not_finished; |
| 8771 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8772 | |
| 8773 | /* Put the mailbox command to the driver internal FIFO */ |
| 8774 | psli->slistat.mbox_busy++; |
| 8775 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8776 | lpfc_mbox_put(phba, mboxq); |
| 8777 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8778 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8779 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8780 | "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] | 8781 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8782 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8783 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8784 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8785 | phba->pport->port_state, |
| 8786 | psli->sli_flag, MBX_NOWAIT); |
| 8787 | /* Wake up worker thread to transport mailbox command from head */ |
| 8788 | lpfc_worker_wake_up(phba); |
| 8789 | |
| 8790 | return MBX_BUSY; |
| 8791 | |
| 8792 | out_not_finished: |
| 8793 | return MBX_NOT_FINISHED; |
| 8794 | } |
| 8795 | |
| 8796 | /** |
| 8797 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8798 | * @phba: Pointer to HBA context object. |
| 8799 | * |
| 8800 | * This function is called by worker thread to send a mailbox command to |
| 8801 | * SLI4 HBA firmware. |
| 8802 | * |
| 8803 | **/ |
| 8804 | int |
| 8805 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8806 | { |
| 8807 | struct lpfc_sli *psli = &phba->sli; |
| 8808 | LPFC_MBOXQ_t *mboxq; |
| 8809 | int rc = MBX_SUCCESS; |
| 8810 | unsigned long iflags; |
| 8811 | struct lpfc_mqe *mqe; |
| 8812 | uint32_t mbx_cmnd; |
| 8813 | |
| 8814 | /* Check interrupt mode before post async mailbox command */ |
| 8815 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8816 | return MBX_NOT_FINISHED; |
| 8817 | |
| 8818 | /* Check for mailbox command service token */ |
| 8819 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8820 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8821 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8822 | return MBX_NOT_FINISHED; |
| 8823 | } |
| 8824 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8825 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8826 | return MBX_NOT_FINISHED; |
| 8827 | } |
| 8828 | if (unlikely(phba->sli.mbox_active)) { |
| 8829 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8830 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8831 | "0384 There is pending active mailbox cmd\n"); |
| 8832 | return MBX_NOT_FINISHED; |
| 8833 | } |
| 8834 | /* Take the mailbox command service token */ |
| 8835 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8836 | |
| 8837 | /* Get the next mailbox command from head of queue */ |
| 8838 | mboxq = lpfc_mbox_get(phba); |
| 8839 | |
| 8840 | /* If no more mailbox command waiting for post, we're done */ |
| 8841 | if (!mboxq) { |
| 8842 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8843 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8844 | return MBX_SUCCESS; |
| 8845 | } |
| 8846 | phba->sli.mbox_active = mboxq; |
| 8847 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8848 | |
| 8849 | /* Check device readiness for posting mailbox command */ |
| 8850 | rc = lpfc_mbox_dev_check(phba); |
| 8851 | if (unlikely(rc)) |
| 8852 | /* Driver clean routine will clean up pending mailbox */ |
| 8853 | goto out_not_finished; |
| 8854 | |
| 8855 | /* Prepare the mbox command to be posted */ |
| 8856 | mqe = &mboxq->u.mqe; |
| 8857 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8858 | |
| 8859 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8860 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8861 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8862 | |
| 8863 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8864 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8865 | "x%x x%x\n", |
| 8866 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8867 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8868 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8869 | phba->pport->port_state, psli->sli_flag); |
| 8870 | |
| 8871 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8872 | if (mboxq->vport) { |
| 8873 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8874 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8875 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8876 | mbx_cmnd, mqe->un.mb_words[0], |
| 8877 | mqe->un.mb_words[1]); |
| 8878 | } else { |
| 8879 | lpfc_debugfs_disc_trc(phba->pport, |
| 8880 | LPFC_DISC_TRC_MBOX, |
| 8881 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8882 | mbx_cmnd, mqe->un.mb_words[0], |
| 8883 | mqe->un.mb_words[1]); |
| 8884 | } |
| 8885 | } |
| 8886 | psli->slistat.mbox_cmd++; |
| 8887 | |
| 8888 | /* Post the mailbox command to the port */ |
| 8889 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8890 | if (rc != MBX_SUCCESS) { |
| 8891 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8892 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8893 | "cannot issue Data: x%x x%x\n", |
| 8894 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8895 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8896 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8897 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8898 | psli->sli_flag, MBX_NOWAIT); |
| 8899 | goto out_not_finished; |
| 8900 | } |
| 8901 | |
| 8902 | return rc; |
| 8903 | |
| 8904 | out_not_finished: |
| 8905 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8906 | if (phba->sli.mbox_active) { |
| 8907 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8908 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8909 | /* Release the token */ |
| 8910 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8911 | phba->sli.mbox_active = NULL; |
| 8912 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8913 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8914 | |
| 8915 | return MBX_NOT_FINISHED; |
| 8916 | } |
| 8917 | |
| 8918 | /** |
| 8919 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8920 | * @phba: Pointer to HBA context object. |
| 8921 | * @pmbox: Pointer to mailbox object. |
| 8922 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8923 | * |
| 8924 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8925 | * the API jump table function pointer from the lpfc_hba struct. |
| 8926 | * |
| 8927 | * Return codes the caller owns the mailbox command after the return of the |
| 8928 | * function. |
| 8929 | **/ |
| 8930 | int |
| 8931 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8932 | { |
| 8933 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8934 | } |
| 8935 | |
| 8936 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8937 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8938 | * @phba: The hba struct for which this call is being executed. |
| 8939 | * @dev_grp: The HBA PCI-Device group number. |
| 8940 | * |
| 8941 | * This routine sets up the mbox interface API function jump table in @phba |
| 8942 | * struct. |
| 8943 | * Returns: 0 - success, -ENODEV - failure. |
| 8944 | **/ |
| 8945 | int |
| 8946 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8947 | { |
| 8948 | |
| 8949 | switch (dev_grp) { |
| 8950 | case LPFC_PCI_DEV_LP: |
| 8951 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8952 | phba->lpfc_sli_handle_slow_ring_event = |
| 8953 | lpfc_sli_handle_slow_ring_event_s3; |
| 8954 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8955 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8956 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8957 | break; |
| 8958 | case LPFC_PCI_DEV_OC: |
| 8959 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8960 | phba->lpfc_sli_handle_slow_ring_event = |
| 8961 | lpfc_sli_handle_slow_ring_event_s4; |
| 8962 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8963 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8964 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8965 | break; |
| 8966 | default: |
| 8967 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8968 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8969 | dev_grp); |
| 8970 | return -ENODEV; |
| 8971 | break; |
| 8972 | } |
| 8973 | return 0; |
| 8974 | } |
| 8975 | |
| 8976 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8977 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8978 | * @phba: Pointer to HBA context object. |
| 8979 | * @pring: Pointer to driver SLI ring object. |
| 8980 | * @piocb: Pointer to address of newly added command iocb. |
| 8981 | * |
| 8982 | * This function is called with hbalock held to add a command |
| 8983 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 8984 | * to the ring. |
| 8985 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8986 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8987 | __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] | 8988 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8989 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8990 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8991 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 8992 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8993 | } |
| 8994 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8995 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8996 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8997 | * @phba: Pointer to HBA context object. |
| 8998 | * @pring: Pointer to driver SLI ring object. |
| 8999 | * @piocb: Pointer to address of newly added command iocb. |
| 9000 | * |
| 9001 | * This function is called with hbalock held before a new |
| 9002 | * iocb is submitted to the firmware. This function checks |
| 9003 | * txq to flush the iocbs in txq to Firmware before |
| 9004 | * submitting new iocbs to the Firmware. |
| 9005 | * If there are iocbs in the txq which need to be submitted |
| 9006 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 9007 | * of the txq after dequeuing it from txq. |
| 9008 | * If there is no iocb in the txq then the function will return |
| 9009 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 9010 | * *piocb to find if there are more commands in the txq. |
| 9011 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9012 | static struct lpfc_iocbq * |
| 9013 | 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] | 9014 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9015 | { |
| 9016 | struct lpfc_iocbq * nextiocb; |
| 9017 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9018 | lockdep_assert_held(&phba->hbalock); |
| 9019 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9020 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9021 | if (!nextiocb) { |
| 9022 | nextiocb = *piocb; |
| 9023 | *piocb = NULL; |
| 9024 | } |
| 9025 | |
| 9026 | return nextiocb; |
| 9027 | } |
| 9028 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9029 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9030 | * __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] | 9031 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9032 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9033 | * @piocb: Pointer to command iocb. |
| 9034 | * @flag: Flag indicating if this command can be put into txq. |
| 9035 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9036 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9037 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9038 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9039 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9040 | * this function allows only iocbs for posting buffers. This function finds |
| 9041 | * next available slot in the command ring and posts the command to the |
| 9042 | * available slot and writes the port attention register to request HBA start |
| 9043 | * processing new iocb. If there is no slot available in the ring and |
| 9044 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9045 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9046 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9047 | * This function is called with hbalock held. The function will return success |
| 9048 | * after it successfully submit the iocb to firmware or after adding to the |
| 9049 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9050 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9051 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9052 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9053 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9054 | { |
| 9055 | struct lpfc_iocbq *nextiocb; |
| 9056 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9057 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9058 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9059 | lockdep_assert_held(&phba->hbalock); |
| 9060 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9061 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9062 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9063 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 9064 | lpfc_printf_log(phba, KERN_ERR, |
| 9065 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9066 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9067 | piocb->iocb.ulpCommand); |
| 9068 | dump_stack(); |
| 9069 | return IOCB_ERROR; |
| 9070 | } |
| 9071 | |
| 9072 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9073 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9074 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9075 | return IOCB_ERROR; |
| 9076 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9077 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9078 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9079 | return IOCB_ERROR; |
| 9080 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9081 | /* |
| 9082 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9083 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9084 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9085 | return IOCB_ERROR; |
| 9086 | |
| 9087 | /* |
| 9088 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9089 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9090 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9091 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9092 | goto iocb_busy; |
| 9093 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9094 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9095 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9096 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9097 | * can be issued if the link is not up. |
| 9098 | */ |
| 9099 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9100 | case CMD_GEN_REQUEST64_CR: |
| 9101 | case CMD_GEN_REQUEST64_CX: |
| 9102 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9103 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9104 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9105 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9106 | MENLO_TRANSPORT_TYPE)) |
| 9107 | |
| 9108 | goto iocb_busy; |
| 9109 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9110 | case CMD_QUE_RING_BUF_CN: |
| 9111 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9112 | /* |
| 9113 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9114 | * completion, iocb_cmpl MUST be 0. |
| 9115 | */ |
| 9116 | if (piocb->iocb_cmpl) |
| 9117 | piocb->iocb_cmpl = NULL; |
| 9118 | /*FALLTHROUGH*/ |
| 9119 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9120 | case CMD_CLOSE_XRI_CN: |
| 9121 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9122 | break; |
| 9123 | default: |
| 9124 | goto iocb_busy; |
| 9125 | } |
| 9126 | |
| 9127 | /* |
| 9128 | * For FCP commands, we must be in a state where we can process link |
| 9129 | * attention events. |
| 9130 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9131 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9132 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9133 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9134 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9136 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9137 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9138 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9139 | |
| 9140 | if (iocb) |
| 9141 | lpfc_sli_update_ring(phba, pring); |
| 9142 | else |
| 9143 | lpfc_sli_update_full_ring(phba, pring); |
| 9144 | |
| 9145 | if (!piocb) |
| 9146 | return IOCB_SUCCESS; |
| 9147 | |
| 9148 | goto out_busy; |
| 9149 | |
| 9150 | iocb_busy: |
| 9151 | pring->stats.iocb_cmd_delay++; |
| 9152 | |
| 9153 | out_busy: |
| 9154 | |
| 9155 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9156 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9157 | return IOCB_SUCCESS; |
| 9158 | } |
| 9159 | |
| 9160 | return IOCB_BUSY; |
| 9161 | } |
| 9162 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9163 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9164 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9165 | * @phba: Pointer to HBA context object. |
| 9166 | * @piocb: Pointer to command iocb. |
| 9167 | * @sglq: Pointer to the scatter gather queue object. |
| 9168 | * |
| 9169 | * This routine converts the bpl or bde that is in the IOCB |
| 9170 | * to a sgl list for the sli4 hardware. The physical address |
| 9171 | * of the bpl/bde is converted back to a virtual address. |
| 9172 | * If the IOCB contains a BPL then the list of BDE's is |
| 9173 | * converted to sli4_sge's. If the IOCB contains a single |
| 9174 | * BDE then it is converted to a single sli_sge. |
| 9175 | * The IOCB is still in cpu endianess so the contents of |
| 9176 | * the bpl can be used without byte swapping. |
| 9177 | * |
| 9178 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9179 | **/ |
| 9180 | static uint16_t |
| 9181 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9182 | struct lpfc_sglq *sglq) |
| 9183 | { |
| 9184 | uint16_t xritag = NO_XRI; |
| 9185 | struct ulp_bde64 *bpl = NULL; |
| 9186 | struct ulp_bde64 bde; |
| 9187 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9188 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9189 | IOCB_t *icmd; |
| 9190 | int numBdes = 0; |
| 9191 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9192 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9193 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9194 | |
| 9195 | if (!piocbq || !sglq) |
| 9196 | return xritag; |
| 9197 | |
| 9198 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9199 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9200 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9201 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9202 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9203 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9204 | sizeof(struct ulp_bde64); |
| 9205 | /* The addrHigh and addrLow fields within the IOCB |
| 9206 | * have not been byteswapped yet so there is no |
| 9207 | * need to swap them back. |
| 9208 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9209 | if (piocbq->context3) |
| 9210 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9211 | else |
| 9212 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9213 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9214 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9215 | if (!bpl) |
| 9216 | return xritag; |
| 9217 | |
| 9218 | for (i = 0; i < numBdes; i++) { |
| 9219 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9220 | sgl->addr_hi = bpl->addrHigh; |
| 9221 | sgl->addr_lo = bpl->addrLow; |
| 9222 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9223 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9224 | if ((i+1) == numBdes) |
| 9225 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9226 | else |
| 9227 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9228 | /* swap the size field back to the cpu so we |
| 9229 | * can assign it to the sgl. |
| 9230 | */ |
| 9231 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9232 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9233 | /* The offsets in the sgl need to be accumulated |
| 9234 | * separately for the request and reply lists. |
| 9235 | * The request is always first, the reply follows. |
| 9236 | */ |
| 9237 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9238 | /* add up the reply sg entries */ |
| 9239 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9240 | inbound++; |
| 9241 | /* first inbound? reset the offset */ |
| 9242 | if (inbound == 1) |
| 9243 | offset = 0; |
| 9244 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9245 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9246 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9247 | offset += bde.tus.f.bdeSize; |
| 9248 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9249 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9250 | bpl++; |
| 9251 | sgl++; |
| 9252 | } |
| 9253 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9254 | /* The addrHigh and addrLow fields of the BDE have not |
| 9255 | * been byteswapped yet so they need to be swapped |
| 9256 | * before putting them in the sgl. |
| 9257 | */ |
| 9258 | sgl->addr_hi = |
| 9259 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9260 | sgl->addr_lo = |
| 9261 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9262 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9263 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9264 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9265 | sgl->sge_len = |
| 9266 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9267 | } |
| 9268 | return sglq->sli4_xritag; |
| 9269 | } |
| 9270 | |
| 9271 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9272 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 9273 | * @phba: Pointer to HBA context object. |
| 9274 | * @piocb: Pointer to command iocb. |
| 9275 | * @wqe: Pointer to the work queue entry. |
| 9276 | * |
| 9277 | * This routine converts the iocb command to its Work Queue Entry |
| 9278 | * equivalent. The wqe pointer should not have any fields set when |
| 9279 | * this routine is called because it will memcpy over them. |
| 9280 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9281 | * wqe. |
| 9282 | * |
| 9283 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9284 | **/ |
| 9285 | static int |
| 9286 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9287 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9288 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9289 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9290 | uint8_t ct = 0; |
| 9291 | uint32_t fip; |
| 9292 | uint32_t abort_tag; |
| 9293 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9294 | uint8_t cmnd; |
| 9295 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9296 | uint16_t abrt_iotag; |
| 9297 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9298 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9299 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9300 | int numBdes, i; |
| 9301 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9302 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9303 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9304 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9305 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9306 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9307 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9308 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9309 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9310 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9311 | command_type = ELS_COMMAND_FIP; |
| 9312 | else |
| 9313 | command_type = ELS_COMMAND_NON_FIP; |
| 9314 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9315 | if (phba->fcp_embed_io) |
| 9316 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9317 | /* Some of the fields are in the right position already */ |
| 9318 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9319 | if (iocbq->iocb.ulpCommand != CMD_SEND_FRAME) { |
| 9320 | /* The ct field has moved so reset */ |
| 9321 | wqe->generic.wqe_com.word7 = 0; |
| 9322 | wqe->generic.wqe_com.word10 = 0; |
| 9323 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9324 | |
| 9325 | abort_tag = (uint32_t) iocbq->iotag; |
| 9326 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9327 | /* words0-2 bpl convert bde */ |
| 9328 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9329 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9330 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9331 | bpl = (struct ulp_bde64 *) |
| 9332 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9333 | if (!bpl) |
| 9334 | return IOCB_ERROR; |
| 9335 | |
| 9336 | /* Should already be byte swapped. */ |
| 9337 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9338 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9339 | /* swap the size field back to the cpu so we |
| 9340 | * can assign it to the sgl. |
| 9341 | */ |
| 9342 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9343 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9344 | total_len = 0; |
| 9345 | for (i = 0; i < numBdes; i++) { |
| 9346 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9347 | total_len += bde.tus.f.bdeSize; |
| 9348 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9349 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9350 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9351 | |
| 9352 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9353 | cmnd = iocbq->iocb.ulpCommand; |
| 9354 | |
| 9355 | switch (iocbq->iocb.ulpCommand) { |
| 9356 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9357 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9358 | ndlp = iocbq->context_un.ndlp; |
| 9359 | else |
| 9360 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9361 | if (!iocbq->iocb.ulpLe) { |
| 9362 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9363 | "2007 Only Limited Edition cmd Format" |
| 9364 | " supported 0x%x\n", |
| 9365 | iocbq->iocb.ulpCommand); |
| 9366 | return IOCB_ERROR; |
| 9367 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9368 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9369 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9370 | /* Els_reguest64 has a TMO */ |
| 9371 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9372 | iocbq->iocb.ulpTimeout); |
| 9373 | /* Need a VF for word 4 set the vf bit*/ |
| 9374 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9375 | /* And a VFID for word 12 */ |
| 9376 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9377 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9378 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9379 | iocbq->iocb.ulpContext); |
| 9380 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9381 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9382 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9383 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9384 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9385 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9386 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9387 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9388 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9389 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9390 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9391 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9392 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9393 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9394 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9395 | *pcmd == ELS_CMD_PLOGI)) { |
| 9396 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9397 | bf_set(els_req64_sid, &wqe->els_req, |
| 9398 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9399 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9400 | !(phba->fc_topology == |
| 9401 | LPFC_TOPOLOGY_LOOP)) |
| 9402 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9403 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9404 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9405 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9406 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9407 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9408 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9409 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9410 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9411 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9412 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9413 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9414 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9415 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9416 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9417 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9418 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9419 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9420 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9421 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9422 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9423 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9424 | iocbq->iocb.un.ulpWord[3]); |
| 9425 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9426 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9427 | /* The entire sequence is transmitted for this IOCB */ |
| 9428 | xmit_len = total_len; |
| 9429 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9430 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9431 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9432 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9433 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9434 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9435 | /* word4 relative_offset memcpy */ |
| 9436 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9437 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9438 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9439 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9440 | LPFC_WQE_IOD_WRITE); |
| 9441 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9442 | LPFC_WQE_LENLOC_WORD12); |
| 9443 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9444 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9445 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9446 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9447 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9448 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9449 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9450 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9451 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9452 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9453 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9454 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9455 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9456 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9457 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9458 | LPFC_WQE_LENLOC_WORD3); |
| 9459 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9460 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9461 | case CMD_FCP_IWRITE64_CR: |
| 9462 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9463 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9464 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9465 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9466 | xmit_len + sizeof(struct fcp_rsp)); |
| 9467 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9468 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9469 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9470 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9471 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9472 | iocbq->iocb.ulpFCP2Rcvy); |
| 9473 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9474 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9475 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9476 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9477 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9478 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9479 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9480 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9481 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9482 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9483 | if (iocbq->priority) { |
| 9484 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9485 | (iocbq->priority << 1)); |
| 9486 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9487 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9488 | (phba->cfg_XLanePriority << 1)); |
| 9489 | } |
| 9490 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9491 | /* Note, word 10 is already initialized to 0 */ |
| 9492 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9493 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9494 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9495 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9496 | else |
| 9497 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9498 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9499 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9500 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9501 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9502 | struct fcp_cmnd *fcp_cmnd; |
| 9503 | uint32_t *ptr; |
| 9504 | |
| 9505 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9506 | |
| 9507 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9508 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9509 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9510 | |
| 9511 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9512 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9513 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9514 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9515 | wqe->generic.bde.addrHigh = 0; |
| 9516 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9517 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9518 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9519 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9520 | |
| 9521 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9522 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9523 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9524 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9525 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9526 | case CMD_FCP_IREAD64_CR: |
| 9527 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9528 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9529 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9530 | xmit_len + sizeof(struct fcp_rsp)); |
| 9531 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9532 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9533 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9534 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9535 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9536 | iocbq->iocb.ulpFCP2Rcvy); |
| 9537 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9538 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9539 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9540 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9541 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9542 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9543 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9544 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9545 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9546 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9547 | if (iocbq->priority) { |
| 9548 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9549 | (iocbq->priority << 1)); |
| 9550 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9551 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9552 | (phba->cfg_XLanePriority << 1)); |
| 9553 | } |
| 9554 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9555 | /* Note, word 10 is already initialized to 0 */ |
| 9556 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9557 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9558 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9559 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9560 | else |
| 9561 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9562 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9563 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9564 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9565 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9566 | struct fcp_cmnd *fcp_cmnd; |
| 9567 | uint32_t *ptr; |
| 9568 | |
| 9569 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9570 | |
| 9571 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9572 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9573 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9574 | |
| 9575 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9576 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9577 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9578 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9579 | wqe->generic.bde.addrHigh = 0; |
| 9580 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9581 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9582 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9583 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9584 | |
| 9585 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9586 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9587 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9588 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9589 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9590 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9591 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9592 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9593 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9594 | xmit_len + sizeof(struct fcp_rsp)); |
| 9595 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9596 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9597 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9598 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9599 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9600 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9601 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9602 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9603 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9604 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9605 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9606 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9607 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9608 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9609 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9610 | if (iocbq->priority) { |
| 9611 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9612 | (iocbq->priority << 1)); |
| 9613 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9614 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9615 | (phba->cfg_XLanePriority << 1)); |
| 9616 | } |
| 9617 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9618 | /* Note, word 10 is already initialized to 0 */ |
| 9619 | |
| 9620 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9621 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9622 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9623 | struct fcp_cmnd *fcp_cmnd; |
| 9624 | uint32_t *ptr; |
| 9625 | |
| 9626 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9627 | |
| 9628 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9629 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9630 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9631 | |
| 9632 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9633 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9634 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9635 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9636 | wqe->generic.bde.addrHigh = 0; |
| 9637 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9638 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9639 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9640 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9641 | |
| 9642 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9643 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9644 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9645 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9646 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9647 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9648 | /* For this command calculate the xmit length of the |
| 9649 | * request bde. |
| 9650 | */ |
| 9651 | xmit_len = 0; |
| 9652 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9653 | sizeof(struct ulp_bde64); |
| 9654 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9655 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9656 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9657 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9658 | xmit_len += bde.tus.f.bdeSize; |
| 9659 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9660 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9661 | wqe->gen_req.request_payload_len = xmit_len; |
| 9662 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9663 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9664 | /* word6 context tag copied in memcpy */ |
| 9665 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9666 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9667 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9668 | "2015 Invalid CT %x command 0x%x\n", |
| 9669 | ct, iocbq->iocb.ulpCommand); |
| 9670 | return IOCB_ERROR; |
| 9671 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9672 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9673 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9674 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9675 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9676 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9677 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9678 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9679 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9680 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9681 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9682 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9683 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9684 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9685 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9686 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9687 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9688 | /* word4 */ |
| 9689 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9690 | /* word5 iocb=rsvd wge=did */ |
| 9691 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9692 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9693 | |
| 9694 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9695 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9696 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9697 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9698 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9699 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9700 | iocbq->vport->fc_myDID); |
| 9701 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9702 | bf_set(wqe_els_did, |
| 9703 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9704 | } |
| 9705 | } |
| 9706 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9707 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9708 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9709 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9710 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9711 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9712 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9713 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9714 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9715 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9716 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9717 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9718 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9719 | LPFC_WQE_LENLOC_WORD3); |
| 9720 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9721 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9722 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9723 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9724 | iocbq->context2)->virt); |
| 9725 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9726 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9727 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9728 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9729 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9730 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9731 | phba->vpi_ids[phba->pport->vpi]); |
| 9732 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9733 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9734 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9735 | case CMD_CLOSE_XRI_CN: |
| 9736 | case CMD_ABORT_XRI_CN: |
| 9737 | case CMD_ABORT_XRI_CX: |
| 9738 | /* words 0-2 memcpy should be 0 rserved */ |
| 9739 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9740 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9741 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9742 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9743 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9744 | } else |
| 9745 | fip = 0; |
| 9746 | |
| 9747 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9748 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9749 | * The link is down, or the command was ELS_FIP |
| 9750 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9751 | * on the wire. |
| 9752 | */ |
| 9753 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9754 | else |
| 9755 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9756 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9757 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9758 | wqe->abort_cmd.rsrvd5 = 0; |
| 9759 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9760 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9761 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9762 | /* |
| 9763 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9764 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9765 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9766 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9767 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9768 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9769 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9770 | cmnd = CMD_ABORT_XRI_CX; |
| 9771 | command_type = OTHER_COMMAND; |
| 9772 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9773 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9774 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9775 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9776 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9777 | * we re-construct this WQE here based on information in |
| 9778 | * iocbq from scratch. |
| 9779 | */ |
| 9780 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9781 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9782 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9783 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9784 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9785 | LPFC_ABTS_UNSOL_INT) { |
| 9786 | /* ABTS sent by initiator to CT exchange, the |
| 9787 | * RX_ID field will be filled with the newly |
| 9788 | * allocated responder XRI. |
| 9789 | */ |
| 9790 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9791 | iocbq->sli4_xritag); |
| 9792 | } else { |
| 9793 | /* ABTS sent by responder to CT exchange, the |
| 9794 | * RX_ID field will be filled with the responder |
| 9795 | * RX_ID from ABTS. |
| 9796 | */ |
| 9797 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9798 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9799 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9800 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9801 | 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] | 9802 | |
| 9803 | /* Use CT=VPI */ |
| 9804 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9805 | ndlp->nlp_DID); |
| 9806 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9807 | iocbq->iocb.ulpContext); |
| 9808 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9809 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9810 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9811 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9812 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9813 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9814 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9815 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9816 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9817 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9818 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9819 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9820 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9821 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9822 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9823 | } |
| 9824 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9825 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9826 | case CMD_SEND_FRAME: |
| 9827 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9828 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9829 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9830 | case CMD_XRI_ABORTED_CX: |
| 9831 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9832 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9833 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9834 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9835 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9836 | default: |
| 9837 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9838 | "2014 Invalid command 0x%x\n", |
| 9839 | iocbq->iocb.ulpCommand); |
| 9840 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9841 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9842 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9843 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9844 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9845 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9846 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9847 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9848 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9849 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9850 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9851 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9852 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9853 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9854 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9855 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9856 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9857 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9858 | 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] | 9859 | return 0; |
| 9860 | } |
| 9861 | |
| 9862 | /** |
| 9863 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9864 | * @phba: Pointer to HBA context object. |
| 9865 | * @ring_number: SLI ring number to issue iocb on. |
| 9866 | * @piocb: Pointer to command iocb. |
| 9867 | * @flag: Flag indicating if this command can be put into txq. |
| 9868 | * |
| 9869 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9870 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9871 | * |
| 9872 | * This function is called with hbalock held. The function will return success |
| 9873 | * after it successfully submit the iocb to firmware or after adding to the |
| 9874 | * txq. |
| 9875 | **/ |
| 9876 | static int |
| 9877 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9878 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9879 | { |
| 9880 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9881 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9882 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9883 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9884 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9885 | /* Get the WQ */ |
| 9886 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9887 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9888 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].fcp_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9889 | } else { |
| 9890 | wq = phba->sli4_hba.els_wq; |
| 9891 | } |
| 9892 | |
| 9893 | /* Get corresponding ring */ |
| 9894 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9895 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9896 | /* |
| 9897 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9898 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9899 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9900 | lockdep_assert_held(&phba->hbalock); |
| 9901 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9902 | if (piocb->sli4_xritag == NO_XRI) { |
| 9903 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9904 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9905 | sglq = NULL; |
| 9906 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9907 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9908 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9909 | __lpfc_sli_ringtx_put(phba, |
| 9910 | pring, piocb); |
| 9911 | return IOCB_SUCCESS; |
| 9912 | } else { |
| 9913 | return IOCB_BUSY; |
| 9914 | } |
| 9915 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9916 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9917 | if (!sglq) { |
| 9918 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9919 | __lpfc_sli_ringtx_put(phba, |
| 9920 | pring, |
| 9921 | piocb); |
| 9922 | return IOCB_SUCCESS; |
| 9923 | } else |
| 9924 | return IOCB_BUSY; |
| 9925 | } |
| 9926 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9927 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9928 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9929 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9930 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9931 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9932 | /* |
| 9933 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9934 | * sglq is on the active list |
| 9935 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9936 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9937 | if (!sglq) |
| 9938 | return IOCB_ERROR; |
| 9939 | } |
| 9940 | |
| 9941 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9942 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9943 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9944 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9945 | return IOCB_ERROR; |
| 9946 | } |
| 9947 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9948 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9949 | return IOCB_ERROR; |
| 9950 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9951 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9952 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9953 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9954 | |
| 9955 | return 0; |
| 9956 | } |
| 9957 | |
| 9958 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9959 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9960 | * |
| 9961 | * This routine wraps the actual lockless version for issusing IOCB function |
| 9962 | * pointer from the lpfc_hba struct. |
| 9963 | * |
| 9964 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9965 | * IOCB_ERROR - Error |
| 9966 | * IOCB_SUCCESS - Success |
| 9967 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9968 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9969 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9970 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 9971 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9972 | { |
| 9973 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9974 | } |
| 9975 | |
| 9976 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9977 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9978 | * @phba: The hba struct for which this call is being executed. |
| 9979 | * @dev_grp: The HBA PCI-Device group number. |
| 9980 | * |
| 9981 | * This routine sets up the SLI interface API function jump table in @phba |
| 9982 | * struct. |
| 9983 | * Returns: 0 - success, -ENODEV - failure. |
| 9984 | **/ |
| 9985 | int |
| 9986 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9987 | { |
| 9988 | |
| 9989 | switch (dev_grp) { |
| 9990 | case LPFC_PCI_DEV_LP: |
| 9991 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 9992 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 9993 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9994 | case LPFC_PCI_DEV_OC: |
| 9995 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 9996 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 9997 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9998 | default: |
| 9999 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10000 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 10001 | dev_grp); |
| 10002 | return -ENODEV; |
| 10003 | break; |
| 10004 | } |
| 10005 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 10006 | return 0; |
| 10007 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10008 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10009 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10010 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10011 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10012 | * @piocb: Pointer to command iocb. |
| 10013 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10014 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 10015 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10016 | * 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] | 10017 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10018 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10019 | struct lpfc_sli_ring * |
| 10020 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10021 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10022 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10023 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10024 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10025 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 10026 | return NULL; |
| 10027 | /* |
| 10028 | * for abort iocb hba_wqidx should already |
| 10029 | * be setup based on what work queue we used. |
| 10030 | */ |
| 10031 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10032 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 10033 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10034 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10035 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].fcp_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10036 | } else { |
| 10037 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10038 | return NULL; |
| 10039 | piocb->hba_wqidx = 0; |
| 10040 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10041 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10042 | } |
| 10043 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10044 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10045 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10046 | * @phba: Pointer to HBA context object. |
| 10047 | * @pring: Pointer to driver SLI ring object. |
| 10048 | * @piocb: Pointer to command iocb. |
| 10049 | * @flag: Flag indicating if this command can be put into txq. |
| 10050 | * |
| 10051 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10052 | * function. This function gets the hbalock and calls |
| 10053 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10054 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10055 | * functions which do not hold hbalock. |
| 10056 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10057 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10058 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10059 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10060 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10061 | struct lpfc_sli_ring *pring; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10062 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 10063 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10064 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10065 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10066 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10067 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10068 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10069 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10070 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10071 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10072 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10073 | } else { |
| 10074 | /* For now, SLI2/3 will still use hbalock */ |
| 10075 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10076 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10077 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10078 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10079 | return rc; |
| 10080 | } |
| 10081 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10082 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10083 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10084 | * @phba: Pointer to HBA context object. |
| 10085 | * |
| 10086 | * This function is called while driver attaches with the |
| 10087 | * HBA to setup the extra ring. The extra ring is used |
| 10088 | * only when driver needs to support target mode functionality |
| 10089 | * or IP over FC functionalities. |
| 10090 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10091 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10092 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10093 | static int |
| 10094 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10095 | { |
| 10096 | struct lpfc_sli *psli; |
| 10097 | struct lpfc_sli_ring *pring; |
| 10098 | |
| 10099 | psli = &phba->sli; |
| 10100 | |
| 10101 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10102 | |
| 10103 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10104 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10105 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10106 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10107 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10108 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10109 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10110 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10111 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10112 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10113 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10114 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10115 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10116 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10117 | |
| 10118 | /* Setup default profile for this ring */ |
| 10119 | pring->iotag_max = 4096; |
| 10120 | pring->num_mask = 1; |
| 10121 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10122 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10123 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10124 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10125 | return 0; |
| 10126 | } |
| 10127 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10128 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10129 | * @phba: Pointer to HBA context object. |
| 10130 | * @iocbq: Pointer to iocb object. |
| 10131 | * |
| 10132 | * The async_event handler calls this routine when it receives |
| 10133 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10134 | * this event when an Abort Sequence request to an rport fails |
| 10135 | * twice in succession. The abort could be originated by the |
| 10136 | * driver or by the port. The ABTS could have been for an ELS |
| 10137 | * or FCP IO. The port only generates this event when an ABTS |
| 10138 | * fails to complete after one retry. |
| 10139 | */ |
| 10140 | static void |
| 10141 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10142 | struct lpfc_iocbq *iocbq) |
| 10143 | { |
| 10144 | struct lpfc_nodelist *ndlp = NULL; |
| 10145 | uint16_t rpi = 0, vpi = 0; |
| 10146 | struct lpfc_vport *vport = NULL; |
| 10147 | |
| 10148 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10149 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10150 | rpi = iocbq->iocb.ulpContext; |
| 10151 | |
| 10152 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10153 | "3092 Port generated ABTS async event " |
| 10154 | "on vpi %d rpi %d status 0x%x\n", |
| 10155 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10156 | |
| 10157 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10158 | if (!vport) |
| 10159 | goto err_exit; |
| 10160 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 10161 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 10162 | goto err_exit; |
| 10163 | |
| 10164 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10165 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10166 | return; |
| 10167 | |
| 10168 | err_exit: |
| 10169 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10170 | "3095 Event Context not found, no " |
| 10171 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10172 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10173 | vpi, rpi); |
| 10174 | } |
| 10175 | |
| 10176 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10177 | * @phba: pointer to HBA context object. |
| 10178 | * @ndlp: nodelist pointer for the impacted rport. |
| 10179 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10180 | * |
| 10181 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10182 | * port. The port generates this event when an abort exchange request to an |
| 10183 | * rport fails twice in succession with no reply. The abort could be originated |
| 10184 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10185 | */ |
| 10186 | void |
| 10187 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10188 | struct lpfc_nodelist *ndlp, |
| 10189 | struct sli4_wcqe_xri_aborted *axri) |
| 10190 | { |
| 10191 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10192 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10193 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10194 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10195 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10196 | "3115 Node Context not found, driver " |
| 10197 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10198 | return; |
| 10199 | } |
| 10200 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10201 | vport = ndlp->vport; |
| 10202 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10203 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10204 | "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] | 10205 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10206 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10207 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10208 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10209 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10210 | /* |
| 10211 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10212 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10213 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10214 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10215 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10216 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10217 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10218 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10219 | } |
| 10220 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10221 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10222 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10223 | * @phba: Pointer to HBA context object. |
| 10224 | * @pring: Pointer to driver SLI ring object. |
| 10225 | * @iocbq: Pointer to iocb object. |
| 10226 | * |
| 10227 | * This function is called by the slow ring event handler |
| 10228 | * function when there is an ASYNC event iocb in the ring. |
| 10229 | * This function is called with no lock held. |
| 10230 | * Currently this function handles only temperature related |
| 10231 | * ASYNC events. The function decodes the temperature sensor |
| 10232 | * event message and posts events for the management applications. |
| 10233 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10234 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10235 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10236 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10237 | { |
| 10238 | IOCB_t *icmd; |
| 10239 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10240 | struct temp_event temp_event_data; |
| 10241 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10242 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10243 | |
| 10244 | icmd = &iocbq->iocb; |
| 10245 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10246 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10247 | switch (evt_code) { |
| 10248 | case ASYNC_TEMP_WARN: |
| 10249 | case ASYNC_TEMP_SAFE: |
| 10250 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10251 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10252 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10253 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 10254 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10255 | "0347 Adapter is very hot, please take " |
| 10256 | "corrective action. temperature : %d Celsius\n", |
| 10257 | (uint32_t) icmd->ulpContext); |
| 10258 | } else { |
| 10259 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 10260 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10261 | "0340 Adapter temperature is OK now. " |
| 10262 | "temperature : %d Celsius\n", |
| 10263 | (uint32_t) icmd->ulpContext); |
| 10264 | } |
| 10265 | |
| 10266 | /* Send temperature change event to applications */ |
| 10267 | shost = lpfc_shost_from_vport(phba->pport); |
| 10268 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10269 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10270 | LPFC_NL_VENDOR_ID); |
| 10271 | break; |
| 10272 | case ASYNC_STATUS_CN: |
| 10273 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10274 | break; |
| 10275 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10276 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10277 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10278 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10279 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10280 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10281 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10282 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10283 | "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] | 10284 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10285 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10286 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10287 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10288 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10289 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10290 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10291 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10292 | } |
| 10293 | |
| 10294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10295 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10296 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10297 | * @phba: Pointer to HBA context object. |
| 10298 | * |
| 10299 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10300 | * number of iocbs per ring and iotags. This function is |
| 10301 | * called while driver attach to the HBA and before the |
| 10302 | * interrupts are enabled. So there is no need for locking. |
| 10303 | * |
| 10304 | * This function always returns 0. |
| 10305 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10306 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10307 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10308 | { |
| 10309 | struct lpfc_sli_ring *pring; |
| 10310 | |
| 10311 | pring = phba->sli4_hba.els_wq->pring; |
| 10312 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10313 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10314 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10315 | pring->prt[0].type = FC_TYPE_ELS; |
| 10316 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10317 | lpfc_els_unsol_event; |
| 10318 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10319 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10320 | pring->prt[1].type = FC_TYPE_ELS; |
| 10321 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10322 | lpfc_els_unsol_event; |
| 10323 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10324 | /* NameServer Inquiry */ |
| 10325 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10326 | /* NameServer */ |
| 10327 | pring->prt[2].type = FC_TYPE_CT; |
| 10328 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10329 | lpfc_ct_unsol_event; |
| 10330 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10331 | /* NameServer response */ |
| 10332 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10333 | /* NameServer */ |
| 10334 | pring->prt[3].type = FC_TYPE_CT; |
| 10335 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10336 | lpfc_ct_unsol_event; |
| 10337 | return 0; |
| 10338 | } |
| 10339 | |
| 10340 | /** |
| 10341 | * lpfc_sli_setup - SLI ring setup function |
| 10342 | * @phba: Pointer to HBA context object. |
| 10343 | * |
| 10344 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10345 | * number of iocbs per ring and iotags. This function is |
| 10346 | * called while driver attach to the HBA and before the |
| 10347 | * interrupts are enabled. So there is no need for locking. |
| 10348 | * |
| 10349 | * This function always returns 0. SLI3 only. |
| 10350 | **/ |
| 10351 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10352 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10353 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10354 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10355 | struct lpfc_sli *psli = &phba->sli; |
| 10356 | struct lpfc_sli_ring *pring; |
| 10357 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10358 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10359 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10360 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10361 | psli->iocbq_lookup = NULL; |
| 10362 | psli->iocbq_lookup_len = 0; |
| 10363 | psli->last_iotag = 0; |
| 10364 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10365 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10366 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10367 | switch (i) { |
| 10368 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10369 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10370 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10371 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10372 | pring->sli.sli3.numCiocb += |
| 10373 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10374 | pring->sli.sli3.numRiocb += |
| 10375 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10376 | pring->sli.sli3.numCiocb += |
| 10377 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10378 | pring->sli.sli3.numRiocb += |
| 10379 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10380 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10381 | SLI3_IOCB_CMD_SIZE : |
| 10382 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10383 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10384 | SLI3_IOCB_RSP_SIZE : |
| 10385 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10386 | pring->iotag_ctr = 0; |
| 10387 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10388 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10389 | pring->fast_iotag = pring->iotag_max; |
| 10390 | pring->num_mask = 0; |
| 10391 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10392 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10393 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10394 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10395 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10396 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10397 | SLI3_IOCB_CMD_SIZE : |
| 10398 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10399 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10400 | SLI3_IOCB_RSP_SIZE : |
| 10401 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10402 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10403 | pring->num_mask = 0; |
| 10404 | break; |
| 10405 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10406 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10407 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10408 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10409 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10410 | SLI3_IOCB_CMD_SIZE : |
| 10411 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10412 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10413 | SLI3_IOCB_RSP_SIZE : |
| 10414 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10415 | pring->fast_iotag = 0; |
| 10416 | pring->iotag_ctr = 0; |
| 10417 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10418 | pring->lpfc_sli_rcv_async_status = |
| 10419 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10420 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10421 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10422 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10423 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10424 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10425 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10426 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10427 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10428 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10429 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10430 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10431 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10432 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10433 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10434 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10435 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10436 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10437 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10438 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10439 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10440 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10441 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10442 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10443 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10444 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10445 | break; |
| 10446 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10447 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10448 | pring->sli.sli3.sizeCiocb) + |
| 10449 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10450 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10451 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10452 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10453 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10454 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10455 | phba->brd_no, totiocbsize, |
| 10456 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10457 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10458 | if (phba->cfg_multi_ring_support == 2) |
| 10459 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10460 | |
| 10461 | return 0; |
| 10462 | } |
| 10463 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10464 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10465 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10466 | * @phba: Pointer to HBA context object. |
| 10467 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10468 | * 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] | 10469 | * ring. This function also initializes ring indices of each ring. |
| 10470 | * This function is called during the initialization of the SLI |
| 10471 | * interface of an HBA. |
| 10472 | * This function is called with no lock held and always returns |
| 10473 | * 1. |
| 10474 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10475 | void |
| 10476 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10477 | { |
| 10478 | struct lpfc_sli *psli; |
| 10479 | struct lpfc_sli_ring *pring; |
| 10480 | int i; |
| 10481 | |
| 10482 | psli = &phba->sli; |
| 10483 | spin_lock_irq(&phba->hbalock); |
| 10484 | INIT_LIST_HEAD(&psli->mboxq); |
| 10485 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10486 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10487 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 10488 | pring = phba->sli4_hba.hdwq[i].fcp_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10489 | pring->flag = 0; |
| 10490 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10491 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10492 | INIT_LIST_HEAD(&pring->txq); |
| 10493 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10494 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10495 | spin_lock_init(&pring->ring_lock); |
| 10496 | } |
| 10497 | pring = phba->sli4_hba.els_wq->pring; |
| 10498 | pring->flag = 0; |
| 10499 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10500 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10501 | INIT_LIST_HEAD(&pring->txq); |
| 10502 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10503 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10504 | spin_lock_init(&pring->ring_lock); |
| 10505 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10506 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 10507 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 10508 | pring = phba->sli4_hba.hdwq[i].nvme_wq->pring; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10509 | pring->flag = 0; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10510 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10511 | pring->txcmplq_cnt = 0; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10512 | INIT_LIST_HEAD(&pring->txq); |
| 10513 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10514 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10515 | spin_lock_init(&pring->ring_lock); |
| 10516 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10517 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10518 | pring->flag = 0; |
| 10519 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10520 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10521 | INIT_LIST_HEAD(&pring->txq); |
| 10522 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10523 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10524 | spin_lock_init(&pring->ring_lock); |
| 10525 | } |
| 10526 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10527 | spin_unlock_irq(&phba->hbalock); |
| 10528 | } |
| 10529 | |
| 10530 | /** |
| 10531 | * lpfc_sli_queue_init - Queue initialization function |
| 10532 | * @phba: Pointer to HBA context object. |
| 10533 | * |
| 10534 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10535 | * ring. This function also initializes ring indices of each ring. |
| 10536 | * This function is called during the initialization of the SLI |
| 10537 | * interface of an HBA. |
| 10538 | * This function is called with no lock held and always returns |
| 10539 | * 1. |
| 10540 | **/ |
| 10541 | void |
| 10542 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10543 | { |
| 10544 | struct lpfc_sli *psli; |
| 10545 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10546 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10547 | |
| 10548 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10549 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10550 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10551 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10552 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10553 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10554 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10555 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10556 | pring->sli.sli3.next_cmdidx = 0; |
| 10557 | pring->sli.sli3.local_getidx = 0; |
| 10558 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10559 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10560 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10561 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10562 | pring->flag = 0; |
| 10563 | INIT_LIST_HEAD(&pring->txq); |
| 10564 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10565 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10566 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10567 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10568 | } |
| 10569 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10570 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10571 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10572 | * @phba: Pointer to HBA context object. |
| 10573 | * |
| 10574 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10575 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10576 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10577 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10578 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10579 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10580 | * pending mailbox command queue from the various clients must be stopped; |
| 10581 | * either the HBA is in a state that it will never works on the outstanding |
| 10582 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10583 | * mailbox command has been completed. |
| 10584 | **/ |
| 10585 | static void |
| 10586 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10587 | { |
| 10588 | LIST_HEAD(completions); |
| 10589 | struct lpfc_sli *psli = &phba->sli; |
| 10590 | LPFC_MBOXQ_t *pmb; |
| 10591 | unsigned long iflag; |
| 10592 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10593 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10594 | local_bh_disable(); |
| 10595 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10596 | /* Flush all the mailbox commands in the mbox system */ |
| 10597 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10598 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10599 | /* The pending mailbox command queue */ |
| 10600 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10601 | /* The outstanding active mailbox command */ |
| 10602 | if (psli->mbox_active) { |
| 10603 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10604 | psli->mbox_active = NULL; |
| 10605 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10606 | } |
| 10607 | /* The completed mailbox command queue */ |
| 10608 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10609 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10610 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10611 | /* Enable softirqs again, done with phba->hbalock */ |
| 10612 | local_bh_enable(); |
| 10613 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10614 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10615 | while (!list_empty(&completions)) { |
| 10616 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10617 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10618 | if (pmb->mbox_cmpl) |
| 10619 | pmb->mbox_cmpl(phba, pmb); |
| 10620 | } |
| 10621 | } |
| 10622 | |
| 10623 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10624 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10625 | * @vport: Pointer to virtual port object. |
| 10626 | * |
| 10627 | * lpfc_sli_host_down is called to clean up the resources |
| 10628 | * associated with a vport before destroying virtual |
| 10629 | * port data structures. |
| 10630 | * This function does following operations: |
| 10631 | * - Free discovery resources associated with this virtual |
| 10632 | * port. |
| 10633 | * - Free iocbs associated with this virtual port in |
| 10634 | * the txq. |
| 10635 | * - Send abort for all iocb commands associated with this |
| 10636 | * vport in txcmplq. |
| 10637 | * |
| 10638 | * This function is called with no lock held and always returns 1. |
| 10639 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10640 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10641 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10642 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10643 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10644 | struct lpfc_hba *phba = vport->phba; |
| 10645 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10646 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10647 | struct lpfc_sli_ring *pring; |
| 10648 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10649 | int i; |
| 10650 | unsigned long flags = 0; |
| 10651 | uint16_t prev_pring_flag; |
| 10652 | |
| 10653 | lpfc_cleanup_discovery_resources(vport); |
| 10654 | |
| 10655 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10656 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10657 | /* |
| 10658 | * Error everything on the txq since these iocbs |
| 10659 | * have not been given to the FW yet. |
| 10660 | * Also issue ABTS for everything on the txcmplq |
| 10661 | */ |
| 10662 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10663 | for (i = 0; i < psli->num_rings; i++) { |
| 10664 | pring = &psli->sli3_ring[i]; |
| 10665 | prev_pring_flag = pring->flag; |
| 10666 | /* Only slow rings */ |
| 10667 | if (pring->ringno == LPFC_ELS_RING) { |
| 10668 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10669 | /* Set the lpfc data pending flag */ |
| 10670 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10671 | } |
| 10672 | list_for_each_entry_safe(iocb, next_iocb, |
| 10673 | &pring->txq, list) { |
| 10674 | if (iocb->vport != vport) |
| 10675 | continue; |
| 10676 | list_move_tail(&iocb->list, &completions); |
| 10677 | } |
| 10678 | list_for_each_entry_safe(iocb, next_iocb, |
| 10679 | &pring->txcmplq, list) { |
| 10680 | if (iocb->vport != vport) |
| 10681 | continue; |
| 10682 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10683 | } |
| 10684 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10685 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10686 | } else { |
| 10687 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10688 | pring = qp->pring; |
| 10689 | if (!pring) |
| 10690 | continue; |
| 10691 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10692 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10693 | /* Set the lpfc data pending flag */ |
| 10694 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10695 | } |
| 10696 | prev_pring_flag = pring->flag; |
| 10697 | spin_lock_irq(&pring->ring_lock); |
| 10698 | list_for_each_entry_safe(iocb, next_iocb, |
| 10699 | &pring->txq, list) { |
| 10700 | if (iocb->vport != vport) |
| 10701 | continue; |
| 10702 | list_move_tail(&iocb->list, &completions); |
| 10703 | } |
| 10704 | spin_unlock_irq(&pring->ring_lock); |
| 10705 | list_for_each_entry_safe(iocb, next_iocb, |
| 10706 | &pring->txcmplq, list) { |
| 10707 | if (iocb->vport != vport) |
| 10708 | continue; |
| 10709 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10710 | } |
| 10711 | pring->flag = prev_pring_flag; |
| 10712 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10713 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10714 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10715 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10716 | /* Cancel all the IOCBs from the completions list */ |
| 10717 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10718 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10719 | return 1; |
| 10720 | } |
| 10721 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10722 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10723 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10724 | * @phba: Pointer to HBA context object. |
| 10725 | * |
| 10726 | * This function cleans up all iocb, buffers, mailbox commands |
| 10727 | * while shutting down the HBA. This function is called with no |
| 10728 | * lock held and always returns 1. |
| 10729 | * This function does the following to cleanup driver resources: |
| 10730 | * - Free discovery resources for each virtual port |
| 10731 | * - Cleanup any pending fabric iocbs |
| 10732 | * - Iterate through the iocb txq and free each entry |
| 10733 | * in the list. |
| 10734 | * - Free up any buffer posted to the HBA |
| 10735 | * - Free mailbox commands in the mailbox queue. |
| 10736 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10737 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10738 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10739 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10740 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10741 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10742 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10743 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10744 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10745 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10746 | int i; |
| 10747 | |
| 10748 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10749 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10750 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10751 | lpfc_hba_down_prep(phba); |
| 10752 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10753 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10754 | local_bh_disable(); |
| 10755 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10756 | lpfc_fabric_abort_hba(phba); |
| 10757 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10758 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10759 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10760 | /* |
| 10761 | * Error everything on the txq since these iocbs |
| 10762 | * have not been given to the FW yet. |
| 10763 | */ |
| 10764 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10765 | for (i = 0; i < psli->num_rings; i++) { |
| 10766 | pring = &psli->sli3_ring[i]; |
| 10767 | /* Only slow rings */ |
| 10768 | if (pring->ringno == LPFC_ELS_RING) { |
| 10769 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10770 | /* Set the lpfc data pending flag */ |
| 10771 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10772 | } |
| 10773 | list_splice_init(&pring->txq, &completions); |
| 10774 | } |
| 10775 | } else { |
| 10776 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10777 | pring = qp->pring; |
| 10778 | if (!pring) |
| 10779 | continue; |
| 10780 | spin_lock_irq(&pring->ring_lock); |
| 10781 | list_splice_init(&pring->txq, &completions); |
| 10782 | spin_unlock_irq(&pring->ring_lock); |
| 10783 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10784 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10785 | /* Set the lpfc data pending flag */ |
| 10786 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10787 | } |
| 10788 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10789 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10790 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10791 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10792 | /* Cancel all the IOCBs from the completions list */ |
| 10793 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10794 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10795 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10796 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10797 | list_splice_init(&phba->elsbuf, &completions); |
| 10798 | phba->elsbuf_cnt = 0; |
| 10799 | phba->elsbuf_prev_cnt = 0; |
| 10800 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10801 | |
| 10802 | while (!list_empty(&completions)) { |
| 10803 | list_remove_head(&completions, buf_ptr, |
| 10804 | struct lpfc_dmabuf, list); |
| 10805 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10806 | kfree(buf_ptr); |
| 10807 | } |
| 10808 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10809 | /* Enable softirqs again, done with phba->hbalock */ |
| 10810 | local_bh_enable(); |
| 10811 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10812 | /* Return any active mbox cmds */ |
| 10813 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10814 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10815 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10816 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10817 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10818 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10819 | return 1; |
| 10820 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10821 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10822 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10823 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10824 | * @srcp: Source memory pointer. |
| 10825 | * @destp: Destination memory pointer. |
| 10826 | * @cnt: Number of words required to be copied. |
| 10827 | * |
| 10828 | * This function is used for copying data between driver memory |
| 10829 | * and the SLI memory. This function also changes the endianness |
| 10830 | * of each word if native endianness is different from SLI |
| 10831 | * endianness. This function can be called with or without |
| 10832 | * lock. |
| 10833 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10834 | void |
| 10835 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10836 | { |
| 10837 | uint32_t *src = srcp; |
| 10838 | uint32_t *dest = destp; |
| 10839 | uint32_t ldata; |
| 10840 | int i; |
| 10841 | |
| 10842 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10843 | ldata = *src; |
| 10844 | ldata = le32_to_cpu(ldata); |
| 10845 | *dest = ldata; |
| 10846 | src++; |
| 10847 | dest++; |
| 10848 | } |
| 10849 | } |
| 10850 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10851 | |
| 10852 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10853 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10854 | * @srcp: Source memory pointer. |
| 10855 | * @destp: Destination memory pointer. |
| 10856 | * @cnt: Number of words required to be copied. |
| 10857 | * |
| 10858 | * This function is used for copying data between a data structure |
| 10859 | * with big endian representation to local endianness. |
| 10860 | * This function can be called with or without lock. |
| 10861 | **/ |
| 10862 | void |
| 10863 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10864 | { |
| 10865 | uint32_t *src = srcp; |
| 10866 | uint32_t *dest = destp; |
| 10867 | uint32_t ldata; |
| 10868 | int i; |
| 10869 | |
| 10870 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10871 | ldata = *src; |
| 10872 | ldata = be32_to_cpu(ldata); |
| 10873 | *dest = ldata; |
| 10874 | src++; |
| 10875 | dest++; |
| 10876 | } |
| 10877 | } |
| 10878 | |
| 10879 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10880 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10881 | * @phba: Pointer to HBA context object. |
| 10882 | * @pring: Pointer to driver SLI ring object. |
| 10883 | * @mp: Pointer to driver buffer object. |
| 10884 | * |
| 10885 | * This function is called with no lock held. |
| 10886 | * It always return zero after adding the buffer to the postbufq |
| 10887 | * buffer list. |
| 10888 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10889 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10890 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10891 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10892 | { |
| 10893 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10894 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10895 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10896 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10897 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10898 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10899 | return 0; |
| 10900 | } |
| 10901 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10902 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10903 | * 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] | 10904 | * @phba: Pointer to HBA context object. |
| 10905 | * |
| 10906 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10907 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10908 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10909 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10910 | * The function returns the allocated tag. The function is called with |
| 10911 | * no locks held. |
| 10912 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10913 | uint32_t |
| 10914 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10915 | { |
| 10916 | spin_lock_irq(&phba->hbalock); |
| 10917 | phba->buffer_tag_count++; |
| 10918 | /* |
| 10919 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10920 | * a tag assigned by HBQ. |
| 10921 | */ |
| 10922 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10923 | spin_unlock_irq(&phba->hbalock); |
| 10924 | return phba->buffer_tag_count; |
| 10925 | } |
| 10926 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10927 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10928 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10929 | * @phba: Pointer to HBA context object. |
| 10930 | * @pring: Pointer to driver SLI ring object. |
| 10931 | * @tag: Buffer tag. |
| 10932 | * |
| 10933 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10934 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10935 | * iocb is posted to the response ring with the tag of the buffer. |
| 10936 | * This function searches the pring->postbufq list using the tag |
| 10937 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10938 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10939 | * buffer is returned to the caller else NULL is returned. |
| 10940 | * This function is called with no lock held. |
| 10941 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10942 | struct lpfc_dmabuf * |
| 10943 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10944 | uint32_t tag) |
| 10945 | { |
| 10946 | struct lpfc_dmabuf *mp, *next_mp; |
| 10947 | struct list_head *slp = &pring->postbufq; |
| 10948 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10949 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10950 | spin_lock_irq(&phba->hbalock); |
| 10951 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10952 | if (mp->buffer_tag == tag) { |
| 10953 | list_del_init(&mp->list); |
| 10954 | pring->postbufq_cnt--; |
| 10955 | spin_unlock_irq(&phba->hbalock); |
| 10956 | return mp; |
| 10957 | } |
| 10958 | } |
| 10959 | |
| 10960 | spin_unlock_irq(&phba->hbalock); |
| 10961 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10962 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10963 | "ring %d Data x%lx x%p x%p x%x\n", |
| 10964 | pring->ringno, (unsigned long) tag, |
| 10965 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10966 | |
| 10967 | return NULL; |
| 10968 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10969 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10970 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10971 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10972 | * @phba: Pointer to HBA context object. |
| 10973 | * @pring: Pointer to driver SLI ring object. |
| 10974 | * @phys: DMA address of the buffer. |
| 10975 | * |
| 10976 | * This function searches the buffer list using the dma_address |
| 10977 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 10978 | * corresponding to the dma_address. The function returns the |
| 10979 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 10980 | * This function is called by the ct and els unsolicited event |
| 10981 | * handlers to get the buffer associated with the unsolicited |
| 10982 | * event. |
| 10983 | * |
| 10984 | * This function is called with no lock held. |
| 10985 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10986 | struct lpfc_dmabuf * |
| 10987 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10988 | dma_addr_t phys) |
| 10989 | { |
| 10990 | struct lpfc_dmabuf *mp, *next_mp; |
| 10991 | struct list_head *slp = &pring->postbufq; |
| 10992 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10993 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10994 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10995 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10996 | if (mp->phys == phys) { |
| 10997 | list_del_init(&mp->list); |
| 10998 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10999 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11000 | return mp; |
| 11001 | } |
| 11002 | } |
| 11003 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11004 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11005 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11006 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11007 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11008 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11009 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11010 | return NULL; |
| 11011 | } |
| 11012 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11014 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11015 | * @phba: Pointer to HBA context object. |
| 11016 | * @cmdiocb: Pointer to driver command iocb object. |
| 11017 | * @rspiocb: Pointer to driver response iocb object. |
| 11018 | * |
| 11019 | * This function is the completion handler for the abort iocbs for |
| 11020 | * ELS commands. This function is called from the ELS ring event |
| 11021 | * handler with no lock held. This function frees memory resources |
| 11022 | * associated with the abort iocb. |
| 11023 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11024 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11025 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11026 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11027 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11028 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11029 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11030 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11031 | |
| 11032 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11033 | |
| 11034 | /* |
| 11035 | * Assume that the port already completed and returned, or |
| 11036 | * will return the iocb. Just Log the message. |
| 11037 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11038 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11039 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11040 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11041 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11042 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11043 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11044 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11045 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11046 | spin_unlock_irq(&phba->hbalock); |
| 11047 | goto release_iocb; |
| 11048 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11049 | if (abort_iotag != 0 && |
| 11050 | abort_iotag <= phba->sli.last_iotag) |
| 11051 | abort_iocb = |
| 11052 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11053 | } else |
| 11054 | /* For sli4 the abort_tag is the XRI, |
| 11055 | * so the abort routine puts the iotag of the iocb |
| 11056 | * being aborted in the context field of the abort |
| 11057 | * IOCB. |
| 11058 | */ |
| 11059 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11060 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11061 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 11062 | "0327 Cannot abort els iocb %p " |
| 11063 | "with tag %x context %x, abort status %x, " |
| 11064 | "abort code %x\n", |
| 11065 | abort_iocb, abort_iotag, abort_context, |
| 11066 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11067 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11068 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11069 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11070 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11071 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11072 | return; |
| 11073 | } |
| 11074 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11075 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11076 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11077 | * @phba: Pointer to HBA context object. |
| 11078 | * @cmdiocb: Pointer to driver command iocb object. |
| 11079 | * @rspiocb: Pointer to driver response iocb object. |
| 11080 | * |
| 11081 | * The function is called from SLI ring event handler with no |
| 11082 | * lock held. This function is the completion handler for ELS commands |
| 11083 | * which are aborted. The function frees memory resources used for |
| 11084 | * the aborted ELS commands. |
| 11085 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11086 | static void |
| 11087 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11088 | struct lpfc_iocbq *rspiocb) |
| 11089 | { |
| 11090 | IOCB_t *irsp = &rspiocb->iocb; |
| 11091 | |
| 11092 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11093 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11094 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11095 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11096 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11097 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11098 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11099 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11100 | else |
| 11101 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11102 | return; |
| 11103 | } |
| 11104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11105 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11106 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11107 | * @phba: Pointer to HBA context object. |
| 11108 | * @pring: Pointer to driver SLI ring object. |
| 11109 | * @cmdiocb: Pointer to driver command iocb object. |
| 11110 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11111 | * This function issues an abort iocb for the provided command iocb down to |
| 11112 | * the port. Other than the case the outstanding command iocb is an abort |
| 11113 | * request, this function issues abort out unconditionally. This function is |
| 11114 | * called with hbalock held. The function returns 0 when it fails due to |
| 11115 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11116 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11117 | static int |
| 11118 | 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] | 11119 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11120 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11121 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11122 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11123 | IOCB_t *icmd = NULL; |
| 11124 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11125 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11126 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11127 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11128 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11129 | lockdep_assert_held(&phba->hbalock); |
| 11130 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11131 | /* |
| 11132 | * There are certain command types we don't want to abort. And we |
| 11133 | * don't want to abort commands that are already in the process of |
| 11134 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11135 | */ |
| 11136 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11137 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11138 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11139 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11140 | return 0; |
| 11141 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11142 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11143 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11144 | if (abtsiocbp == NULL) |
| 11145 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11146 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11147 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11148 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11149 | */ |
| 11150 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11151 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11152 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11153 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11154 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11155 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11156 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11157 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11158 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11159 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11160 | if (pring->ringno == LPFC_ELS_RING) { |
| 11161 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11162 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11163 | } |
| 11164 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11165 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11166 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11167 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11168 | /* 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] | 11169 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11170 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 11171 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11172 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11173 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11174 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11175 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11176 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11177 | else |
| 11178 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11179 | |
| 11180 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11181 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11182 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11183 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11184 | "0339 Abort xri x%x, original iotag x%x, " |
| 11185 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11186 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11187 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11188 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11189 | |
| 11190 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11191 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11192 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11193 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11194 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11195 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11196 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11197 | abtsiocbp, 0); |
| 11198 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11199 | } else { |
| 11200 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11201 | abtsiocbp, 0); |
| 11202 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11203 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11204 | if (retval) |
| 11205 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11206 | |
| 11207 | /* |
| 11208 | * Caller to this routine should check for IOCB_ERROR |
| 11209 | * and handle it properly. This routine no longer removes |
| 11210 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 11211 | */ |
| 11212 | return retval; |
| 11213 | } |
| 11214 | |
| 11215 | /** |
| 11216 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 11217 | * @phba: Pointer to HBA context object. |
| 11218 | * @pring: Pointer to driver SLI ring object. |
| 11219 | * @cmdiocb: Pointer to driver command iocb object. |
| 11220 | * |
| 11221 | * This function issues an abort iocb for the provided command iocb. In case |
| 11222 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11223 | * ring. Instead, the callback function shall be changed to those commands |
| 11224 | * so that nothing happens when them finishes. This function is called with |
| 11225 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 11226 | * request. |
| 11227 | **/ |
| 11228 | int |
| 11229 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11230 | struct lpfc_iocbq *cmdiocb) |
| 11231 | { |
| 11232 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11233 | int retval = IOCB_ERROR; |
| 11234 | IOCB_t *icmd = NULL; |
| 11235 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11236 | lockdep_assert_held(&phba->hbalock); |
| 11237 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11238 | /* |
| 11239 | * There are certain command types we don't want to abort. And we |
| 11240 | * don't want to abort commands that are already in the process of |
| 11241 | * being aborted. |
| 11242 | */ |
| 11243 | icmd = &cmdiocb->iocb; |
| 11244 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11245 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11246 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11247 | return 0; |
| 11248 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 11249 | if (!pring) { |
| 11250 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11251 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11252 | else |
| 11253 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11254 | goto abort_iotag_exit; |
| 11255 | } |
| 11256 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11257 | /* |
| 11258 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11259 | * the callback so that nothing happens when it finishes. |
| 11260 | */ |
| 11261 | if ((vport->load_flag & FC_UNLOADING) && |
| 11262 | (pring->ringno == LPFC_ELS_RING)) { |
| 11263 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11264 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11265 | else |
| 11266 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11267 | goto abort_iotag_exit; |
| 11268 | } |
| 11269 | |
| 11270 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 11271 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 11272 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11273 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11274 | /* |
| 11275 | * Caller to this routine should check for IOCB_ERROR |
| 11276 | * and handle it properly. This routine no longer removes |
| 11277 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11278 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11279 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11280 | } |
| 11281 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11282 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11283 | * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb |
| 11284 | * @phba: Pointer to HBA context object. |
| 11285 | * @pring: Pointer to driver SLI ring object. |
| 11286 | * @cmdiocb: Pointer to driver command iocb object. |
| 11287 | * |
| 11288 | * This function issues an abort iocb for the provided command iocb down to |
| 11289 | * the port. Other than the case the outstanding command iocb is an abort |
| 11290 | * request, this function issues abort out unconditionally. This function is |
| 11291 | * called with hbalock held. The function returns 0 when it fails due to |
| 11292 | * memory allocation failure or when the command iocb is an abort request. |
| 11293 | **/ |
| 11294 | static int |
| 11295 | lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11296 | struct lpfc_iocbq *cmdiocb) |
| 11297 | { |
| 11298 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11299 | struct lpfc_iocbq *abtsiocbp; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 11300 | union lpfc_wqe128 *abts_wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11301 | int retval; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 11302 | int idx = cmdiocb->hba_wqidx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11303 | |
| 11304 | /* |
| 11305 | * There are certain command types we don't want to abort. And we |
| 11306 | * don't want to abort commands that are already in the process of |
| 11307 | * being aborted. |
| 11308 | */ |
| 11309 | if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 11310 | cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
| 11311 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11312 | return 0; |
| 11313 | |
| 11314 | /* issue ABTS for this io based on iotag */ |
| 11315 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| 11316 | if (abtsiocbp == NULL) |
| 11317 | return 0; |
| 11318 | |
| 11319 | /* This signals the response to set the correct status |
| 11320 | * before calling the completion handler |
| 11321 | */ |
| 11322 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11323 | |
| 11324 | /* Complete prepping the abort wqe and issue to the FW. */ |
| 11325 | abts_wqe = &abtsiocbp->wqe; |
James Smart | 1c36833 | 2018-11-29 16:09:37 -0800 | [diff] [blame] | 11326 | |
| 11327 | /* Clear any stale WQE contents */ |
| 11328 | memset(abts_wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11329 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); |
| 11330 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11331 | /* word 7 */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11332 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 11333 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, |
| 11334 | cmdiocb->iocb.ulpClass); |
| 11335 | |
| 11336 | /* word 8 - tell the FW to abort the IO associated with this |
| 11337 | * outstanding exchange ID. |
| 11338 | */ |
| 11339 | abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag; |
| 11340 | |
| 11341 | /* word 9 - this is the iotag for the abts_wqe completion. */ |
| 11342 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, |
| 11343 | abtsiocbp->iotag); |
| 11344 | |
| 11345 | /* word 10 */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11346 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); |
| 11347 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 11348 | |
| 11349 | /* word 11 */ |
| 11350 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 11351 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); |
| 11352 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 11353 | |
| 11354 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 11355 | abtsiocbp->iocb_flag |= LPFC_IO_NVME; |
| 11356 | abtsiocbp->vport = vport; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11357 | abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 11358 | retval = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[idx], |
| 11359 | abtsiocbp); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 11360 | if (retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11361 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 11362 | "6147 Failed abts issue_wqe with status x%x " |
| 11363 | "for oxid x%x\n", |
| 11364 | retval, cmdiocb->sli4_xritag); |
| 11365 | lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 11366 | return retval; |
| 11367 | } |
| 11368 | |
| 11369 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 11370 | "6148 Drv Abort NVME Request Issued for " |
| 11371 | "ox_id x%x on reqtag x%x\n", |
| 11372 | cmdiocb->sli4_xritag, |
| 11373 | abtsiocbp->iotag); |
| 11374 | |
| 11375 | return retval; |
| 11376 | } |
| 11377 | |
| 11378 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11379 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11380 | * @phba: pointer to lpfc HBA data structure. |
| 11381 | * |
| 11382 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11383 | **/ |
| 11384 | void |
| 11385 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11386 | { |
| 11387 | struct lpfc_sli *psli = &phba->sli; |
| 11388 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11389 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11390 | int i; |
| 11391 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11392 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11393 | for (i = 0; i < psli->num_rings; i++) { |
| 11394 | pring = &psli->sli3_ring[i]; |
| 11395 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11396 | } |
| 11397 | return; |
| 11398 | } |
| 11399 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11400 | pring = qp->pring; |
| 11401 | if (!pring) |
| 11402 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11403 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11404 | } |
| 11405 | } |
| 11406 | |
| 11407 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11408 | * 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] | 11409 | * @iocbq: Pointer to driver iocb object. |
| 11410 | * @vport: Pointer to driver virtual port object. |
| 11411 | * @tgt_id: SCSI ID of the target. |
| 11412 | * @lun_id: LUN ID of the scsi device. |
| 11413 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11414 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11415 | * 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] | 11416 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11417 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11418 | * 1 if the filtering criteria is not met. |
| 11419 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11420 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11421 | * lun_id parameter. |
| 11422 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11423 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11424 | * parameters. |
| 11425 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11426 | * given iocb is for the SCSI host associated with the given vport. |
| 11427 | * This function is called with no locks held. |
| 11428 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11429 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11430 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11431 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11432 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11433 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11434 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11435 | int rc = 1; |
| 11436 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11437 | if (iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11438 | return rc; |
| 11439 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11440 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11441 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11442 | return rc; |
| 11443 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11444 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11445 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11446 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11447 | return rc; |
| 11448 | |
| 11449 | switch (ctx_cmd) { |
| 11450 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11451 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11452 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11453 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11454 | rc = 0; |
| 11455 | break; |
| 11456 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11457 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11458 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11459 | rc = 0; |
| 11460 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11461 | case LPFC_CTX_HOST: |
| 11462 | rc = 0; |
| 11463 | break; |
| 11464 | default: |
| 11465 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11466 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11467 | break; |
| 11468 | } |
| 11469 | |
| 11470 | return rc; |
| 11471 | } |
| 11472 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11473 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11474 | * 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] | 11475 | * @vport: Pointer to virtual port. |
| 11476 | * @tgt_id: SCSI ID of the target. |
| 11477 | * @lun_id: LUN ID of the scsi device. |
| 11478 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11479 | * |
| 11480 | * This function returns number of FCP commands pending for the vport. |
| 11481 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11482 | * commands pending on the vport associated with SCSI device specified |
| 11483 | * by tgt_id and lun_id parameters. |
| 11484 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11485 | * commands pending on the vport associated with SCSI target specified |
| 11486 | * by tgt_id parameter. |
| 11487 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11488 | * commands pending on the vport. |
| 11489 | * This function returns the number of iocbs which satisfy the filter. |
| 11490 | * This function is called without any lock held. |
| 11491 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11492 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11493 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11494 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11495 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11496 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11497 | struct lpfc_iocbq *iocbq; |
| 11498 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11499 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11500 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11501 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11502 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11503 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11504 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11505 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11506 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11507 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11508 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11510 | return sum; |
| 11511 | } |
| 11512 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11513 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11514 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11515 | * @phba: Pointer to HBA context object |
| 11516 | * @cmdiocb: Pointer to command iocb object. |
| 11517 | * @rspiocb: Pointer to response iocb object. |
| 11518 | * |
| 11519 | * This function is called when an aborted FCP iocb completes. This |
| 11520 | * function is called by the ring event handler with no lock held. |
| 11521 | * This function frees the iocb. |
| 11522 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11523 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11524 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11525 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11526 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11527 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11528 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11529 | "original iotag x%x, abort cmd iotag x%x " |
| 11530 | "status 0x%x, reason 0x%x\n", |
| 11531 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11532 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11533 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11534 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11535 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11536 | return; |
| 11537 | } |
| 11538 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11539 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11540 | * 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] | 11541 | * @vport: Pointer to virtual port. |
| 11542 | * @pring: Pointer to driver SLI ring object. |
| 11543 | * @tgt_id: SCSI ID of the target. |
| 11544 | * @lun_id: LUN ID of the scsi device. |
| 11545 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11546 | * |
| 11547 | * This function sends an abort command for every SCSI command |
| 11548 | * associated with the given virtual port pending on the ring |
| 11549 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11550 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11551 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11552 | * parameters |
| 11553 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11554 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11555 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11556 | * FCP iocbs associated with virtual port. |
| 11557 | * This function returns number of iocbs it failed to abort. |
| 11558 | * This function is called with no locks held. |
| 11559 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11560 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11561 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11562 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11563 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11564 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11565 | struct lpfc_iocbq *iocbq; |
| 11566 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11567 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11568 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11569 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11570 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11571 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11572 | /* all I/Os are in process of being flushed */ |
| 11573 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) |
| 11574 | return errcnt; |
| 11575 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11576 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11577 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11578 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11579 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11580 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11581 | continue; |
| 11582 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11583 | /* |
| 11584 | * If the iocbq is already being aborted, don't take a second |
| 11585 | * action, but do count it. |
| 11586 | */ |
| 11587 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11588 | continue; |
| 11589 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11590 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11591 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11592 | if (abtsiocb == NULL) { |
| 11593 | errcnt++; |
| 11594 | continue; |
| 11595 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11596 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11597 | /* indicate the IO is being aborted by the driver. */ |
| 11598 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11599 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11600 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11601 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11602 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11603 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11604 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11605 | else |
| 11606 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11607 | abtsiocb->iocb.ulpLe = 1; |
| 11608 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11609 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11610 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11611 | /* 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] | 11612 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11613 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11614 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11615 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11616 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11617 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11618 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11619 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11620 | else |
| 11621 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11622 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11623 | /* Setup callback routine and issue the command. */ |
| 11624 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11625 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11626 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11627 | if (!pring_s4) |
| 11628 | continue; |
| 11629 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11630 | abtsiocb, 0); |
| 11631 | } else |
| 11632 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11633 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11634 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11635 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11636 | errcnt++; |
| 11637 | continue; |
| 11638 | } |
| 11639 | } |
| 11640 | |
| 11641 | return errcnt; |
| 11642 | } |
| 11643 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11644 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11645 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11646 | * @vport: Pointer to virtual port. |
| 11647 | * @pring: Pointer to driver SLI ring object. |
| 11648 | * @tgt_id: SCSI ID of the target. |
| 11649 | * @lun_id: LUN ID of the scsi device. |
| 11650 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11651 | * |
| 11652 | * This function sends an abort command for every SCSI command |
| 11653 | * associated with the given virtual port pending on the ring |
| 11654 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11655 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11656 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11657 | * parameters |
| 11658 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11659 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11660 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11661 | * FCP iocbs associated with virtual port. |
| 11662 | * This function returns number of iocbs it aborted . |
| 11663 | * This function is called with no locks held right after a taskmgmt |
| 11664 | * command is sent. |
| 11665 | **/ |
| 11666 | int |
| 11667 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11668 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11669 | { |
| 11670 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11671 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11672 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11673 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11674 | struct lpfc_iocbq *iocbq; |
| 11675 | IOCB_t *icmd; |
| 11676 | int sum, i, ret_val; |
| 11677 | unsigned long iflags; |
| 11678 | struct lpfc_sli_ring *pring_s4; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11679 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11680 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11681 | |
| 11682 | /* all I/Os are in process of being flushed */ |
| 11683 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11684 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11685 | return 0; |
| 11686 | } |
| 11687 | sum = 0; |
| 11688 | |
| 11689 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11690 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11691 | |
| 11692 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11693 | cmd) != 0) |
| 11694 | continue; |
| 11695 | |
| 11696 | /* |
| 11697 | * If the iocbq is already being aborted, don't take a second |
| 11698 | * action, but do count it. |
| 11699 | */ |
| 11700 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11701 | continue; |
| 11702 | |
| 11703 | /* issue ABTS for this IOCB based on iotag */ |
| 11704 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 11705 | if (abtsiocbq == NULL) |
| 11706 | continue; |
| 11707 | |
| 11708 | icmd = &iocbq->iocb; |
| 11709 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11710 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11711 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11712 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11713 | iocbq->sli4_xritag; |
| 11714 | else |
| 11715 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11716 | abtsiocbq->iocb.ulpLe = 1; |
| 11717 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11718 | abtsiocbq->vport = vport; |
| 11719 | |
| 11720 | /* 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] | 11721 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11722 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11723 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11724 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11725 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11726 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11727 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11728 | ndlp = lpfc_cmd->rdata->pnode; |
| 11729 | |
| 11730 | if (lpfc_is_link_up(phba) && |
| 11731 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11732 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11733 | else |
| 11734 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11735 | |
| 11736 | /* Setup callback routine and issue the command. */ |
| 11737 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11738 | |
| 11739 | /* |
| 11740 | * Indicate the IO is being aborted by the driver and set |
| 11741 | * the caller's flag into the aborted IO. |
| 11742 | */ |
| 11743 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11744 | |
| 11745 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11746 | pring_s4 = lpfc_sli4_calc_ring(phba, abtsiocbq); |
| 11747 | if (!pring_s4) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11748 | continue; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11749 | /* Note: both hbalock and ring_lock must be set here */ |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11750 | spin_lock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11751 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11752 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11753 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11754 | } else { |
| 11755 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11756 | abtsiocbq, 0); |
| 11757 | } |
| 11758 | |
| 11759 | |
| 11760 | if (ret_val == IOCB_ERROR) |
| 11761 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11762 | else |
| 11763 | sum++; |
| 11764 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11765 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11766 | return sum; |
| 11767 | } |
| 11768 | |
| 11769 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11770 | * 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] | 11771 | * @phba: Pointer to HBA context object. |
| 11772 | * @cmdiocbq: Pointer to command iocb. |
| 11773 | * @rspiocbq: Pointer to response iocb. |
| 11774 | * |
| 11775 | * This function is the completion handler for iocbs issued using |
| 11776 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11777 | * ring event handler function without any lock held. This function |
| 11778 | * can be called from both worker thread context and interrupt |
| 11779 | * context. This function also can be called from other thread which |
| 11780 | * cleans up the SLI layer objects. |
| 11781 | * This function copy the contents of the response iocb to the |
| 11782 | * response iocb memory object provided by the caller of |
| 11783 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11784 | * sleeps for the iocb completion. |
| 11785 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11786 | static void |
| 11787 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11788 | struct lpfc_iocbq *cmdiocbq, |
| 11789 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11790 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11791 | wait_queue_head_t *pdone_q; |
| 11792 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11793 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11794 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11795 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11796 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11797 | |
| 11798 | /* |
| 11799 | * A time out has occurred for the iocb. If a time out |
| 11800 | * completion handler has been supplied, call it. Otherwise, |
| 11801 | * just free the iocbq. |
| 11802 | */ |
| 11803 | |
| 11804 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11805 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11806 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11807 | if (cmdiocbq->iocb_cmpl) |
| 11808 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11809 | else |
| 11810 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11811 | return; |
| 11812 | } |
| 11813 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11814 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11815 | if (cmdiocbq->context2 && rspiocbq) |
| 11816 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11817 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11818 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11819 | /* Set the exchange busy flag for task management commands */ |
| 11820 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11821 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11822 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11823 | cur_iocbq); |
| 11824 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11825 | } |
| 11826 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11827 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11828 | if (pdone_q) |
| 11829 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11830 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11831 | return; |
| 11832 | } |
| 11833 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11834 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11835 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11836 | * @phba: Pointer to HBA context object.. |
| 11837 | * @piocbq: Pointer to command iocb. |
| 11838 | * @flag: Flag to test. |
| 11839 | * |
| 11840 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11841 | * see if the passed in flag is set. |
| 11842 | * Returns: |
| 11843 | * 1 if flag is set. |
| 11844 | * 0 if flag is not set. |
| 11845 | **/ |
| 11846 | static int |
| 11847 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11848 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11849 | { |
| 11850 | unsigned long iflags; |
| 11851 | int ret; |
| 11852 | |
| 11853 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11854 | ret = piocbq->iocb_flag & flag; |
| 11855 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11856 | return ret; |
| 11857 | |
| 11858 | } |
| 11859 | |
| 11860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11861 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11862 | * @phba: Pointer to HBA context object.. |
| 11863 | * @pring: Pointer to sli ring. |
| 11864 | * @piocb: Pointer to command iocb. |
| 11865 | * @prspiocbq: Pointer to response iocb. |
| 11866 | * @timeout: Timeout in number of seconds. |
| 11867 | * |
| 11868 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11869 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11870 | * to handle iocbs which time out. If the field is NULL, the |
| 11871 | * function shall free the iocbq structure. If more clean up is |
| 11872 | * needed, the caller is expected to provide a completion function |
| 11873 | * that will provide the needed clean up. If the iocb command is |
| 11874 | * not completed within timeout seconds, the function will either |
| 11875 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11876 | * completion function set in the iocb_cmpl field and then return |
| 11877 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11878 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11879 | * The function waits for the iocb completion using an |
| 11880 | * non-interruptible wait. |
| 11881 | * This function will sleep while waiting for iocb completion. |
| 11882 | * So, this function should not be called from any context which |
| 11883 | * does not allow sleeping. Due to the same reason, this function |
| 11884 | * cannot be called with interrupt disabled. |
| 11885 | * This function assumes that the iocb completions occur while |
| 11886 | * this function sleep. So, this function cannot be called from |
| 11887 | * the thread which process iocb completion for this ring. |
| 11888 | * This function clears the iocb_flag of the iocb object before |
| 11889 | * issuing the iocb and the iocb completion handler sets this |
| 11890 | * flag and wakes this thread when the iocb completes. |
| 11891 | * The contents of the response iocb will be copied to prspiocbq |
| 11892 | * by the completion handler when the command completes. |
| 11893 | * This function returns IOCB_SUCCESS when success. |
| 11894 | * This function is called with no lock held. |
| 11895 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11896 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11897 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11898 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11899 | struct lpfc_iocbq *piocb, |
| 11900 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11901 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11902 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11903 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11904 | long timeleft, timeout_req = 0; |
| 11905 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11906 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11907 | struct lpfc_iocbq *iocb; |
| 11908 | int txq_cnt = 0; |
| 11909 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11910 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11911 | unsigned long iflags; |
| 11912 | bool iocb_completed = true; |
| 11913 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11914 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11915 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11916 | else |
| 11917 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11918 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11919 | * If the caller has provided a response iocbq buffer, then context2 |
| 11920 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11921 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11922 | if (prspiocbq) { |
| 11923 | if (piocb->context2) |
| 11924 | return IOCB_ERROR; |
| 11925 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11926 | } |
| 11927 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11928 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11929 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11930 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11931 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11932 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11933 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11934 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11935 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11936 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11937 | writel(creg_val, phba->HCregaddr); |
| 11938 | readl(phba->HCregaddr); /* flush */ |
| 11939 | } |
| 11940 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11941 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11942 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11943 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11944 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11945 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11946 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11947 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11948 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11949 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11950 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11951 | /* |
| 11952 | * IOCB timed out. Inform the wake iocb wait |
| 11953 | * completion function and set local status |
| 11954 | */ |
| 11955 | |
| 11956 | iocb_completed = false; |
| 11957 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11958 | } |
| 11959 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11960 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11961 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11962 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11963 | /* Note: we are not indicating if the IOCB has a success |
| 11964 | * status or not - that's for the caller to check. |
| 11965 | * IOCB_SUCCESS means just that the command was sent and |
| 11966 | * completed. Not that it completed successfully. |
| 11967 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11968 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11969 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11970 | "0338 IOCB wait timeout error - no " |
| 11971 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11972 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11973 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11974 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11975 | "0330 IOCB wake NOT set, " |
| 11976 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11977 | timeout, (timeleft / jiffies)); |
| 11978 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11979 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11980 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11981 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11982 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11983 | txq_cnt++; |
| 11984 | } |
| 11985 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11986 | txcmplq_cnt++; |
| 11987 | } |
| 11988 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11989 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11990 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11991 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11992 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11993 | } else { |
| 11994 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11995 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11996 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11997 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11998 | } |
| 11999 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12000 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12001 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12002 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12003 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 12004 | writel(creg_val, phba->HCregaddr); |
| 12005 | readl(phba->HCregaddr); /* flush */ |
| 12006 | } |
| 12007 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12008 | if (prspiocbq) |
| 12009 | piocb->context2 = NULL; |
| 12010 | |
| 12011 | piocb->context_un.wait_queue = NULL; |
| 12012 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12013 | return retval; |
| 12014 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12015 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12016 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12017 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12018 | * @phba: Pointer to HBA context object. |
| 12019 | * @pmboxq: Pointer to driver mailbox object. |
| 12020 | * @timeout: Timeout in number of seconds. |
| 12021 | * |
| 12022 | * This function issues the mailbox to firmware and waits for the |
| 12023 | * mailbox command to complete. If the mailbox command is not |
| 12024 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 12025 | * The function waits for the mailbox completion using an |
| 12026 | * interruptible wait. If the thread is woken up due to a |
| 12027 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 12028 | * should not free the mailbox resources, if this function returns |
| 12029 | * MBX_TIMEOUT. |
| 12030 | * This function will sleep while waiting for mailbox completion. |
| 12031 | * So, this function should not be called from any context which |
| 12032 | * does not allow sleeping. Due to the same reason, this function |
| 12033 | * cannot be called with interrupt disabled. |
| 12034 | * This function assumes that the mailbox completion occurs while |
| 12035 | * this function sleep. So, this function cannot be called from |
| 12036 | * the worker thread which processes mailbox completion. |
| 12037 | * This function is called in the context of HBA management |
| 12038 | * applications. |
| 12039 | * This function returns MBX_SUCCESS when successful. |
| 12040 | * This function is called with no lock held. |
| 12041 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12042 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12043 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12044 | uint32_t timeout) |
| 12045 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12046 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12047 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12048 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12049 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12050 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12051 | /* setup wake call as IOCB callback */ |
| 12052 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12053 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12054 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 12055 | init_completion(&mbox_done); |
| 12056 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12057 | /* now issue the command */ |
| 12058 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12059 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12060 | wait_for_completion_timeout(&mbox_done, |
| 12061 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12062 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12063 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12064 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12065 | /* |
| 12066 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 12067 | * else do not free the resources. |
| 12068 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12069 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12070 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12071 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12072 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12073 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12074 | } |
| 12075 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12076 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12077 | return retval; |
| 12078 | } |
| 12079 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12080 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12081 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12082 | * @phba: Pointer to HBA context. |
| 12083 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12084 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12085 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12086 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12087 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12088 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12089 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12090 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12091 | * as with offline or HBA function reset), this routine will wait for the |
| 12092 | * outstanding mailbox command to complete before invoking the mailbox |
| 12093 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12094 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12095 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12096 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12097 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12098 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12099 | unsigned long timeout; |
| 12100 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12101 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12102 | /* delay 100ms for port state */ |
| 12103 | msleep(100); |
| 12104 | lpfc_sli_mbox_sys_flush(phba); |
| 12105 | return; |
| 12106 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12107 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12108 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12109 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12110 | local_bh_disable(); |
| 12111 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12112 | spin_lock_irq(&phba->hbalock); |
| 12113 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12114 | |
| 12115 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12116 | /* Determine how long we might wait for the active mailbox |
| 12117 | * command to be gracefully completed by firmware. |
| 12118 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12119 | if (phba->sli.mbox_active) |
| 12120 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12121 | phba->sli.mbox_active) * |
| 12122 | 1000) + jiffies; |
| 12123 | spin_unlock_irq(&phba->hbalock); |
| 12124 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12125 | /* Enable softirqs again, done with phba->hbalock */ |
| 12126 | local_bh_enable(); |
| 12127 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12128 | while (phba->sli.mbox_active) { |
| 12129 | /* Check active mailbox complete status every 2ms */ |
| 12130 | msleep(2); |
| 12131 | if (time_after(jiffies, timeout)) |
| 12132 | /* Timeout, let the mailbox flush routine to |
| 12133 | * forcefully release active mailbox command |
| 12134 | */ |
| 12135 | break; |
| 12136 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12137 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12138 | spin_unlock_irq(&phba->hbalock); |
| 12139 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12140 | /* Enable softirqs again, done with phba->hbalock */ |
| 12141 | local_bh_enable(); |
| 12142 | } |
| 12143 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12144 | lpfc_sli_mbox_sys_flush(phba); |
| 12145 | } |
| 12146 | |
| 12147 | /** |
| 12148 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12149 | * @phba: Pointer to HBA context. |
| 12150 | * |
| 12151 | * This function is called to read the SLI3 device error attention registers |
| 12152 | * for possible error attention events. The caller must hold the hostlock |
| 12153 | * with spin_lock_irq(). |
| 12154 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12155 | * 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] | 12156 | * Register and returns 0 otherwise. |
| 12157 | **/ |
| 12158 | static int |
| 12159 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12160 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12161 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12162 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12163 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12164 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12165 | goto unplug_err; |
| 12166 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12167 | if (ha_copy & HA_ERATT) { |
| 12168 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12169 | if (lpfc_sli_read_hs(phba)) |
| 12170 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12171 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12172 | /* Check if there is a deferred error condition is active */ |
| 12173 | if ((HS_FFER1 & phba->work_hs) && |
| 12174 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12175 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12176 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12177 | /* Clear all interrupt enable conditions */ |
| 12178 | writel(0, phba->HCregaddr); |
| 12179 | readl(phba->HCregaddr); |
| 12180 | } |
| 12181 | |
| 12182 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12183 | phba->work_ha |= HA_ERATT; |
| 12184 | /* Indicate polling handles this ERATT */ |
| 12185 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12186 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12187 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12188 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12189 | |
| 12190 | unplug_err: |
| 12191 | /* Set the driver HS work bitmap */ |
| 12192 | phba->work_hs |= UNPLUG_ERR; |
| 12193 | /* Set the driver HA work bitmap */ |
| 12194 | phba->work_ha |= HA_ERATT; |
| 12195 | /* Indicate polling handles this ERATT */ |
| 12196 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12197 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12198 | } |
| 12199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12200 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12201 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12202 | * @phba: Pointer to HBA context. |
| 12203 | * |
| 12204 | * This function is called to read the SLI4 device error attention registers |
| 12205 | * for possible error attention events. The caller must hold the hostlock |
| 12206 | * with spin_lock_irq(). |
| 12207 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12208 | * 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] | 12209 | * Register and returns 0 otherwise. |
| 12210 | **/ |
| 12211 | static int |
| 12212 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12213 | { |
| 12214 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12215 | uint32_t if_type, portsmphr; |
| 12216 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12217 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12218 | /* |
| 12219 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12220 | * registers for error attention. This can be changed later. |
| 12221 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12222 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12223 | switch (if_type) { |
| 12224 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12225 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12226 | &uerr_sta_lo) || |
| 12227 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12228 | &uerr_sta_hi)) { |
| 12229 | phba->work_hs |= UNPLUG_ERR; |
| 12230 | phba->work_ha |= HA_ERATT; |
| 12231 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12232 | return 1; |
| 12233 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12234 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12235 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 12236 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12237 | "1423 HBA Unrecoverable error: " |
| 12238 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12239 | "ue_mask_lo_reg=0x%x, " |
| 12240 | "ue_mask_hi_reg=0x%x\n", |
| 12241 | uerr_sta_lo, uerr_sta_hi, |
| 12242 | phba->sli4_hba.ue_mask_lo, |
| 12243 | phba->sli4_hba.ue_mask_hi); |
| 12244 | phba->work_status[0] = uerr_sta_lo; |
| 12245 | phba->work_status[1] = uerr_sta_hi; |
| 12246 | phba->work_ha |= HA_ERATT; |
| 12247 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12248 | return 1; |
| 12249 | } |
| 12250 | break; |
| 12251 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12252 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12253 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12254 | &portstat_reg.word0) || |
| 12255 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12256 | &portsmphr)){ |
| 12257 | phba->work_hs |= UNPLUG_ERR; |
| 12258 | phba->work_ha |= HA_ERATT; |
| 12259 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12260 | return 1; |
| 12261 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12262 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12263 | phba->work_status[0] = |
| 12264 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12265 | phba->work_status[1] = |
| 12266 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 12267 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12268 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12269 | "port status reg 0x%x, " |
| 12270 | "port smphr reg 0x%x, " |
| 12271 | "error 1=0x%x, error 2=0x%x\n", |
| 12272 | portstat_reg.word0, |
| 12273 | portsmphr, |
| 12274 | phba->work_status[0], |
| 12275 | phba->work_status[1]); |
| 12276 | phba->work_ha |= HA_ERATT; |
| 12277 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12278 | return 1; |
| 12279 | } |
| 12280 | break; |
| 12281 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12282 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12283 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12284 | "2886 HBA Error Attention on unsupported " |
| 12285 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12286 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12287 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12288 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12289 | return 0; |
| 12290 | } |
| 12291 | |
| 12292 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12293 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12294 | * @phba: Pointer to HBA context. |
| 12295 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12296 | * 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] | 12297 | * error attention register bit for error attention events. |
| 12298 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12299 | * 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] | 12300 | * Register and returns 0 otherwise. |
| 12301 | **/ |
| 12302 | int |
| 12303 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12304 | { |
| 12305 | uint32_t ha_copy; |
| 12306 | |
| 12307 | /* If somebody is waiting to handle an eratt, don't process it |
| 12308 | * here. The brdkill function will do this. |
| 12309 | */ |
| 12310 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12311 | return 0; |
| 12312 | |
| 12313 | /* Check if interrupt handler handles this ERATT */ |
| 12314 | spin_lock_irq(&phba->hbalock); |
| 12315 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12316 | /* Interrupt handler has handled ERATT */ |
| 12317 | spin_unlock_irq(&phba->hbalock); |
| 12318 | return 0; |
| 12319 | } |
| 12320 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12321 | /* |
| 12322 | * If there is deferred error attention, do not check for error |
| 12323 | * attention |
| 12324 | */ |
| 12325 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12326 | spin_unlock_irq(&phba->hbalock); |
| 12327 | return 0; |
| 12328 | } |
| 12329 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12330 | /* If PCI channel is offline, don't process it */ |
| 12331 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12332 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12333 | return 0; |
| 12334 | } |
| 12335 | |
| 12336 | switch (phba->sli_rev) { |
| 12337 | case LPFC_SLI_REV2: |
| 12338 | case LPFC_SLI_REV3: |
| 12339 | /* Read chip Host Attention (HA) register */ |
| 12340 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12341 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12342 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12343 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12344 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12345 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12346 | default: |
| 12347 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12348 | "0299 Invalid SLI revision (%d)\n", |
| 12349 | phba->sli_rev); |
| 12350 | ha_copy = 0; |
| 12351 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12352 | } |
| 12353 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12354 | |
| 12355 | return ha_copy; |
| 12356 | } |
| 12357 | |
| 12358 | /** |
| 12359 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12360 | * @phba: Pointer to HBA context. |
| 12361 | * |
| 12362 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12363 | * that the interrupt should be handled. |
| 12364 | * |
| 12365 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12366 | * interrupt should be handled, otherwise -EIO. |
| 12367 | */ |
| 12368 | static inline int |
| 12369 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12370 | { |
| 12371 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12372 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12373 | return -EIO; |
| 12374 | |
| 12375 | /* Update device level interrupt statistics */ |
| 12376 | phba->sli.slistat.sli_intr++; |
| 12377 | |
| 12378 | /* Ignore all interrupts during initialization. */ |
| 12379 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12380 | return -EIO; |
| 12381 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12382 | return 0; |
| 12383 | } |
| 12384 | |
| 12385 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12386 | * 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] | 12387 | * @irq: Interrupt number. |
| 12388 | * @dev_id: The device context pointer. |
| 12389 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12390 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12391 | * service routine when device with SLI-3 interface spec is enabled with |
| 12392 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12393 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12394 | * interrupt mode, this function is called as part of the device-level |
| 12395 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12396 | * is undergoing initialization, the interrupt handler will not process |
| 12397 | * the interrupt. The link attention and ELS ring attention events are |
| 12398 | * handled by the worker thread. The interrupt handler signals the worker |
| 12399 | * thread and returns for these events. This function is called without |
| 12400 | * 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] | 12401 | * structures. |
| 12402 | * |
| 12403 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12404 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12405 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12406 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12407 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12408 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12409 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12410 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12411 | uint32_t work_ha_copy; |
| 12412 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12413 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12414 | uint32_t control; |
| 12415 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12416 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12417 | struct lpfc_vport *vport; |
| 12418 | struct lpfc_nodelist *ndlp; |
| 12419 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12420 | LPFC_MBOXQ_t *pmb; |
| 12421 | int rc; |
| 12422 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12423 | /* |
| 12424 | * Get the driver's phba structure from the dev_id and |
| 12425 | * assume the HBA is not interrupting. |
| 12426 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12427 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12428 | |
| 12429 | if (unlikely(!phba)) |
| 12430 | return IRQ_NONE; |
| 12431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12432 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12433 | * Stuff needs to be attented to when this function is invoked as an |
| 12434 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12435 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12436 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12437 | /* Check device state for handling interrupt */ |
| 12438 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12439 | return IRQ_NONE; |
| 12440 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12441 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12442 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12443 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12444 | /* If somebody is waiting to handle an eratt don't process it |
| 12445 | * here. The brdkill function will do this. |
| 12446 | */ |
| 12447 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12448 | ha_copy &= ~HA_ERATT; |
| 12449 | /* Check the need for handling ERATT in interrupt handler */ |
| 12450 | if (ha_copy & HA_ERATT) { |
| 12451 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12452 | /* ERATT polling has handled ERATT */ |
| 12453 | ha_copy &= ~HA_ERATT; |
| 12454 | else |
| 12455 | /* Indicate interrupt handler handles ERATT */ |
| 12456 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12457 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12458 | |
| 12459 | /* |
| 12460 | * If there is deferred error attention, do not check for any |
| 12461 | * interrupt. |
| 12462 | */ |
| 12463 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12464 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12465 | return IRQ_NONE; |
| 12466 | } |
| 12467 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12468 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12469 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12470 | goto unplug_error; |
| 12471 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12472 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12473 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12474 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12475 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12476 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12477 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12478 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12479 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12480 | } else |
| 12481 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12482 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12483 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12484 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12485 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12486 | if (work_ha_copy & HA_LATT) { |
| 12487 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12488 | /* |
| 12489 | * Turn off Link Attention interrupts |
| 12490 | * until CLEAR_LA done |
| 12491 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12492 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12493 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12494 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12495 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12496 | control &= ~HC_LAINT_ENA; |
| 12497 | writel(control, phba->HCregaddr); |
| 12498 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12499 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12500 | } |
| 12501 | else |
| 12502 | work_ha_copy &= ~HA_LATT; |
| 12503 | } |
| 12504 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12505 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12506 | /* |
| 12507 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12508 | * the only slow ring. |
| 12509 | */ |
| 12510 | status = (work_ha_copy & |
| 12511 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12512 | status >>= (4*LPFC_ELS_RING); |
| 12513 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12514 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12515 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12516 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12517 | |
| 12518 | lpfc_debugfs_slow_ring_trc(phba, |
| 12519 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12520 | control, status, |
| 12521 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12522 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12523 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12524 | lpfc_debugfs_slow_ring_trc(phba, |
| 12525 | "ISR Disable ring:" |
| 12526 | "pwork:x%x hawork:x%x wait:x%x", |
| 12527 | phba->work_ha, work_ha_copy, |
| 12528 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12529 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12530 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12531 | control &= |
| 12532 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12533 | writel(control, phba->HCregaddr); |
| 12534 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12535 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12536 | else { |
| 12537 | lpfc_debugfs_slow_ring_trc(phba, |
| 12538 | "ISR slow ring: pwork:" |
| 12539 | "x%x hawork:x%x wait:x%x", |
| 12540 | phba->work_ha, work_ha_copy, |
| 12541 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12542 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12543 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12544 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12545 | } |
| 12546 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12547 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12548 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12549 | if (lpfc_sli_read_hs(phba)) |
| 12550 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12551 | /* |
| 12552 | * Check if there is a deferred error condition |
| 12553 | * is active |
| 12554 | */ |
| 12555 | if ((HS_FFER1 & phba->work_hs) && |
| 12556 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12557 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12558 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12559 | phba->hba_flag |= DEFER_ERATT; |
| 12560 | /* Clear all interrupt enable conditions */ |
| 12561 | writel(0, phba->HCregaddr); |
| 12562 | readl(phba->HCregaddr); |
| 12563 | } |
| 12564 | } |
| 12565 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12566 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12567 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12568 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12569 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12570 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12571 | |
| 12572 | /* First check out the status word */ |
| 12573 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12574 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12575 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12576 | /* |
| 12577 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12578 | * mbxStatus <status> |
| 12579 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12580 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12581 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12582 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12583 | "Interrupt mbxCommand x%x " |
| 12584 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12585 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12586 | pmbox->mbxCommand, |
| 12587 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12588 | /* clear mailbox attention bit */ |
| 12589 | work_ha_copy &= ~HA_MBATT; |
| 12590 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12591 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12592 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12593 | phba->last_completion_time = jiffies; |
| 12594 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12595 | if (pmb->mbox_cmpl) { |
| 12596 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12597 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12598 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12599 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12600 | lpfc_sli_pcimem_bcopy( |
| 12601 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12602 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12603 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12604 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12605 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12606 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12607 | |
| 12608 | lpfc_debugfs_disc_trc(vport, |
| 12609 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12610 | "MBOX dflt rpi: : " |
| 12611 | "status:x%x rpi:x%x", |
| 12612 | (uint32_t)pmbox->mbxStatus, |
| 12613 | pmbox->un.varWords[0], 0); |
| 12614 | |
| 12615 | if (!pmbox->mbxStatus) { |
| 12616 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12617 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12618 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12619 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12620 | |
| 12621 | /* Reg_LOGIN of dflt RPI was |
| 12622 | * successful. new lets get |
| 12623 | * rid of the RPI using the |
| 12624 | * same mbox buffer. |
| 12625 | */ |
| 12626 | lpfc_unreg_login(phba, |
| 12627 | vport->vpi, |
| 12628 | pmbox->un.varWords[0], |
| 12629 | pmb); |
| 12630 | pmb->mbox_cmpl = |
| 12631 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12632 | pmb->ctx_buf = mp; |
| 12633 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12634 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12635 | rc = lpfc_sli_issue_mbox(phba, |
| 12636 | pmb, |
| 12637 | MBX_NOWAIT); |
| 12638 | if (rc != MBX_BUSY) |
| 12639 | lpfc_printf_log(phba, |
| 12640 | KERN_ERR, |
| 12641 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12642 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12643 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12644 | if (rc != MBX_NOT_FINISHED) |
| 12645 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12646 | } |
| 12647 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12648 | spin_lock_irqsave( |
| 12649 | &phba->pport->work_port_lock, |
| 12650 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12651 | phba->pport->work_port_events &= |
| 12652 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12653 | spin_unlock_irqrestore( |
| 12654 | &phba->pport->work_port_lock, |
| 12655 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12656 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12657 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12658 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12659 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12660 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12661 | if ((work_ha_copy & HA_MBATT) && |
| 12662 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12663 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12664 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12665 | do { |
| 12666 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12667 | MBX_NOWAIT); |
| 12668 | } while (rc == MBX_NOT_FINISHED); |
| 12669 | if (rc != MBX_SUCCESS) |
| 12670 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12671 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12672 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12673 | } |
| 12674 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12675 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12676 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12677 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12678 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12679 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12680 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12681 | unplug_error: |
| 12682 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12683 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12684 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12685 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12686 | |
| 12687 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12688 | * 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] | 12689 | * @irq: Interrupt number. |
| 12690 | * @dev_id: The device context pointer. |
| 12691 | * |
| 12692 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12693 | * service routine when device with SLI-3 interface spec is enabled with |
| 12694 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12695 | * ring event in the HBA. However, when the device is enabled with either |
| 12696 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12697 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12698 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12699 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12700 | * the intrrupt context. This function is called without any lock held. |
| 12701 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12702 | * |
| 12703 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12704 | * returns IRQ_NONE. |
| 12705 | **/ |
| 12706 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12707 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12708 | { |
| 12709 | struct lpfc_hba *phba; |
| 12710 | uint32_t ha_copy; |
| 12711 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12712 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12713 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12714 | |
| 12715 | /* Get the driver's phba structure from the dev_id and |
| 12716 | * assume the HBA is not interrupting. |
| 12717 | */ |
| 12718 | phba = (struct lpfc_hba *) dev_id; |
| 12719 | |
| 12720 | if (unlikely(!phba)) |
| 12721 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12722 | |
| 12723 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12724 | * Stuff needs to be attented to when this function is invoked as an |
| 12725 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12726 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12727 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12728 | /* Check device state for handling interrupt */ |
| 12729 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12730 | return IRQ_NONE; |
| 12731 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12732 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12733 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12734 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12735 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12736 | /* |
| 12737 | * If there is deferred error attention, do not check for |
| 12738 | * any interrupt. |
| 12739 | */ |
| 12740 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12741 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12742 | return IRQ_NONE; |
| 12743 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12744 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12745 | phba->HAregaddr); |
| 12746 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12747 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12748 | } else |
| 12749 | ha_copy = phba->ha_copy; |
| 12750 | |
| 12751 | /* |
| 12752 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12753 | */ |
| 12754 | ha_copy &= ~(phba->work_ha_mask); |
| 12755 | |
| 12756 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12757 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12758 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12759 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12760 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12761 | |
| 12762 | if (phba->cfg_multi_ring_support == 2) { |
| 12763 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12764 | * Process all events on extra ring. Take the optimized path |
| 12765 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12766 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12767 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12768 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12769 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12770 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12771 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12772 | status); |
| 12773 | } |
| 12774 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12775 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12776 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12777 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12778 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12779 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12780 | * @irq: Interrupt number. |
| 12781 | * @dev_id: The device context pointer. |
| 12782 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12783 | * This function is the HBA device-level interrupt handler to device with |
| 12784 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12785 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12786 | * requires driver attention. This function invokes the slow-path interrupt |
| 12787 | * attention handling function and fast-path interrupt attention handling |
| 12788 | * function in turn to process the relevant HBA attention events. This |
| 12789 | * function is called without any lock held. It gets the hbalock to access |
| 12790 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12791 | * |
| 12792 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12793 | * returns IRQ_NONE. |
| 12794 | **/ |
| 12795 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12796 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12797 | { |
| 12798 | struct lpfc_hba *phba; |
| 12799 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12800 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12801 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12802 | |
| 12803 | /* |
| 12804 | * Get the driver's phba structure from the dev_id and |
| 12805 | * assume the HBA is not interrupting. |
| 12806 | */ |
| 12807 | phba = (struct lpfc_hba *) dev_id; |
| 12808 | |
| 12809 | if (unlikely(!phba)) |
| 12810 | return IRQ_NONE; |
| 12811 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12812 | /* Check device state for handling interrupt */ |
| 12813 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12814 | return IRQ_NONE; |
| 12815 | |
| 12816 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12817 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12818 | spin_unlock(&phba->hbalock); |
| 12819 | return IRQ_HANDLED; |
| 12820 | } |
| 12821 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12822 | if (unlikely(!phba->ha_copy)) { |
| 12823 | spin_unlock(&phba->hbalock); |
| 12824 | return IRQ_NONE; |
| 12825 | } else if (phba->ha_copy & HA_ERATT) { |
| 12826 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12827 | /* ERATT polling has handled ERATT */ |
| 12828 | phba->ha_copy &= ~HA_ERATT; |
| 12829 | else |
| 12830 | /* Indicate interrupt handler handles ERATT */ |
| 12831 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12832 | } |
| 12833 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12834 | /* |
| 12835 | * If there is deferred error attention, do not check for any interrupt. |
| 12836 | */ |
| 12837 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12838 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12839 | return IRQ_NONE; |
| 12840 | } |
| 12841 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12842 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12843 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12844 | spin_unlock(&phba->hbalock); |
| 12845 | return IRQ_HANDLED; |
| 12846 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12847 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12848 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12849 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12850 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12851 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12852 | readl(phba->HAregaddr); /* flush */ |
| 12853 | spin_unlock(&phba->hbalock); |
| 12854 | |
| 12855 | /* |
| 12856 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12857 | */ |
| 12858 | |
| 12859 | /* status of events with mailbox and link attention */ |
| 12860 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12861 | |
| 12862 | /* status of events with ELS ring */ |
| 12863 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12864 | status2 >>= (4*LPFC_ELS_RING); |
| 12865 | |
| 12866 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12867 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12868 | else |
| 12869 | sp_irq_rc = IRQ_NONE; |
| 12870 | |
| 12871 | /* |
| 12872 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12873 | */ |
| 12874 | |
| 12875 | /* status of events with FCP ring */ |
| 12876 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12877 | status1 >>= (4*LPFC_FCP_RING); |
| 12878 | |
| 12879 | /* status of events with extra ring */ |
| 12880 | if (phba->cfg_multi_ring_support == 2) { |
| 12881 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12882 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12883 | } else |
| 12884 | status2 = 0; |
| 12885 | |
| 12886 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12887 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12888 | else |
| 12889 | fp_irq_rc = IRQ_NONE; |
| 12890 | |
| 12891 | /* Return device-level interrupt handling status */ |
| 12892 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12893 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12894 | |
| 12895 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12896 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12897 | * @phba: pointer to lpfc hba data structure. |
| 12898 | * |
| 12899 | * This routine is invoked by the worker thread to process all the pending |
| 12900 | * SLI4 els abort xri events. |
| 12901 | **/ |
| 12902 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12903 | { |
| 12904 | struct lpfc_cq_event *cq_event; |
| 12905 | |
| 12906 | /* First, declare the els xri abort event has been handled */ |
| 12907 | spin_lock_irq(&phba->hbalock); |
| 12908 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12909 | spin_unlock_irq(&phba->hbalock); |
| 12910 | /* Now, handle all the els xri abort events */ |
| 12911 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12912 | /* Get the first event from the head of the event queue */ |
| 12913 | spin_lock_irq(&phba->hbalock); |
| 12914 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12915 | cq_event, struct lpfc_cq_event, list); |
| 12916 | spin_unlock_irq(&phba->hbalock); |
| 12917 | /* Notify aborted XRI for ELS work queue */ |
| 12918 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12919 | /* Free the event processed back to the free pool */ |
| 12920 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12921 | } |
| 12922 | } |
| 12923 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12924 | /** |
| 12925 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12926 | * @phba: pointer to lpfc hba data structure |
| 12927 | * @pIocbIn: pointer to the rspiocbq |
| 12928 | * @pIocbOut: pointer to the cmdiocbq |
| 12929 | * @wcqe: pointer to the complete wcqe |
| 12930 | * |
| 12931 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12932 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12933 | * completion status information from the complete wcqe. |
| 12934 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12935 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12936 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12937 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12938 | struct lpfc_iocbq *pIocbOut, |
| 12939 | struct lpfc_wcqe_complete *wcqe) |
| 12940 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12941 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12942 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12943 | uint32_t status, max_response; |
| 12944 | struct lpfc_dmabuf *dmabuf; |
| 12945 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12946 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12947 | |
| 12948 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12949 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12950 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12951 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12952 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12953 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12954 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12955 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12956 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12957 | wcqe->total_data_placed; |
| 12958 | else |
| 12959 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12960 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12961 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12962 | switch (pIocbOut->iocb.ulpCommand) { |
| 12963 | case CMD_ELS_REQUEST64_CR: |
| 12964 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12965 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12966 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12967 | max_response = bde.tus.f.bdeSize; |
| 12968 | break; |
| 12969 | case CMD_GEN_REQUEST64_CR: |
| 12970 | max_response = 0; |
| 12971 | if (!pIocbOut->context3) |
| 12972 | break; |
| 12973 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12974 | sizeof(struct ulp_bde64); |
| 12975 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12976 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12977 | for (i = 0; i < numBdes; i++) { |
| 12978 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12979 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12980 | max_response += bde.tus.f.bdeSize; |
| 12981 | } |
| 12982 | break; |
| 12983 | default: |
| 12984 | max_response = wcqe->total_data_placed; |
| 12985 | break; |
| 12986 | } |
| 12987 | if (max_response < wcqe->total_data_placed) |
| 12988 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12989 | else |
| 12990 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12991 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12992 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12993 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12994 | /* Convert BG errors for completion status */ |
| 12995 | if (status == CQE_STATUS_DI_ERROR) { |
| 12996 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 12997 | |
| 12998 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 12999 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 13000 | else |
| 13001 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 13002 | |
| 13003 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 13004 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 13005 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13006 | BGS_GUARD_ERR_MASK; |
| 13007 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 13008 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13009 | BGS_APPTAG_ERR_MASK; |
| 13010 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 13011 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13012 | BGS_REFTAG_ERR_MASK; |
| 13013 | |
| 13014 | /* Check to see if there was any good data before the error */ |
| 13015 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 13016 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13017 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 13018 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 13019 | wcqe->total_data_placed; |
| 13020 | } |
| 13021 | |
| 13022 | /* |
| 13023 | * Set ALL the error bits to indicate we don't know what |
| 13024 | * type of error it is. |
| 13025 | */ |
| 13026 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 13027 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13028 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 13029 | BGS_GUARD_ERR_MASK); |
| 13030 | } |
| 13031 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13032 | /* Pick up HBA exchange busy condition */ |
| 13033 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 13034 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13035 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 13036 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13037 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13038 | } |
| 13039 | |
| 13040 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13041 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 13042 | * @phba: Pointer to HBA context object. |
| 13043 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13044 | * |
| 13045 | * This routine handles an ELS work-queue completion event and construct |
| 13046 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 13047 | * discovery engine to handle. |
| 13048 | * |
| 13049 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 13050 | **/ |
| 13051 | static struct lpfc_iocbq * |
| 13052 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 13053 | struct lpfc_iocbq *irspiocbq) |
| 13054 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13055 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13056 | struct lpfc_iocbq *cmdiocbq; |
| 13057 | struct lpfc_wcqe_complete *wcqe; |
| 13058 | unsigned long iflags; |
| 13059 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13060 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 13061 | if (unlikely(!pring)) |
| 13062 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13063 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13064 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13065 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13066 | pring->stats.iocb_event++; |
| 13067 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 13068 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13069 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13070 | if (unlikely(!cmdiocbq)) { |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13071 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13072 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13073 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13074 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 13075 | wcqe->word0, wcqe->total_data_placed, |
| 13076 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13077 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 13078 | return NULL; |
| 13079 | } |
| 13080 | |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13081 | /* Put the iocb back on the txcmplq */ |
| 13082 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13083 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13084 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13085 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13086 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13087 | |
| 13088 | return irspiocbq; |
| 13089 | } |
| 13090 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13091 | inline struct lpfc_cq_event * |
| 13092 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13093 | { |
| 13094 | struct lpfc_cq_event *cq_event; |
| 13095 | |
| 13096 | /* Allocate a new internal CQ_EVENT entry */ |
| 13097 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13098 | if (!cq_event) { |
| 13099 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13100 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13101 | return NULL; |
| 13102 | } |
| 13103 | |
| 13104 | /* Move the CQE into the event */ |
| 13105 | memcpy(&cq_event->cqe, entry, size); |
| 13106 | return cq_event; |
| 13107 | } |
| 13108 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13109 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13110 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 13111 | * @phba: Pointer to HBA context object. |
| 13112 | * @cqe: Pointer to mailbox completion queue entry. |
| 13113 | * |
| 13114 | * This routine process a mailbox completion queue entry with asynchrous |
| 13115 | * event. |
| 13116 | * |
| 13117 | * Return: true if work posted to worker thread, otherwise false. |
| 13118 | **/ |
| 13119 | static bool |
| 13120 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13121 | { |
| 13122 | struct lpfc_cq_event *cq_event; |
| 13123 | unsigned long iflags; |
| 13124 | |
| 13125 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13126 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13127 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13128 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13129 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13130 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13131 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13132 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13133 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13134 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 13135 | /* Set the async event flag */ |
| 13136 | phba->hba_flag |= ASYNC_EVENT; |
| 13137 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13138 | |
| 13139 | return true; |
| 13140 | } |
| 13141 | |
| 13142 | /** |
| 13143 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13144 | * @phba: Pointer to HBA context object. |
| 13145 | * @cqe: Pointer to mailbox completion queue entry. |
| 13146 | * |
| 13147 | * This routine process a mailbox completion queue entry with mailbox |
| 13148 | * completion event. |
| 13149 | * |
| 13150 | * Return: true if work posted to worker thread, otherwise false. |
| 13151 | **/ |
| 13152 | static bool |
| 13153 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13154 | { |
| 13155 | uint32_t mcqe_status; |
| 13156 | MAILBOX_t *mbox, *pmbox; |
| 13157 | struct lpfc_mqe *mqe; |
| 13158 | struct lpfc_vport *vport; |
| 13159 | struct lpfc_nodelist *ndlp; |
| 13160 | struct lpfc_dmabuf *mp; |
| 13161 | unsigned long iflags; |
| 13162 | LPFC_MBOXQ_t *pmb; |
| 13163 | bool workposted = false; |
| 13164 | int rc; |
| 13165 | |
| 13166 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13167 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13168 | goto out_no_mqe_complete; |
| 13169 | |
| 13170 | /* Get the reference to the active mbox command */ |
| 13171 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13172 | pmb = phba->sli.mbox_active; |
| 13173 | if (unlikely(!pmb)) { |
| 13174 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13175 | "1832 No pending MBOX command to handle\n"); |
| 13176 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13177 | goto out_no_mqe_complete; |
| 13178 | } |
| 13179 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13180 | mqe = &pmb->u.mqe; |
| 13181 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13182 | mbox = phba->mbox; |
| 13183 | vport = pmb->vport; |
| 13184 | |
| 13185 | /* Reset heartbeat timer */ |
| 13186 | phba->last_completion_time = jiffies; |
| 13187 | del_timer(&phba->sli.mbox_tmo); |
| 13188 | |
| 13189 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13190 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13191 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13192 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13193 | /* |
| 13194 | * For mcqe errors, conditionally move a modified error code to |
| 13195 | * the mbox so that the error will not be missed. |
| 13196 | */ |
| 13197 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13198 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13199 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13200 | bf_set(lpfc_mqe_status, mqe, |
| 13201 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13202 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13203 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13204 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13205 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13206 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13207 | mcqe_status, |
| 13208 | pmbox->un.varWords[0], 0); |
| 13209 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13210 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13211 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13212 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 13213 | * RID of the PPI using the same mbox buffer. |
| 13214 | */ |
| 13215 | lpfc_unreg_login(phba, vport->vpi, |
| 13216 | pmbox->un.varWords[0], pmb); |
| 13217 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13218 | pmb->ctx_buf = mp; |
| 13219 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13220 | pmb->vport = vport; |
| 13221 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13222 | if (rc != MBX_BUSY) |
| 13223 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 13224 | LOG_SLI, "0385 rc should " |
| 13225 | "have been MBX_BUSY\n"); |
| 13226 | if (rc != MBX_NOT_FINISHED) |
| 13227 | goto send_current_mbox; |
| 13228 | } |
| 13229 | } |
| 13230 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13231 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13232 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13233 | |
| 13234 | /* There is mailbox completion work to do */ |
| 13235 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13236 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13237 | phba->work_ha |= HA_MBATT; |
| 13238 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13239 | workposted = true; |
| 13240 | |
| 13241 | send_current_mbox: |
| 13242 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13243 | /* Release the mailbox command posting token */ |
| 13244 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13245 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13246 | phba->sli.mbox_active = NULL; |
| 13247 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13248 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13249 | lpfc_worker_wake_up(phba); |
| 13250 | out_no_mqe_complete: |
| 13251 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13252 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 13253 | return workposted; |
| 13254 | } |
| 13255 | |
| 13256 | /** |
| 13257 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13258 | * @phba: Pointer to HBA context object. |
| 13259 | * @cqe: Pointer to mailbox completion queue entry. |
| 13260 | * |
| 13261 | * This routine process a mailbox completion queue entry, it invokes the |
| 13262 | * proper mailbox complete handling or asynchrous event handling routine |
| 13263 | * according to the MCQE's async bit. |
| 13264 | * |
| 13265 | * Return: true if work posted to worker thread, otherwise false. |
| 13266 | **/ |
| 13267 | static bool |
| 13268 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 13269 | { |
| 13270 | struct lpfc_mcqe mcqe; |
| 13271 | bool workposted; |
| 13272 | |
| 13273 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13274 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13275 | |
| 13276 | /* Invoke the proper event handling routine */ |
| 13277 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13278 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13279 | else |
| 13280 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13281 | return workposted; |
| 13282 | } |
| 13283 | |
| 13284 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13285 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13286 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13287 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13288 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13289 | * |
| 13290 | * This routine handles an ELS work-queue completion event. |
| 13291 | * |
| 13292 | * Return: true if work posted to worker thread, otherwise false. |
| 13293 | **/ |
| 13294 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13295 | 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] | 13296 | struct lpfc_wcqe_complete *wcqe) |
| 13297 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13298 | struct lpfc_iocbq *irspiocbq; |
| 13299 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13300 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13301 | int txq_cnt = 0; |
| 13302 | int txcmplq_cnt = 0; |
| 13303 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13304 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13305 | /* Check for response status */ |
| 13306 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13307 | /* Log the error status */ |
| 13308 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13309 | "0357 ELS CQE error: status=x%x: " |
| 13310 | "CQE: %08x %08x %08x %08x\n", |
| 13311 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13312 | wcqe->word0, wcqe->total_data_placed, |
| 13313 | wcqe->parameter, wcqe->word3); |
| 13314 | } |
| 13315 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13316 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13317 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13318 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13319 | if (!list_empty(&pring->txq)) |
| 13320 | txq_cnt++; |
| 13321 | if (!list_empty(&pring->txcmplq)) |
| 13322 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13323 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13324 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 13325 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13326 | txq_cnt, phba->iocb_cnt, |
| 13327 | fcp_txcmplq_cnt, |
| 13328 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13329 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13330 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13331 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13332 | /* Save off the slow-path queue event for work thread to process */ |
| 13333 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13334 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13335 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13336 | &phba->sli4_hba.sp_queue_event); |
| 13337 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13338 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13339 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13340 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13341 | } |
| 13342 | |
| 13343 | /** |
| 13344 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13345 | * @phba: Pointer to HBA context object. |
| 13346 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13347 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13348 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13349 | * proper WQ release routine to the slow-path WQ. |
| 13350 | **/ |
| 13351 | static void |
| 13352 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13353 | struct lpfc_wcqe_release *wcqe) |
| 13354 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13355 | /* sanity check on queue memory */ |
| 13356 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13357 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13358 | /* Check for the slow-path ELS work queue */ |
| 13359 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13360 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13361 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13362 | else |
| 13363 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13364 | "2579 Slow-path wqe consume event carries " |
| 13365 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13366 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13367 | phba->sli4_hba.els_wq->queue_id); |
| 13368 | } |
| 13369 | |
| 13370 | /** |
| 13371 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13372 | * @phba: Pointer to HBA context object. |
| 13373 | * @cq: Pointer to a WQ completion queue. |
| 13374 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13375 | * |
| 13376 | * This routine handles an XRI abort event. |
| 13377 | * |
| 13378 | * Return: true if work posted to worker thread, otherwise false. |
| 13379 | **/ |
| 13380 | static bool |
| 13381 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13382 | struct lpfc_queue *cq, |
| 13383 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13384 | { |
| 13385 | bool workposted = false; |
| 13386 | struct lpfc_cq_event *cq_event; |
| 13387 | unsigned long iflags; |
| 13388 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13389 | switch (cq->subtype) { |
| 13390 | case LPFC_FCP: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13391 | lpfc_sli4_fcp_xri_aborted(phba, wcqe, cq->hdwq); |
| 13392 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13393 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13394 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13395 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13396 | cq_event = lpfc_cq_event_setup( |
| 13397 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13398 | if (!cq_event) |
| 13399 | return false; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13400 | cq_event->hdwq = cq->hdwq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13401 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13402 | list_add_tail(&cq_event->list, |
| 13403 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13404 | /* Set the els xri abort event flag */ |
| 13405 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13406 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13407 | workposted = true; |
| 13408 | break; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13409 | case LPFC_NVME: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13410 | /* Notify aborted XRI for NVME work queue */ |
| 13411 | if (phba->nvmet_support) |
| 13412 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13413 | else |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13414 | lpfc_sli4_nvme_xri_aborted(phba, wcqe, cq->hdwq); |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13415 | |
| 13416 | workposted = false; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13417 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13418 | default: |
| 13419 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13420 | "0603 Invalid CQ subtype %d: " |
| 13421 | "%08x %08x %08x %08x\n", |
| 13422 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13423 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13424 | workposted = false; |
| 13425 | break; |
| 13426 | } |
| 13427 | return workposted; |
| 13428 | } |
| 13429 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13430 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13431 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13432 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13433 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13434 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13435 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13436 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13437 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13438 | * |
| 13439 | * Return: true if work posted to worker thread, otherwise false. |
| 13440 | **/ |
| 13441 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13442 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13443 | { |
| 13444 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13445 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13446 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13447 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13448 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13449 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13450 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13451 | unsigned long iflags; |
| 13452 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13453 | /* sanity check on queue memory */ |
| 13454 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13455 | return workposted; |
| 13456 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13457 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13458 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13459 | else |
| 13460 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13461 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13462 | goto out; |
| 13463 | |
| 13464 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13465 | switch (status) { |
| 13466 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13467 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13468 | "2537 Receive Frame Truncated!!\n"); |
| 13469 | case FC_STATUS_RQ_SUCCESS: |
| 13470 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13471 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13472 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13473 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13474 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13475 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13476 | goto out; |
| 13477 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13478 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13479 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13480 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13481 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13482 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13483 | |
| 13484 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13485 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13486 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13487 | /* Handle MDS Loopback frames */ |
| 13488 | lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf); |
| 13489 | break; |
| 13490 | } |
| 13491 | |
| 13492 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13493 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13494 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13495 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13496 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13497 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13498 | workposted = true; |
| 13499 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13500 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13501 | if (phba->nvmet_support) { |
| 13502 | tgtp = phba->targetport->private; |
| 13503 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13504 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13505 | "%d: %x %x %x\n", |
| 13506 | status, hrq->RQ_buf_posted, |
| 13507 | hrq->RQ_no_posted_buf, |
| 13508 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13509 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13510 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13511 | } |
| 13512 | /* fallthrough */ |
| 13513 | |
| 13514 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13515 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13516 | /* Post more buffers if possible */ |
| 13517 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13518 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13519 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13520 | workposted = true; |
| 13521 | break; |
| 13522 | } |
| 13523 | out: |
| 13524 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13525 | } |
| 13526 | |
| 13527 | /** |
| 13528 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13529 | * @phba: Pointer to HBA context object. |
| 13530 | * @cq: Pointer to the completion queue. |
| 13531 | * @wcqe: Pointer to a completion queue entry. |
| 13532 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13533 | * 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] | 13534 | * entry. |
| 13535 | * |
| 13536 | * Return: true if work posted to worker thread, otherwise false. |
| 13537 | **/ |
| 13538 | static bool |
| 13539 | 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] | 13540 | struct lpfc_cqe *cqe) |
| 13541 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13542 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13543 | bool workposted = false; |
| 13544 | |
| 13545 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13546 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13547 | |
| 13548 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13549 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13550 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13551 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13552 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13553 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13554 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13555 | break; |
| 13556 | case CQE_CODE_RELEASE_WQE: |
| 13557 | /* Process the WQ release event */ |
| 13558 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13559 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13560 | break; |
| 13561 | case CQE_CODE_XRI_ABORTED: |
| 13562 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13563 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13564 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13565 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13566 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13567 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13568 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13569 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13570 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13571 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13572 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13573 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13574 | default: |
| 13575 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13576 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13577 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13578 | break; |
| 13579 | } |
| 13580 | return workposted; |
| 13581 | } |
| 13582 | |
| 13583 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13584 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13585 | * @phba: Pointer to HBA context object. |
| 13586 | * @eqe: Pointer to fast-path event queue entry. |
| 13587 | * |
| 13588 | * This routine process a event queue entry from the slow-path event queue. |
| 13589 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13590 | * completion event on a completion queue, if not, an error shall be logged |
| 13591 | * and just return. Otherwise, it will get to the corresponding completion |
| 13592 | * queue and process all the entries on that completion queue, rearm the |
| 13593 | * completion queue, and then return. |
| 13594 | * |
| 13595 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13596 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13597 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13598 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13599 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13600 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13601 | uint16_t cqid; |
| 13602 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13603 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13604 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13605 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13606 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13607 | if (childq->queue_id == cqid) { |
| 13608 | cq = childq; |
| 13609 | break; |
| 13610 | } |
| 13611 | } |
| 13612 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13613 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13614 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13615 | "0365 Slow-path CQ identifier " |
| 13616 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13617 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13618 | } |
| 13619 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13620 | /* Save EQ associated with this CQ */ |
| 13621 | cq->assoc_qp = speq; |
| 13622 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 13623 | if (!queue_work_on(cq->chann, phba->wq, &cq->spwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13624 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13625 | "0390 Cannot schedule soft IRQ " |
| 13626 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13627 | cqid, cq->queue_id, smp_processor_id()); |
| 13628 | } |
| 13629 | |
| 13630 | /** |
| 13631 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13632 | * @phba: Pointer to HBA context object. |
| 13633 | * |
| 13634 | * This routine process a event queue entry from the slow-path event queue. |
| 13635 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13636 | * completion event on a completion queue, if not, an error shall be logged |
| 13637 | * and just return. Otherwise, it will get to the corresponding completion |
| 13638 | * queue and process all the entries on that completion queue, rearm the |
| 13639 | * completion queue, and then return. |
| 13640 | * |
| 13641 | **/ |
| 13642 | static void |
| 13643 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13644 | { |
| 13645 | struct lpfc_queue *cq = |
| 13646 | container_of(work, struct lpfc_queue, spwork); |
| 13647 | struct lpfc_hba *phba = cq->phba; |
| 13648 | struct lpfc_cqe *cqe; |
| 13649 | bool workposted = false; |
| 13650 | int ccount = 0; |
| 13651 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13652 | /* Process all the entries to the CQ */ |
| 13653 | switch (cq->type) { |
| 13654 | case LPFC_MCQ: |
| 13655 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 13656 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13657 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13658 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13659 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13660 | } |
| 13661 | break; |
| 13662 | case LPFC_WCQ: |
| 13663 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13664 | if (cq->subtype == LPFC_FCP || |
| 13665 | cq->subtype == LPFC_NVME) { |
| 13666 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13667 | if (phba->ktime_on) |
| 13668 | cq->isr_timestamp = ktime_get_ns(); |
| 13669 | else |
| 13670 | cq->isr_timestamp = 0; |
| 13671 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13672 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13673 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13674 | } else { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13675 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 13676 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13677 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13678 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13679 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13680 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13681 | |
| 13682 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13683 | if (ccount > cq->CQ_max_cqe) |
| 13684 | cq->CQ_max_cqe = ccount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13685 | break; |
| 13686 | default: |
| 13687 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13688 | "0370 Invalid completion queue type (%d)\n", |
| 13689 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13690 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13691 | } |
| 13692 | |
| 13693 | /* Catch the no cq entry condition, log an error */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13694 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13695 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13696 | "0371 No entry from the CQ: identifier " |
| 13697 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 13698 | |
| 13699 | /* In any case, flash and re-arm the RCQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 13700 | phba->sli4_hba.sli4_cq_release(cq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13701 | |
| 13702 | /* wake up worker thread if there are works to be done */ |
| 13703 | if (workposted) |
| 13704 | lpfc_worker_wake_up(phba); |
| 13705 | } |
| 13706 | |
| 13707 | /** |
| 13708 | * 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] | 13709 | * @phba: Pointer to HBA context object. |
| 13710 | * @cq: Pointer to associated CQ |
| 13711 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13712 | * |
| 13713 | * This routine process a fast-path work queue completion entry from fast-path |
| 13714 | * event queue for FCP command response completion. |
| 13715 | **/ |
| 13716 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13717 | 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] | 13718 | struct lpfc_wcqe_complete *wcqe) |
| 13719 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13720 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13721 | struct lpfc_iocbq *cmdiocbq; |
| 13722 | struct lpfc_iocbq irspiocbq; |
| 13723 | unsigned long iflags; |
| 13724 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13725 | /* Check for response status */ |
| 13726 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13727 | /* If resource errors reported from HBA, reduce queue |
| 13728 | * depth of the SCSI device. |
| 13729 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13730 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13731 | IOSTAT_LOCAL_REJECT)) && |
| 13732 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13733 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13734 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13735 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13736 | /* Log the error status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13737 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13738 | "0373 FCP CQE error: status=x%x: " |
| 13739 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13740 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13741 | wcqe->word0, wcqe->total_data_placed, |
| 13742 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13743 | } |
| 13744 | |
| 13745 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13746 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13747 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13748 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13749 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13750 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13751 | if (unlikely(!cmdiocbq)) { |
| 13752 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13753 | "0374 FCP complete with no corresponding " |
| 13754 | "cmdiocb: iotag (%d)\n", |
| 13755 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13756 | return; |
| 13757 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13758 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13759 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13760 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13761 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13762 | if (cmdiocbq->wqe_cmpl) { |
| 13763 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13764 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13765 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13766 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13767 | } |
| 13768 | |
| 13769 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13770 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13771 | return; |
| 13772 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13773 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13774 | "0375 FCP cmdiocb not callback function " |
| 13775 | "iotag: (%d)\n", |
| 13776 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13777 | return; |
| 13778 | } |
| 13779 | |
| 13780 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13781 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13782 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13783 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13784 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13785 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13786 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13787 | } |
| 13788 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13789 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13790 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13791 | } |
| 13792 | |
| 13793 | /** |
| 13794 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13795 | * @phba: Pointer to HBA context object. |
| 13796 | * @cq: Pointer to completion queue. |
| 13797 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13798 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13799 | * 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] | 13800 | * proper WQ release routine to the slow-path WQ. |
| 13801 | **/ |
| 13802 | static void |
| 13803 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13804 | struct lpfc_wcqe_release *wcqe) |
| 13805 | { |
| 13806 | struct lpfc_queue *childwq; |
| 13807 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13808 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13809 | |
| 13810 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13811 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13812 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13813 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13814 | lpfc_sli4_wq_release(childwq, |
| 13815 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13816 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 13817 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13818 | wqid_matched = true; |
| 13819 | break; |
| 13820 | } |
| 13821 | } |
| 13822 | /* Report warning log message if no match found */ |
| 13823 | if (wqid_matched != true) |
| 13824 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13825 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13826 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13827 | } |
| 13828 | |
| 13829 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13830 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13831 | * @phba: Pointer to HBA context object. |
| 13832 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13833 | * |
| 13834 | * This routine process a receive-queue completion queue entry. |
| 13835 | * |
| 13836 | * Return: true if work posted to worker thread, otherwise false. |
| 13837 | **/ |
| 13838 | static bool |
| 13839 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13840 | struct lpfc_rcqe *rcqe) |
| 13841 | { |
| 13842 | bool workposted = false; |
| 13843 | struct lpfc_queue *hrq; |
| 13844 | struct lpfc_queue *drq; |
| 13845 | struct rqb_dmabuf *dma_buf; |
| 13846 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13847 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13848 | uint32_t status, rq_id; |
| 13849 | unsigned long iflags; |
| 13850 | uint32_t fctl, idx; |
| 13851 | |
| 13852 | if ((phba->nvmet_support == 0) || |
| 13853 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13854 | return workposted; |
| 13855 | |
| 13856 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13857 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13858 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13859 | |
| 13860 | /* sanity check on queue memory */ |
| 13861 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13862 | return workposted; |
| 13863 | |
| 13864 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13865 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13866 | else |
| 13867 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13868 | |
| 13869 | if ((phba->nvmet_support == 0) || |
| 13870 | (rq_id != hrq->queue_id)) |
| 13871 | return workposted; |
| 13872 | |
| 13873 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13874 | switch (status) { |
| 13875 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13876 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13877 | "6126 Receive Frame Truncated!!\n"); |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 13878 | /* Drop thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13879 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13880 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13881 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13882 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13883 | if (!dma_buf) { |
| 13884 | hrq->RQ_no_buf_found++; |
| 13885 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13886 | goto out; |
| 13887 | } |
| 13888 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13889 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13890 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13891 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13892 | |
| 13893 | /* Just some basic sanity checks on FCP Command frame */ |
| 13894 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 13895 | fc_hdr->fh_f_ctl[1] << 8 | |
| 13896 | fc_hdr->fh_f_ctl[2]); |
| 13897 | if (((fctl & |
| 13898 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 13899 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 13900 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 13901 | goto drop; |
| 13902 | |
| 13903 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
| 13904 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13905 | lpfc_nvmet_unsol_fcp_event( |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 13906 | phba, idx, dma_buf, |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13907 | cq->isr_timestamp); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13908 | return false; |
| 13909 | } |
| 13910 | drop: |
| 13911 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
| 13912 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13913 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13914 | if (phba->nvmet_support) { |
| 13915 | tgtp = phba->targetport->private; |
| 13916 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13917 | "6401 RQE Error x%x, posted %d err_cnt " |
| 13918 | "%d: %x %x %x\n", |
| 13919 | status, hrq->RQ_buf_posted, |
| 13920 | hrq->RQ_no_posted_buf, |
| 13921 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13922 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13923 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13924 | } |
| 13925 | /* fallthrough */ |
| 13926 | |
| 13927 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13928 | hrq->RQ_no_posted_buf++; |
| 13929 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13930 | break; |
| 13931 | } |
| 13932 | out: |
| 13933 | return workposted; |
| 13934 | } |
| 13935 | |
| 13936 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13937 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13938 | * @cq: Pointer to the completion queue. |
| 13939 | * @eqe: Pointer to fast-path completion queue entry. |
| 13940 | * |
| 13941 | * This routine process a fast-path work queue completion entry from fast-path |
| 13942 | * event queue for FCP command response completion. |
| 13943 | **/ |
| 13944 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13945 | 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] | 13946 | struct lpfc_cqe *cqe) |
| 13947 | { |
| 13948 | struct lpfc_wcqe_release wcqe; |
| 13949 | bool workposted = false; |
| 13950 | |
| 13951 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13952 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13953 | |
| 13954 | /* Check and process for different type of WCQE and dispatch */ |
| 13955 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 13956 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13957 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13958 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13959 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 13960 | phba->last_completion_time = jiffies; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13961 | if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME)) |
| 13962 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
| 13963 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13964 | if (cq->subtype == LPFC_NVME_LS) |
| 13965 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13966 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13967 | break; |
| 13968 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13969 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13970 | /* Process the WQ release event */ |
| 13971 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 13972 | (struct lpfc_wcqe_release *)&wcqe); |
| 13973 | break; |
| 13974 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13975 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13976 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13977 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13978 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 13979 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 13980 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13981 | case CQE_CODE_RECEIVE_V1: |
| 13982 | case CQE_CODE_RECEIVE: |
| 13983 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13984 | if (cq->subtype == LPFC_NVMET) { |
| 13985 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 13986 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 13987 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13988 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13989 | default: |
| 13990 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13991 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13992 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 13993 | break; |
| 13994 | } |
| 13995 | return workposted; |
| 13996 | } |
| 13997 | |
| 13998 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13999 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14000 | * @phba: Pointer to HBA context object. |
| 14001 | * @eqe: Pointer to fast-path event queue entry. |
| 14002 | * |
| 14003 | * This routine process a event queue entry from the fast-path event queue. |
| 14004 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14005 | * completion event on a completion queue, if not, an error shall be logged |
| 14006 | * and just return. Otherwise, it will get to the corresponding completion |
| 14007 | * queue and process all the entries on the completion queue, rearm the |
| 14008 | * completion queue, and then return. |
| 14009 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14010 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14011 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 14012 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14013 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14014 | struct lpfc_queue *cq = NULL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14015 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14016 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14017 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14018 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14019 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14020 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14021 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14022 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14023 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14024 | } |
| 14025 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14026 | /* Get the reference to the corresponding CQ */ |
| 14027 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14028 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14029 | /* Use the fast lookup method first */ |
| 14030 | if (cqid <= phba->sli4_hba.cq_max) { |
| 14031 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 14032 | if (cq) |
| 14033 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14034 | } |
| 14035 | |
| 14036 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14037 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14038 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14039 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14040 | /* Process NVMET unsol rcv */ |
| 14041 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14042 | goto process_cq; |
| 14043 | } |
| 14044 | } |
| 14045 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14046 | if (phba->sli4_hba.nvmels_cq && |
| 14047 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14048 | /* Process NVME unsol rcv */ |
| 14049 | cq = phba->sli4_hba.nvmels_cq; |
| 14050 | } |
| 14051 | |
| 14052 | /* Otherwise this is a Slow path event */ |
| 14053 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14054 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 14055 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14056 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14057 | } |
| 14058 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14059 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14060 | if (unlikely(cqid != cq->queue_id)) { |
| 14061 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14062 | "0368 Miss-matched fast-path completion " |
| 14063 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14064 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14065 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14066 | } |
| 14067 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14068 | work_cq: |
James Smart | 45aa312 | 2019-01-28 11:14:29 -0800 | [diff] [blame] | 14069 | if (!queue_work_on(cq->chann, phba->wq, &cq->irqwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14070 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14071 | "0363 Cannot schedule soft IRQ " |
| 14072 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 14073 | cqid, cq->queue_id, smp_processor_id()); |
| 14074 | } |
| 14075 | |
| 14076 | /** |
| 14077 | * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14078 | * @phba: Pointer to HBA context object. |
| 14079 | * @eqe: Pointer to fast-path event queue entry. |
| 14080 | * |
| 14081 | * This routine process a event queue entry from the fast-path event queue. |
| 14082 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14083 | * completion event on a completion queue, if not, an error shall be logged |
| 14084 | * and just return. Otherwise, it will get to the corresponding completion |
| 14085 | * queue and process all the entries on the completion queue, rearm the |
| 14086 | * completion queue, and then return. |
| 14087 | **/ |
| 14088 | static void |
| 14089 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
| 14090 | { |
| 14091 | struct lpfc_queue *cq = |
| 14092 | container_of(work, struct lpfc_queue, irqwork); |
| 14093 | struct lpfc_hba *phba = cq->phba; |
| 14094 | struct lpfc_cqe *cqe; |
| 14095 | bool workposted = false; |
| 14096 | int ccount = 0; |
| 14097 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14098 | /* Process all the entries to the CQ */ |
| 14099 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 14100 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 14101 | if (phba->ktime_on) |
| 14102 | cq->isr_timestamp = ktime_get_ns(); |
| 14103 | else |
| 14104 | cq->isr_timestamp = 0; |
| 14105 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14106 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14107 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 14108 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14109 | } |
| 14110 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14111 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14112 | if (ccount > cq->CQ_max_cqe) |
| 14113 | cq->CQ_max_cqe = ccount; |
| 14114 | cq->assoc_qp->EQ_cqe_cnt += ccount; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14115 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14116 | /* Catch the no cq entry condition */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14117 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14118 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14119 | "0369 No entry from fast-path completion " |
| 14120 | "queue fcpcqid=%d\n", cq->queue_id); |
| 14121 | |
| 14122 | /* In any case, flash and re-arm the CQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14123 | phba->sli4_hba.sli4_cq_release(cq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14124 | |
| 14125 | /* wake up worker thread if there are works to be done */ |
| 14126 | if (workposted) |
| 14127 | lpfc_worker_wake_up(phba); |
| 14128 | } |
| 14129 | |
| 14130 | static void |
| 14131 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 14132 | { |
| 14133 | struct lpfc_eqe *eqe; |
| 14134 | |
| 14135 | /* walk all the EQ entries and drop on the floor */ |
| 14136 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 14137 | ; |
| 14138 | |
| 14139 | /* Clear and re-arm the EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14140 | phba->sli4_hba.sli4_eq_release(eq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14141 | } |
| 14142 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14143 | |
| 14144 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14145 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14146 | * @irq: Interrupt number. |
| 14147 | * @dev_id: The device context pointer. |
| 14148 | * |
| 14149 | * This function is directly called from the PCI layer as an interrupt |
| 14150 | * service routine when device with SLI-4 interface spec is enabled with |
| 14151 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14152 | * ring event in the HBA. However, when the device is enabled with either |
| 14153 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14154 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14155 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14156 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14157 | * the intrrupt context. This function is called without any lock held. |
| 14158 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14159 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14160 | * equal to that of FCP CQ index. |
| 14161 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14162 | * The link attention and ELS ring attention events are handled |
| 14163 | * by the worker thread. The interrupt handler signals the worker thread |
| 14164 | * and returns for these events. This function is called without any lock |
| 14165 | * held. It gets the hbalock to access and update SLI data structures. |
| 14166 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14167 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14168 | * returns IRQ_NONE. |
| 14169 | **/ |
| 14170 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14171 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14172 | { |
| 14173 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14174 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14175 | struct lpfc_queue *fpeq; |
| 14176 | struct lpfc_eqe *eqe; |
| 14177 | unsigned long iflag; |
| 14178 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14179 | int hba_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14180 | |
| 14181 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14182 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14183 | phba = hba_eq_hdl->phba; |
| 14184 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14185 | |
| 14186 | if (unlikely(!phba)) |
| 14187 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14188 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14189 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14190 | |
| 14191 | /* Get to the EQ struct associated with this vector */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14192 | fpeq = phba->sli4_hba.hdwq[hba_eqidx].hba_eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14193 | if (unlikely(!fpeq)) |
| 14194 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14195 | |
| 14196 | /* Check device state for handling interrupt */ |
| 14197 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14198 | /* Check again for link_state with lock held */ |
| 14199 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14200 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14201 | /* Flush, clear interrupt, and rearm the EQ */ |
| 14202 | lpfc_sli4_eq_flush(phba, fpeq); |
| 14203 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14204 | return IRQ_NONE; |
| 14205 | } |
| 14206 | |
| 14207 | /* |
| 14208 | * Process all the event on FCP fast-path EQ |
| 14209 | */ |
| 14210 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14211 | lpfc_sli4_hba_handle_eqe(phba, eqe, hba_eqidx); |
| 14212 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 14213 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14214 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14215 | } |
| 14216 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14217 | /* Track the max number of EQEs processed in 1 intr */ |
| 14218 | if (ecount > fpeq->EQ_max_eqe) |
| 14219 | fpeq->EQ_max_eqe = ecount; |
| 14220 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14221 | /* Always clear and re-arm the fast-path EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14222 | phba->sli4_hba.sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14223 | |
| 14224 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14225 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14226 | if (phba->intr_type == MSIX) |
| 14227 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14228 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14229 | "0358 MSI-X interrupt with no EQE\n"); |
| 14230 | else |
| 14231 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14232 | return IRQ_NONE; |
| 14233 | } |
| 14234 | |
| 14235 | return IRQ_HANDLED; |
| 14236 | } /* lpfc_sli4_fp_intr_handler */ |
| 14237 | |
| 14238 | /** |
| 14239 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14240 | * @irq: Interrupt number. |
| 14241 | * @dev_id: The device context pointer. |
| 14242 | * |
| 14243 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14244 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14245 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14246 | * driver attention. This function invokes the slow-path interrupt attention |
| 14247 | * handling function and fast-path interrupt attention handling function in |
| 14248 | * turn to process the relevant HBA attention events. This function is called |
| 14249 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14250 | * structures. |
| 14251 | * |
| 14252 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14253 | * returns IRQ_NONE. |
| 14254 | **/ |
| 14255 | irqreturn_t |
| 14256 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14257 | { |
| 14258 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14259 | irqreturn_t hba_irq_rc; |
| 14260 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14261 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14262 | |
| 14263 | /* Get the driver's phba structure from the dev_id */ |
| 14264 | phba = (struct lpfc_hba *)dev_id; |
| 14265 | |
| 14266 | if (unlikely(!phba)) |
| 14267 | return IRQ_NONE; |
| 14268 | |
| 14269 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14270 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14271 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14272 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14273 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14274 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14275 | if (hba_irq_rc == IRQ_HANDLED) |
| 14276 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14277 | } |
| 14278 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14279 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14280 | } /* lpfc_sli4_intr_handler */ |
| 14281 | |
| 14282 | /** |
| 14283 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14284 | * @queue: The queue structure to free. |
| 14285 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14286 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14287 | * the host resident queue. This function must be called after destroying the |
| 14288 | * queue on the HBA. |
| 14289 | **/ |
| 14290 | void |
| 14291 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14292 | { |
| 14293 | struct lpfc_dmabuf *dmabuf; |
| 14294 | |
| 14295 | if (!queue) |
| 14296 | return; |
| 14297 | |
| 14298 | while (!list_empty(&queue->page_list)) { |
| 14299 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14300 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14301 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14302 | dmabuf->virt, dmabuf->phys); |
| 14303 | kfree(dmabuf); |
| 14304 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14305 | if (queue->rqbp) { |
| 14306 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14307 | kfree(queue->rqbp); |
| 14308 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14309 | |
| 14310 | if (!list_empty(&queue->wq_list)) |
| 14311 | list_del(&queue->wq_list); |
| 14312 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14313 | kfree(queue); |
| 14314 | return; |
| 14315 | } |
| 14316 | |
| 14317 | /** |
| 14318 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14319 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14320 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14321 | * @entry_size: The size of each queue entry for this queue. |
| 14322 | * @entry count: The number of entries that this queue will handle. |
| 14323 | * |
| 14324 | * This function allocates a queue structure and the DMAable memory used for |
| 14325 | * the host resident queue. This function must be called before creating the |
| 14326 | * queue on the HBA. |
| 14327 | **/ |
| 14328 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14329 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
| 14330 | uint32_t entry_size, uint32_t entry_count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14331 | { |
| 14332 | struct lpfc_queue *queue; |
| 14333 | struct lpfc_dmabuf *dmabuf; |
| 14334 | int x, total_qe_count; |
| 14335 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14336 | 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] | 14337 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14338 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14339 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14340 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14341 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 14342 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 14343 | if (!queue) |
| 14344 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14345 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 14346 | hw_page_size))/hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14347 | |
| 14348 | /* If needed, Adjust page count to match the max the adapter supports */ |
Ewan D. Milne | 4e87eb2 | 2018-12-13 15:25:16 -0500 | [diff] [blame] | 14349 | if (phba->sli4_hba.pc_sli4_params.wqpcnt && |
| 14350 | (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14351 | queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14352 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14353 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14354 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14355 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14356 | INIT_LIST_HEAD(&queue->page_list); |
| 14357 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14358 | |
| 14359 | /* Set queue parameters now. If the system cannot provide memory |
| 14360 | * resources, the free routine needs to know what was allocated. |
| 14361 | */ |
| 14362 | queue->entry_size = entry_size; |
| 14363 | queue->entry_count = entry_count; |
| 14364 | queue->page_size = hw_page_size; |
| 14365 | queue->phba = phba; |
| 14366 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14367 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 14368 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 14369 | if (!dmabuf) |
| 14370 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 14371 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 14372 | hw_page_size, &dmabuf->phys, |
| 14373 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14374 | if (!dmabuf->virt) { |
| 14375 | kfree(dmabuf); |
| 14376 | goto out_fail; |
| 14377 | } |
| 14378 | dmabuf->buffer_tag = x; |
| 14379 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 14380 | /* initialize queue's entry array */ |
| 14381 | dma_pointer = dmabuf->virt; |
| 14382 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14383 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14384 | total_qe_count++, dma_pointer += entry_size) { |
| 14385 | queue->qe[total_qe_count].address = dma_pointer; |
| 14386 | } |
| 14387 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14388 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14389 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14390 | |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14391 | /* entry_repost will be set during q creation */ |
| 14392 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14393 | return queue; |
| 14394 | out_fail: |
| 14395 | lpfc_sli4_queue_free(queue); |
| 14396 | return NULL; |
| 14397 | } |
| 14398 | |
| 14399 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14400 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14401 | * @phba: HBA structure that indicates port to create a queue on. |
| 14402 | * @pci_barset: PCI BAR set flag. |
| 14403 | * |
| 14404 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14405 | * memory address if not already done so and return it. The returned host |
| 14406 | * memory address can be NULL. |
| 14407 | */ |
| 14408 | static void __iomem * |
| 14409 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14410 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14411 | if (!phba->pcidev) |
| 14412 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14413 | |
| 14414 | switch (pci_barset) { |
| 14415 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14416 | return phba->pci_bar0_memmap_p; |
| 14417 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14418 | return phba->pci_bar2_memmap_p; |
| 14419 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14420 | return phba->pci_bar4_memmap_p; |
| 14421 | default: |
| 14422 | break; |
| 14423 | } |
| 14424 | return NULL; |
| 14425 | } |
| 14426 | |
| 14427 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14428 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14429 | * @phba: HBA structure that indicates port to create a queue on. |
| 14430 | * @startq: The starting FCP EQ to modify |
| 14431 | * |
| 14432 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 14433 | * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be |
| 14434 | * updated in one mailbox command. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14435 | * |
| 14436 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 14437 | * is used to get the starting FCP EQ to change. |
| 14438 | * This function is asynchronous and will wait for the mailbox |
| 14439 | * command to finish before continuing. |
| 14440 | * |
| 14441 | * On success this function will return a zero. If unable to allocate enough |
| 14442 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14443 | * fails this function will return -ENXIO. |
| 14444 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14445 | int |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14446 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
| 14447 | uint32_t numq, uint32_t imax) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14448 | { |
| 14449 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14450 | LPFC_MBOXQ_t *mbox; |
| 14451 | struct lpfc_queue *eq; |
| 14452 | int cnt, rc, length, status = 0; |
| 14453 | uint32_t shdr_status, shdr_add_status; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14454 | uint32_t result, val; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14455 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14456 | union lpfc_sli4_cfg_shdr *shdr; |
| 14457 | uint16_t dmult; |
| 14458 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14459 | if (startq >= phba->cfg_irq_chann) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14460 | return 0; |
| 14461 | |
| 14462 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14463 | if (!mbox) |
| 14464 | return -ENOMEM; |
| 14465 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14466 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14467 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14468 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14469 | length, LPFC_SLI4_MBX_EMBED); |
| 14470 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14471 | |
| 14472 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14473 | result = imax / phba->cfg_irq_chann; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14474 | if (result > LPFC_DMULT_CONST || result == 0) |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14475 | dmult = 0; |
| 14476 | else |
| 14477 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14478 | if (dmult > LPFC_DMULT_MAX) |
| 14479 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14480 | |
| 14481 | cnt = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14482 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14483 | eq = phba->sli4_hba.hdwq[qidx].hba_eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14484 | if (!eq) |
| 14485 | continue; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14486 | eq->q_mode = imax; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14487 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14488 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14489 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 14490 | cnt++; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14491 | |
| 14492 | /* q_mode is only used for auto_imax */ |
| 14493 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14494 | /* Use EQ Delay Register method for q_mode */ |
| 14495 | |
| 14496 | /* Convert for EQ Delay register */ |
| 14497 | val = phba->cfg_fcp_imax; |
| 14498 | if (val) { |
| 14499 | /* First, interrupts per sec per EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14500 | val = phba->cfg_fcp_imax / phba->cfg_irq_chann; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14501 | |
| 14502 | /* us delay between each interrupt */ |
| 14503 | val = LPFC_SEC_TO_USEC / val; |
| 14504 | } |
| 14505 | eq->q_mode = val; |
| 14506 | } else { |
| 14507 | eq->q_mode = imax; |
| 14508 | } |
| 14509 | |
| 14510 | if (cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14511 | break; |
| 14512 | } |
| 14513 | eq_delay->u.request.num_eq = cnt; |
| 14514 | |
| 14515 | mbox->vport = phba->pport; |
| 14516 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14517 | mbox->ctx_buf = NULL; |
| 14518 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14519 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14520 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14521 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14522 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14523 | if (shdr_status || shdr_add_status || rc) { |
| 14524 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14525 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14526 | "status x%x add_status x%x, mbx status x%x\n", |
| 14527 | shdr_status, shdr_add_status, rc); |
| 14528 | status = -ENXIO; |
| 14529 | } |
| 14530 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14531 | return status; |
| 14532 | } |
| 14533 | |
| 14534 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14535 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14536 | * @phba: HBA structure that indicates port to create a queue on. |
| 14537 | * @eq: The queue structure to use to create the event queue. |
| 14538 | * @imax: The maximum interrupt per second limit. |
| 14539 | * |
| 14540 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14541 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14542 | * |
| 14543 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14544 | * is used to get the entry count and entry size that are necessary to |
| 14545 | * determine the number of pages to allocate and use for this queue. This |
| 14546 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14547 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14548 | * command to finish before continuing. |
| 14549 | * |
| 14550 | * 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] | 14551 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14552 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14553 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14554 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14555 | 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] | 14556 | { |
| 14557 | struct lpfc_mbx_eq_create *eq_create; |
| 14558 | LPFC_MBOXQ_t *mbox; |
| 14559 | int rc, length, status = 0; |
| 14560 | struct lpfc_dmabuf *dmabuf; |
| 14561 | uint32_t shdr_status, shdr_add_status; |
| 14562 | union lpfc_sli4_cfg_shdr *shdr; |
| 14563 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14564 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14565 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14566 | /* sanity check on queue memory */ |
| 14567 | if (!eq) |
| 14568 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14569 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14570 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14571 | |
| 14572 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14573 | if (!mbox) |
| 14574 | return -ENOMEM; |
| 14575 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14576 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14577 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14578 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14579 | length, LPFC_SLI4_MBX_EMBED); |
| 14580 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14581 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14582 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14583 | eq->page_count); |
| 14584 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14585 | LPFC_EQE_SIZE); |
| 14586 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14587 | |
| 14588 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 14589 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 14590 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14591 | LPFC_Q_CREATE_VERSION_2); |
| 14592 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 14593 | phba->sli4_hba.pc_sli4_params.eqav); |
| 14594 | } |
| 14595 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14596 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14597 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14598 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14599 | dmult); |
| 14600 | switch (eq->entry_count) { |
| 14601 | default: |
| 14602 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14603 | "0360 Unsupported EQ count. (%d)\n", |
| 14604 | eq->entry_count); |
| 14605 | if (eq->entry_count < 256) |
| 14606 | return -EINVAL; |
| 14607 | /* otherwise default to smallest count (drop through) */ |
| 14608 | case 256: |
| 14609 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14610 | LPFC_EQ_CNT_256); |
| 14611 | break; |
| 14612 | case 512: |
| 14613 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14614 | LPFC_EQ_CNT_512); |
| 14615 | break; |
| 14616 | case 1024: |
| 14617 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14618 | LPFC_EQ_CNT_1024); |
| 14619 | break; |
| 14620 | case 2048: |
| 14621 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14622 | LPFC_EQ_CNT_2048); |
| 14623 | break; |
| 14624 | case 4096: |
| 14625 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14626 | LPFC_EQ_CNT_4096); |
| 14627 | break; |
| 14628 | } |
| 14629 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14630 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14631 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14632 | putPaddrLow(dmabuf->phys); |
| 14633 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14634 | putPaddrHigh(dmabuf->phys); |
| 14635 | } |
| 14636 | mbox->vport = phba->pport; |
| 14637 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14638 | mbox->ctx_buf = NULL; |
| 14639 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14640 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14641 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14642 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14643 | if (shdr_status || shdr_add_status || rc) { |
| 14644 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14645 | "2500 EQ_CREATE mailbox failed with " |
| 14646 | "status x%x add_status x%x, mbx status x%x\n", |
| 14647 | shdr_status, shdr_add_status, rc); |
| 14648 | status = -ENXIO; |
| 14649 | } |
| 14650 | eq->type = LPFC_EQ; |
| 14651 | eq->subtype = LPFC_NONE; |
| 14652 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14653 | if (eq->queue_id == 0xFFFF) |
| 14654 | status = -ENXIO; |
| 14655 | eq->host_index = 0; |
| 14656 | eq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14657 | eq->entry_repost = LPFC_EQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14658 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14659 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14660 | return status; |
| 14661 | } |
| 14662 | |
| 14663 | /** |
| 14664 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14665 | * @phba: HBA structure that indicates port to create a queue on. |
| 14666 | * @cq: The queue structure to use to create the completion queue. |
| 14667 | * @eq: The event queue to bind this completion queue to. |
| 14668 | * |
| 14669 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14670 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14671 | * |
| 14672 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14673 | * is used to get the entry count and entry size that are necessary to |
| 14674 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14675 | * is used to indicate which event queue to bind this completion queue to. This |
| 14676 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14677 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14678 | * command to finish before continuing. |
| 14679 | * |
| 14680 | * 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] | 14681 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14682 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14683 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14684 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14685 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14686 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14687 | { |
| 14688 | struct lpfc_mbx_cq_create *cq_create; |
| 14689 | struct lpfc_dmabuf *dmabuf; |
| 14690 | LPFC_MBOXQ_t *mbox; |
| 14691 | int rc, length, status = 0; |
| 14692 | uint32_t shdr_status, shdr_add_status; |
| 14693 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14694 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14695 | /* sanity check on queue memory */ |
| 14696 | if (!cq || !eq) |
| 14697 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14698 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14699 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14700 | if (!mbox) |
| 14701 | return -ENOMEM; |
| 14702 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14703 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14704 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14705 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14706 | length, LPFC_SLI4_MBX_EMBED); |
| 14707 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14708 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14709 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14710 | cq->page_count); |
| 14711 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14712 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14713 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14714 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14715 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14716 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 14717 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14718 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14719 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14720 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 14721 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14722 | } else { |
| 14723 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14724 | eq->queue_id); |
| 14725 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14726 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14727 | case 2048: |
| 14728 | case 4096: |
| 14729 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14730 | LPFC_Q_CREATE_VERSION_2) { |
| 14731 | cq_create->u.request.context.lpfc_cq_context_count = |
| 14732 | cq->entry_count; |
| 14733 | bf_set(lpfc_cq_context_count, |
| 14734 | &cq_create->u.request.context, |
| 14735 | LPFC_CQ_CNT_WORD7); |
| 14736 | break; |
| 14737 | } |
| 14738 | /* Fall Thru */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14739 | default: |
| 14740 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14741 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14742 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14743 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14744 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14745 | if (cq->entry_count < 256) { |
| 14746 | status = -EINVAL; |
| 14747 | goto out; |
| 14748 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14749 | /* otherwise default to smallest count (drop through) */ |
| 14750 | case 256: |
| 14751 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14752 | LPFC_CQ_CNT_256); |
| 14753 | break; |
| 14754 | case 512: |
| 14755 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14756 | LPFC_CQ_CNT_512); |
| 14757 | break; |
| 14758 | case 1024: |
| 14759 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14760 | LPFC_CQ_CNT_1024); |
| 14761 | break; |
| 14762 | } |
| 14763 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14764 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14765 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14766 | putPaddrLow(dmabuf->phys); |
| 14767 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14768 | putPaddrHigh(dmabuf->phys); |
| 14769 | } |
| 14770 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14771 | |
| 14772 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14773 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14774 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14775 | if (shdr_status || shdr_add_status || rc) { |
| 14776 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14777 | "2501 CQ_CREATE mailbox failed with " |
| 14778 | "status x%x add_status x%x, mbx status x%x\n", |
| 14779 | shdr_status, shdr_add_status, rc); |
| 14780 | status = -ENXIO; |
| 14781 | goto out; |
| 14782 | } |
| 14783 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 14784 | if (cq->queue_id == 0xFFFF) { |
| 14785 | status = -ENXIO; |
| 14786 | goto out; |
| 14787 | } |
| 14788 | /* link the cq onto the parent eq child list */ |
| 14789 | list_add_tail(&cq->list, &eq->child_list); |
| 14790 | /* Set up completion queue's type and subtype */ |
| 14791 | cq->type = type; |
| 14792 | cq->subtype = subtype; |
| 14793 | 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] | 14794 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14795 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14796 | cq->host_index = 0; |
| 14797 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14798 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14799 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 14800 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 14801 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14802 | out: |
| 14803 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14804 | return status; |
| 14805 | } |
| 14806 | |
| 14807 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14808 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 14809 | * @phba: HBA structure that indicates port to create a queue on. |
| 14810 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14811 | * @hdwq: The hardware queue array with the EQ to bind completion queues to. |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14812 | * |
| 14813 | * This function creates a set of completion queue, s to support MRQ |
| 14814 | * as detailed in @cqp, on a port, |
| 14815 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 14816 | * |
| 14817 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14818 | * is used to get the entry count and entry size that are necessary to |
| 14819 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14820 | * is used to indicate which event queue to bind this completion queue to. This |
| 14821 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 14822 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14823 | * command to finish before continuing. |
| 14824 | * |
| 14825 | * On success this function will return a zero. If unable to allocate enough |
| 14826 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14827 | * fails this function will return -ENXIO. |
| 14828 | **/ |
| 14829 | int |
| 14830 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14831 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 14832 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14833 | { |
| 14834 | struct lpfc_queue *cq; |
| 14835 | struct lpfc_queue *eq; |
| 14836 | struct lpfc_mbx_cq_create_set *cq_set; |
| 14837 | struct lpfc_dmabuf *dmabuf; |
| 14838 | LPFC_MBOXQ_t *mbox; |
| 14839 | int rc, length, alloclen, status = 0; |
| 14840 | int cnt, idx, numcq, page_idx = 0; |
| 14841 | uint32_t shdr_status, shdr_add_status; |
| 14842 | union lpfc_sli4_cfg_shdr *shdr; |
| 14843 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14844 | |
| 14845 | /* sanity check on queue memory */ |
| 14846 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14847 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14848 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14849 | |
| 14850 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14851 | if (!mbox) |
| 14852 | return -ENOMEM; |
| 14853 | |
| 14854 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 14855 | length += ((numcq * cqp[0]->page_count) * |
| 14856 | sizeof(struct dma_address)); |
| 14857 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14858 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 14859 | LPFC_SLI4_MBX_NEMBED); |
| 14860 | if (alloclen < length) { |
| 14861 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14862 | "3098 Allocated DMA memory size (%d) is " |
| 14863 | "less than the requested DMA memory size " |
| 14864 | "(%d)\n", alloclen, length); |
| 14865 | status = -ENOMEM; |
| 14866 | goto out; |
| 14867 | } |
| 14868 | cq_set = mbox->sge_array->addr[0]; |
| 14869 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 14870 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 14871 | |
| 14872 | for (idx = 0; idx < numcq; idx++) { |
| 14873 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14874 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14875 | if (!cq || !eq) { |
| 14876 | status = -ENOMEM; |
| 14877 | goto out; |
| 14878 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14879 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14880 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14881 | |
| 14882 | switch (idx) { |
| 14883 | case 0: |
| 14884 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 14885 | &cq_set->u.request, |
| 14886 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 14887 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 14888 | &cq_set->u.request, cq->page_count); |
| 14889 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 14890 | &cq_set->u.request, 1); |
| 14891 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 14892 | &cq_set->u.request, 1); |
| 14893 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 14894 | &cq_set->u.request, 0); |
| 14895 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 14896 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14897 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 14898 | &cq_set->u.request, |
| 14899 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14900 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14901 | case 2048: |
| 14902 | case 4096: |
| 14903 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14904 | LPFC_Q_CREATE_VERSION_2) { |
| 14905 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14906 | &cq_set->u.request, |
| 14907 | cq->entry_count); |
| 14908 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14909 | &cq_set->u.request, |
| 14910 | LPFC_CQ_CNT_WORD7); |
| 14911 | break; |
| 14912 | } |
| 14913 | /* Fall Thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14914 | default: |
| 14915 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14916 | "3118 Bad CQ count. (%d)\n", |
| 14917 | cq->entry_count); |
| 14918 | if (cq->entry_count < 256) { |
| 14919 | status = -EINVAL; |
| 14920 | goto out; |
| 14921 | } |
| 14922 | /* otherwise default to smallest (drop thru) */ |
| 14923 | case 256: |
| 14924 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14925 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 14926 | break; |
| 14927 | case 512: |
| 14928 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14929 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 14930 | break; |
| 14931 | case 1024: |
| 14932 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14933 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 14934 | break; |
| 14935 | } |
| 14936 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 14937 | &cq_set->u.request, eq->queue_id); |
| 14938 | break; |
| 14939 | case 1: |
| 14940 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 14941 | &cq_set->u.request, eq->queue_id); |
| 14942 | break; |
| 14943 | case 2: |
| 14944 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 14945 | &cq_set->u.request, eq->queue_id); |
| 14946 | break; |
| 14947 | case 3: |
| 14948 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 14949 | &cq_set->u.request, eq->queue_id); |
| 14950 | break; |
| 14951 | case 4: |
| 14952 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 14953 | &cq_set->u.request, eq->queue_id); |
| 14954 | break; |
| 14955 | case 5: |
| 14956 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 14957 | &cq_set->u.request, eq->queue_id); |
| 14958 | break; |
| 14959 | case 6: |
| 14960 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 14961 | &cq_set->u.request, eq->queue_id); |
| 14962 | break; |
| 14963 | case 7: |
| 14964 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 14965 | &cq_set->u.request, eq->queue_id); |
| 14966 | break; |
| 14967 | case 8: |
| 14968 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 14969 | &cq_set->u.request, eq->queue_id); |
| 14970 | break; |
| 14971 | case 9: |
| 14972 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 14973 | &cq_set->u.request, eq->queue_id); |
| 14974 | break; |
| 14975 | case 10: |
| 14976 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 14977 | &cq_set->u.request, eq->queue_id); |
| 14978 | break; |
| 14979 | case 11: |
| 14980 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 14981 | &cq_set->u.request, eq->queue_id); |
| 14982 | break; |
| 14983 | case 12: |
| 14984 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 14985 | &cq_set->u.request, eq->queue_id); |
| 14986 | break; |
| 14987 | case 13: |
| 14988 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 14989 | &cq_set->u.request, eq->queue_id); |
| 14990 | break; |
| 14991 | case 14: |
| 14992 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 14993 | &cq_set->u.request, eq->queue_id); |
| 14994 | break; |
| 14995 | case 15: |
| 14996 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 14997 | &cq_set->u.request, eq->queue_id); |
| 14998 | break; |
| 14999 | } |
| 15000 | |
| 15001 | /* link the cq onto the parent eq child list */ |
| 15002 | list_add_tail(&cq->list, &eq->child_list); |
| 15003 | /* Set up completion queue's type and subtype */ |
| 15004 | cq->type = type; |
| 15005 | cq->subtype = subtype; |
| 15006 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 15007 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15008 | cq->host_index = 0; |
| 15009 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15010 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15011 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15012 | |
| 15013 | rc = 0; |
| 15014 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15015 | memset(dmabuf->virt, 0, hw_page_size); |
| 15016 | cnt = page_idx + dmabuf->buffer_tag; |
| 15017 | cq_set->u.request.page[cnt].addr_lo = |
| 15018 | putPaddrLow(dmabuf->phys); |
| 15019 | cq_set->u.request.page[cnt].addr_hi = |
| 15020 | putPaddrHigh(dmabuf->phys); |
| 15021 | rc++; |
| 15022 | } |
| 15023 | page_idx += rc; |
| 15024 | } |
| 15025 | |
| 15026 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15027 | |
| 15028 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15029 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15030 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15031 | if (shdr_status || shdr_add_status || rc) { |
| 15032 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15033 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15034 | "status x%x add_status x%x, mbx status x%x\n", |
| 15035 | shdr_status, shdr_add_status, rc); |
| 15036 | status = -ENXIO; |
| 15037 | goto out; |
| 15038 | } |
| 15039 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15040 | if (rc == 0xFFFF) { |
| 15041 | status = -ENXIO; |
| 15042 | goto out; |
| 15043 | } |
| 15044 | |
| 15045 | for (idx = 0; idx < numcq; idx++) { |
| 15046 | cq = cqp[idx]; |
| 15047 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 15048 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15049 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15050 | } |
| 15051 | |
| 15052 | out: |
| 15053 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15054 | return status; |
| 15055 | } |
| 15056 | |
| 15057 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15058 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15059 | * @phba: HBA structure that indicates port to create a queue on. |
| 15060 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15061 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15062 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15063 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15064 | * This function provides failback (fb) functionality when the |
| 15065 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15066 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15067 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15068 | * This routine cannot fail as all attributes were previously accessed and |
| 15069 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15070 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15071 | static void |
| 15072 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15073 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15074 | { |
| 15075 | struct lpfc_mbx_mq_create *mq_create; |
| 15076 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15077 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15078 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15079 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15080 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15081 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15082 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15083 | length, LPFC_SLI4_MBX_EMBED); |
| 15084 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15085 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15086 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15087 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15088 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15089 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15090 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15091 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15092 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15093 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15094 | break; |
| 15095 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15096 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15097 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15098 | break; |
| 15099 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15100 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15101 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15102 | break; |
| 15103 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15104 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15105 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15106 | break; |
| 15107 | } |
| 15108 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15109 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15110 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15111 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15112 | putPaddrHigh(dmabuf->phys); |
| 15113 | } |
| 15114 | } |
| 15115 | |
| 15116 | /** |
| 15117 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15118 | * @phba: HBA structure that indicates port to create a queue on. |
| 15119 | * @mq: The queue structure to use to create the mailbox queue. |
| 15120 | * @cq: The completion queue to associate with this cq. |
| 15121 | * @subtype: The queue's subtype. |
| 15122 | * |
| 15123 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15124 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15125 | * |
| 15126 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15127 | * is used to get the entry count and entry size that are necessary to |
| 15128 | * determine the number of pages to allocate and use for this queue. This |
| 15129 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15130 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15131 | * command to finish before continuing. |
| 15132 | * |
| 15133 | * 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] | 15134 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15135 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15136 | **/ |
| 15137 | int32_t |
| 15138 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15139 | struct lpfc_queue *cq, uint32_t subtype) |
| 15140 | { |
| 15141 | struct lpfc_mbx_mq_create *mq_create; |
| 15142 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15143 | struct lpfc_dmabuf *dmabuf; |
| 15144 | LPFC_MBOXQ_t *mbox; |
| 15145 | int rc, length, status = 0; |
| 15146 | uint32_t shdr_status, shdr_add_status; |
| 15147 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15148 | 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] | 15149 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15150 | /* sanity check on queue memory */ |
| 15151 | if (!mq || !cq) |
| 15152 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15153 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15154 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15155 | |
| 15156 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15157 | if (!mbox) |
| 15158 | return -ENOMEM; |
| 15159 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15160 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15161 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15162 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15163 | length, LPFC_SLI4_MBX_EMBED); |
| 15164 | |
| 15165 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15166 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15167 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15168 | &mq_create_ext->u.request, mq->page_count); |
| 15169 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15170 | &mq_create_ext->u.request, 1); |
| 15171 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15172 | &mq_create_ext->u.request, 1); |
| 15173 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15174 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15175 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15176 | &mq_create_ext->u.request, 1); |
| 15177 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15178 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15179 | 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] | 15180 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15181 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15182 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15183 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15184 | cq->queue_id); |
| 15185 | else |
| 15186 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15187 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15188 | switch (mq->entry_count) { |
| 15189 | default: |
| 15190 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15191 | "0362 Unsupported MQ count. (%d)\n", |
| 15192 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15193 | if (mq->entry_count < 16) { |
| 15194 | status = -EINVAL; |
| 15195 | goto out; |
| 15196 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15197 | /* otherwise default to smallest count (drop through) */ |
| 15198 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15199 | bf_set(lpfc_mq_context_ring_size, |
| 15200 | &mq_create_ext->u.request.context, |
| 15201 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15202 | break; |
| 15203 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15204 | bf_set(lpfc_mq_context_ring_size, |
| 15205 | &mq_create_ext->u.request.context, |
| 15206 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15207 | break; |
| 15208 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15209 | bf_set(lpfc_mq_context_ring_size, |
| 15210 | &mq_create_ext->u.request.context, |
| 15211 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15212 | break; |
| 15213 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15214 | bf_set(lpfc_mq_context_ring_size, |
| 15215 | &mq_create_ext->u.request.context, |
| 15216 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15217 | break; |
| 15218 | } |
| 15219 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15220 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15221 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15222 | putPaddrLow(dmabuf->phys); |
| 15223 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15224 | putPaddrHigh(dmabuf->phys); |
| 15225 | } |
| 15226 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15227 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15228 | &mq_create_ext->u.response); |
| 15229 | if (rc != MBX_SUCCESS) { |
| 15230 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15231 | "2795 MQ_CREATE_EXT failed with " |
| 15232 | "status x%x. Failback to MQ_CREATE.\n", |
| 15233 | rc); |
| 15234 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15235 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15236 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15237 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15238 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15239 | &mq_create->u.response); |
| 15240 | } |
| 15241 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15242 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15243 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15244 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15245 | if (shdr_status || shdr_add_status || rc) { |
| 15246 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15247 | "2502 MQ_CREATE mailbox failed with " |
| 15248 | "status x%x add_status x%x, mbx status x%x\n", |
| 15249 | shdr_status, shdr_add_status, rc); |
| 15250 | status = -ENXIO; |
| 15251 | goto out; |
| 15252 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15253 | if (mq->queue_id == 0xFFFF) { |
| 15254 | status = -ENXIO; |
| 15255 | goto out; |
| 15256 | } |
| 15257 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15258 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15259 | mq->subtype = subtype; |
| 15260 | mq->host_index = 0; |
| 15261 | mq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15262 | mq->entry_repost = LPFC_MQ_REPOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15263 | |
| 15264 | /* link the mq onto the parent cq child list */ |
| 15265 | list_add_tail(&mq->list, &cq->child_list); |
| 15266 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15267 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15268 | return status; |
| 15269 | } |
| 15270 | |
| 15271 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15272 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15273 | * @phba: HBA structure that indicates port to create a queue on. |
| 15274 | * @wq: The queue structure to use to create the work queue. |
| 15275 | * @cq: The completion queue to bind this work queue to. |
| 15276 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15277 | * |
| 15278 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15279 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15280 | * |
| 15281 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15282 | * is used to get the entry count and entry size that are necessary to |
| 15283 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15284 | * is used to indicate which completion queue to bind this work queue to. This |
| 15285 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15286 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15287 | * command to finish before continuing. |
| 15288 | * |
| 15289 | * 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] | 15290 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15291 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15292 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15293 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15294 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15295 | struct lpfc_queue *cq, uint32_t subtype) |
| 15296 | { |
| 15297 | struct lpfc_mbx_wq_create *wq_create; |
| 15298 | struct lpfc_dmabuf *dmabuf; |
| 15299 | LPFC_MBOXQ_t *mbox; |
| 15300 | int rc, length, status = 0; |
| 15301 | uint32_t shdr_status, shdr_add_status; |
| 15302 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15303 | 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] | 15304 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15305 | void __iomem *bar_memmap_p; |
| 15306 | uint32_t db_offset; |
| 15307 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15308 | uint8_t dpp_barset; |
| 15309 | uint32_t dpp_offset; |
| 15310 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15311 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15312 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15313 | /* sanity check on queue memory */ |
| 15314 | if (!wq || !cq) |
| 15315 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15316 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15317 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15318 | |
| 15319 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15320 | if (!mbox) |
| 15321 | return -ENOMEM; |
| 15322 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15323 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15324 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15325 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15326 | length, LPFC_SLI4_MBX_EMBED); |
| 15327 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15328 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15329 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15330 | wq->page_count); |
| 15331 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15332 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15333 | |
| 15334 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15335 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15336 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15337 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15338 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15339 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15340 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15341 | else |
| 15342 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15343 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15344 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15345 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15346 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15347 | else |
| 15348 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15349 | |
| 15350 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15351 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15352 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15353 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15354 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15355 | LPFC_Q_CREATE_VERSION_1); |
| 15356 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15357 | switch (wq->entry_size) { |
| 15358 | default: |
| 15359 | case 64: |
| 15360 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15361 | &wq_create->u.request_1, |
| 15362 | LPFC_WQ_WQE_SIZE_64); |
| 15363 | break; |
| 15364 | case 128: |
| 15365 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15366 | &wq_create->u.request_1, |
| 15367 | LPFC_WQ_WQE_SIZE_128); |
| 15368 | break; |
| 15369 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15370 | /* Request DPP by default */ |
| 15371 | bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1); |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15372 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15373 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15374 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15375 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15376 | break; |
| 15377 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15378 | page = wq_create->u.request.page; |
| 15379 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15380 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15381 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15382 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15383 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15384 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15385 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15386 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15387 | |
| 15388 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15389 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15390 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15391 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15392 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15393 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15394 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15395 | if (shdr_status || shdr_add_status || rc) { |
| 15396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15397 | "2503 WQ_CREATE mailbox failed with " |
| 15398 | "status x%x add_status x%x, mbx status x%x\n", |
| 15399 | shdr_status, shdr_add_status, rc); |
| 15400 | status = -ENXIO; |
| 15401 | goto out; |
| 15402 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15403 | |
| 15404 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15405 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15406 | &wq_create->u.response); |
| 15407 | else |
| 15408 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15409 | &wq_create->u.response_1); |
| 15410 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15411 | if (wq->queue_id == 0xFFFF) { |
| 15412 | status = -ENXIO; |
| 15413 | goto out; |
| 15414 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15415 | |
| 15416 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15417 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15418 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15419 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15420 | &wq_create->u.response); |
| 15421 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15422 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15423 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15424 | "3265 WQ[%d] doorbell format " |
| 15425 | "not supported: x%x\n", |
| 15426 | wq->queue_id, wq->db_format); |
| 15427 | status = -EINVAL; |
| 15428 | goto out; |
| 15429 | } |
| 15430 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15431 | &wq_create->u.response); |
| 15432 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15433 | pci_barset); |
| 15434 | if (!bar_memmap_p) { |
| 15435 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15436 | "3263 WQ[%d] failed to memmap " |
| 15437 | "pci barset:x%x\n", |
| 15438 | wq->queue_id, pci_barset); |
| 15439 | status = -ENOMEM; |
| 15440 | goto out; |
| 15441 | } |
| 15442 | db_offset = wq_create->u.response.doorbell_offset; |
| 15443 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15444 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15445 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15446 | "3252 WQ[%d] doorbell offset " |
| 15447 | "not supported: x%x\n", |
| 15448 | wq->queue_id, db_offset); |
| 15449 | status = -EINVAL; |
| 15450 | goto out; |
| 15451 | } |
| 15452 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15453 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15454 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15455 | "format:x%x\n", wq->queue_id, |
| 15456 | pci_barset, db_offset, wq->db_format); |
| 15457 | } else |
| 15458 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15459 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15460 | /* Check if DPP was honored by the firmware */ |
| 15461 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15462 | &wq_create->u.response_1); |
| 15463 | if (wq->dpp_enable) { |
| 15464 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15465 | &wq_create->u.response_1); |
| 15466 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15467 | pci_barset); |
| 15468 | if (!bar_memmap_p) { |
| 15469 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15470 | "3267 WQ[%d] failed to memmap " |
| 15471 | "pci barset:x%x\n", |
| 15472 | wq->queue_id, pci_barset); |
| 15473 | status = -ENOMEM; |
| 15474 | goto out; |
| 15475 | } |
| 15476 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15477 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15478 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15479 | &wq_create->u.response_1); |
| 15480 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15481 | &wq_create->u.response_1); |
| 15482 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15483 | dpp_barset); |
| 15484 | if (!bar_memmap_p) { |
| 15485 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15486 | "3268 WQ[%d] failed to memmap " |
| 15487 | "pci barset:x%x\n", |
| 15488 | wq->queue_id, dpp_barset); |
| 15489 | status = -ENOMEM; |
| 15490 | goto out; |
| 15491 | } |
| 15492 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15493 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15494 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15495 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15496 | "dpp_id:x%x dpp_barset:x%x " |
| 15497 | "dpp_offset:x%x\n", |
| 15498 | wq->queue_id, pci_barset, db_offset, |
| 15499 | wq->dpp_id, dpp_barset, dpp_offset); |
| 15500 | |
| 15501 | /* Enable combined writes for DPP aperture */ |
| 15502 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 15503 | #ifdef CONFIG_X86 |
| 15504 | rc = set_memory_wc(pg_addr, 1); |
| 15505 | if (rc) { |
| 15506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15507 | "3272 Cannot setup Combined " |
| 15508 | "Write on WQ[%d] - disable DPP\n", |
| 15509 | wq->queue_id); |
| 15510 | phba->cfg_enable_dpp = 0; |
| 15511 | } |
| 15512 | #else |
| 15513 | phba->cfg_enable_dpp = 0; |
| 15514 | #endif |
| 15515 | } else |
| 15516 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15517 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15518 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15519 | if (wq->pring == NULL) { |
| 15520 | status = -ENOMEM; |
| 15521 | goto out; |
| 15522 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15523 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15524 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15525 | wq->subtype = subtype; |
| 15526 | wq->host_index = 0; |
| 15527 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 15528 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15529 | |
| 15530 | /* link the wq onto the parent cq child list */ |
| 15531 | list_add_tail(&wq->list, &cq->child_list); |
| 15532 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15533 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15534 | return status; |
| 15535 | } |
| 15536 | |
| 15537 | /** |
| 15538 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15539 | * @phba: HBA structure that indicates port to create a queue on. |
| 15540 | * @hrq: The queue structure to use to create the header receive queue. |
| 15541 | * @drq: The queue structure to use to create the data receive queue. |
| 15542 | * @cq: The completion queue to bind this work queue to. |
| 15543 | * |
| 15544 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15545 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15546 | * to the HBA. |
| 15547 | * |
| 15548 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15549 | * struct is used to get the entry count that is necessary to determine the |
| 15550 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15551 | * completion queue to bind received buffers that are posted to these queues to. |
| 15552 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15553 | * receive queue pair. This function is asynchronous and will wait for the |
| 15554 | * mailbox command to finish before continuing. |
| 15555 | * |
| 15556 | * 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] | 15557 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15558 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15559 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15560 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15561 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15562 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15563 | { |
| 15564 | struct lpfc_mbx_rq_create *rq_create; |
| 15565 | struct lpfc_dmabuf *dmabuf; |
| 15566 | LPFC_MBOXQ_t *mbox; |
| 15567 | int rc, length, status = 0; |
| 15568 | uint32_t shdr_status, shdr_add_status; |
| 15569 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15570 | 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] | 15571 | void __iomem *bar_memmap_p; |
| 15572 | uint32_t db_offset; |
| 15573 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15574 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15575 | /* sanity check on queue memory */ |
| 15576 | if (!hrq || !drq || !cq) |
| 15577 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15578 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15579 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15580 | |
| 15581 | if (hrq->entry_count != drq->entry_count) |
| 15582 | return -EINVAL; |
| 15583 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15584 | if (!mbox) |
| 15585 | return -ENOMEM; |
| 15586 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15587 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15588 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15589 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15590 | length, LPFC_SLI4_MBX_EMBED); |
| 15591 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15592 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15593 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15594 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15595 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15596 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15597 | &rq_create->u.request.context, |
| 15598 | hrq->entry_count); |
| 15599 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15600 | bf_set(lpfc_rq_context_rqe_size, |
| 15601 | &rq_create->u.request.context, |
| 15602 | LPFC_RQE_SIZE_8); |
| 15603 | bf_set(lpfc_rq_context_page_size, |
| 15604 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15605 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15606 | } else { |
| 15607 | switch (hrq->entry_count) { |
| 15608 | default: |
| 15609 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15610 | "2535 Unsupported RQ count. (%d)\n", |
| 15611 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15612 | if (hrq->entry_count < 512) { |
| 15613 | status = -EINVAL; |
| 15614 | goto out; |
| 15615 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15616 | /* otherwise default to smallest count (drop through) */ |
| 15617 | case 512: |
| 15618 | bf_set(lpfc_rq_context_rqe_count, |
| 15619 | &rq_create->u.request.context, |
| 15620 | LPFC_RQ_RING_SIZE_512); |
| 15621 | break; |
| 15622 | case 1024: |
| 15623 | bf_set(lpfc_rq_context_rqe_count, |
| 15624 | &rq_create->u.request.context, |
| 15625 | LPFC_RQ_RING_SIZE_1024); |
| 15626 | break; |
| 15627 | case 2048: |
| 15628 | bf_set(lpfc_rq_context_rqe_count, |
| 15629 | &rq_create->u.request.context, |
| 15630 | LPFC_RQ_RING_SIZE_2048); |
| 15631 | break; |
| 15632 | case 4096: |
| 15633 | bf_set(lpfc_rq_context_rqe_count, |
| 15634 | &rq_create->u.request.context, |
| 15635 | LPFC_RQ_RING_SIZE_4096); |
| 15636 | break; |
| 15637 | } |
| 15638 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15639 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15640 | } |
| 15641 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15642 | cq->queue_id); |
| 15643 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15644 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15645 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15646 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15647 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15648 | putPaddrLow(dmabuf->phys); |
| 15649 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15650 | putPaddrHigh(dmabuf->phys); |
| 15651 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15652 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15653 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15654 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15655 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15656 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15657 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15658 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15659 | if (shdr_status || shdr_add_status || rc) { |
| 15660 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15661 | "2504 RQ_CREATE mailbox failed with " |
| 15662 | "status x%x add_status x%x, mbx status x%x\n", |
| 15663 | shdr_status, shdr_add_status, rc); |
| 15664 | status = -ENXIO; |
| 15665 | goto out; |
| 15666 | } |
| 15667 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15668 | if (hrq->queue_id == 0xFFFF) { |
| 15669 | status = -ENXIO; |
| 15670 | goto out; |
| 15671 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15672 | |
| 15673 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15674 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15675 | &rq_create->u.response); |
| 15676 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15677 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15678 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15679 | "3262 RQ [%d] doorbell format not " |
| 15680 | "supported: x%x\n", hrq->queue_id, |
| 15681 | hrq->db_format); |
| 15682 | status = -EINVAL; |
| 15683 | goto out; |
| 15684 | } |
| 15685 | |
| 15686 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15687 | &rq_create->u.response); |
| 15688 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15689 | if (!bar_memmap_p) { |
| 15690 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15691 | "3269 RQ[%d] failed to memmap pci " |
| 15692 | "barset:x%x\n", hrq->queue_id, |
| 15693 | pci_barset); |
| 15694 | status = -ENOMEM; |
| 15695 | goto out; |
| 15696 | } |
| 15697 | |
| 15698 | db_offset = rq_create->u.response.doorbell_offset; |
| 15699 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15700 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15701 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15702 | "3270 RQ[%d] doorbell offset not " |
| 15703 | "supported: x%x\n", hrq->queue_id, |
| 15704 | db_offset); |
| 15705 | status = -EINVAL; |
| 15706 | goto out; |
| 15707 | } |
| 15708 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15709 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15710 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15711 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15712 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15713 | } else { |
| 15714 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15715 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15716 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15717 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15718 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15719 | hrq->subtype = subtype; |
| 15720 | hrq->host_index = 0; |
| 15721 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15722 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15723 | |
| 15724 | /* now create the data queue */ |
| 15725 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15726 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15727 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15728 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15729 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15730 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15731 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15732 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15733 | if (subtype == LPFC_NVMET) |
| 15734 | rq_create->u.request.context.buffer_size = |
| 15735 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15736 | else |
| 15737 | rq_create->u.request.context.buffer_size = |
| 15738 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15739 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15740 | LPFC_RQE_SIZE_8); |
| 15741 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15742 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15743 | } else { |
| 15744 | switch (drq->entry_count) { |
| 15745 | default: |
| 15746 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15747 | "2536 Unsupported RQ count. (%d)\n", |
| 15748 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15749 | if (drq->entry_count < 512) { |
| 15750 | status = -EINVAL; |
| 15751 | goto out; |
| 15752 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15753 | /* otherwise default to smallest count (drop through) */ |
| 15754 | case 512: |
| 15755 | bf_set(lpfc_rq_context_rqe_count, |
| 15756 | &rq_create->u.request.context, |
| 15757 | LPFC_RQ_RING_SIZE_512); |
| 15758 | break; |
| 15759 | case 1024: |
| 15760 | bf_set(lpfc_rq_context_rqe_count, |
| 15761 | &rq_create->u.request.context, |
| 15762 | LPFC_RQ_RING_SIZE_1024); |
| 15763 | break; |
| 15764 | case 2048: |
| 15765 | bf_set(lpfc_rq_context_rqe_count, |
| 15766 | &rq_create->u.request.context, |
| 15767 | LPFC_RQ_RING_SIZE_2048); |
| 15768 | break; |
| 15769 | case 4096: |
| 15770 | bf_set(lpfc_rq_context_rqe_count, |
| 15771 | &rq_create->u.request.context, |
| 15772 | LPFC_RQ_RING_SIZE_4096); |
| 15773 | break; |
| 15774 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15775 | if (subtype == LPFC_NVMET) |
| 15776 | bf_set(lpfc_rq_context_buf_size, |
| 15777 | &rq_create->u.request.context, |
| 15778 | LPFC_NVMET_DATA_BUF_SIZE); |
| 15779 | else |
| 15780 | bf_set(lpfc_rq_context_buf_size, |
| 15781 | &rq_create->u.request.context, |
| 15782 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15783 | } |
| 15784 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15785 | cq->queue_id); |
| 15786 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15787 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15788 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15789 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15790 | putPaddrLow(dmabuf->phys); |
| 15791 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15792 | putPaddrHigh(dmabuf->phys); |
| 15793 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15794 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15795 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15796 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15797 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15798 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15799 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15800 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15801 | if (shdr_status || shdr_add_status || rc) { |
| 15802 | status = -ENXIO; |
| 15803 | goto out; |
| 15804 | } |
| 15805 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15806 | if (drq->queue_id == 0xFFFF) { |
| 15807 | status = -ENXIO; |
| 15808 | goto out; |
| 15809 | } |
| 15810 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15811 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15812 | drq->subtype = subtype; |
| 15813 | drq->host_index = 0; |
| 15814 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15815 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15816 | |
| 15817 | /* link the header and data RQs onto the parent cq child list */ |
| 15818 | list_add_tail(&hrq->list, &cq->child_list); |
| 15819 | list_add_tail(&drq->list, &cq->child_list); |
| 15820 | |
| 15821 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15822 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15823 | return status; |
| 15824 | } |
| 15825 | |
| 15826 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15827 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 15828 | * @phba: HBA structure that indicates port to create a queue on. |
| 15829 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 15830 | * @drqp: The queue structure array to use to create the data receive queues. |
| 15831 | * @cqp: The completion queue array to bind these receive queues to. |
| 15832 | * |
| 15833 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15834 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15835 | * to the HBA. |
| 15836 | * |
| 15837 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15838 | * struct is used to get the entry count that is necessary to determine the |
| 15839 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15840 | * completion queue to bind received buffers that are posted to these queues to. |
| 15841 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15842 | * receive queue pair. This function is asynchronous and will wait for the |
| 15843 | * mailbox command to finish before continuing. |
| 15844 | * |
| 15845 | * On success this function will return a zero. If unable to allocate enough |
| 15846 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15847 | * fails this function will return -ENXIO. |
| 15848 | **/ |
| 15849 | int |
| 15850 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 15851 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 15852 | uint32_t subtype) |
| 15853 | { |
| 15854 | struct lpfc_queue *hrq, *drq, *cq; |
| 15855 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 15856 | struct lpfc_dmabuf *dmabuf; |
| 15857 | LPFC_MBOXQ_t *mbox; |
| 15858 | int rc, length, alloclen, status = 0; |
| 15859 | int cnt, idx, numrq, page_idx = 0; |
| 15860 | uint32_t shdr_status, shdr_add_status; |
| 15861 | union lpfc_sli4_cfg_shdr *shdr; |
| 15862 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15863 | |
| 15864 | numrq = phba->cfg_nvmet_mrq; |
| 15865 | /* sanity check on array memory */ |
| 15866 | if (!hrqp || !drqp || !cqp || !numrq) |
| 15867 | return -ENODEV; |
| 15868 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15869 | hw_page_size = SLI4_PAGE_SIZE; |
| 15870 | |
| 15871 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15872 | if (!mbox) |
| 15873 | return -ENOMEM; |
| 15874 | |
| 15875 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 15876 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 15877 | sizeof(struct dma_address)); |
| 15878 | |
| 15879 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15880 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 15881 | LPFC_SLI4_MBX_NEMBED); |
| 15882 | if (alloclen < length) { |
| 15883 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15884 | "3099 Allocated DMA memory size (%d) is " |
| 15885 | "less than the requested DMA memory size " |
| 15886 | "(%d)\n", alloclen, length); |
| 15887 | status = -ENOMEM; |
| 15888 | goto out; |
| 15889 | } |
| 15890 | |
| 15891 | |
| 15892 | |
| 15893 | rq_create = mbox->sge_array->addr[0]; |
| 15894 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 15895 | |
| 15896 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 15897 | cnt = 0; |
| 15898 | |
| 15899 | for (idx = 0; idx < numrq; idx++) { |
| 15900 | hrq = hrqp[idx]; |
| 15901 | drq = drqp[idx]; |
| 15902 | cq = cqp[idx]; |
| 15903 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15904 | /* sanity check on queue memory */ |
| 15905 | if (!hrq || !drq || !cq) { |
| 15906 | status = -ENODEV; |
| 15907 | goto out; |
| 15908 | } |
| 15909 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 15910 | if (hrq->entry_count != drq->entry_count) { |
| 15911 | status = -EINVAL; |
| 15912 | goto out; |
| 15913 | } |
| 15914 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15915 | if (idx == 0) { |
| 15916 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 15917 | &rq_create->u.request, |
| 15918 | hrq->page_count); |
| 15919 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 15920 | &rq_create->u.request, (numrq * 2)); |
| 15921 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 15922 | 1); |
| 15923 | bf_set(lpfc_rq_context_base_cq, |
| 15924 | &rq_create->u.request.context, |
| 15925 | cq->queue_id); |
| 15926 | bf_set(lpfc_rq_context_data_size, |
| 15927 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15928 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15929 | bf_set(lpfc_rq_context_hdr_size, |
| 15930 | &rq_create->u.request.context, |
| 15931 | LPFC_HDR_BUF_SIZE); |
| 15932 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15933 | &rq_create->u.request.context, |
| 15934 | hrq->entry_count); |
| 15935 | bf_set(lpfc_rq_context_rqe_size, |
| 15936 | &rq_create->u.request.context, |
| 15937 | LPFC_RQE_SIZE_8); |
| 15938 | bf_set(lpfc_rq_context_page_size, |
| 15939 | &rq_create->u.request.context, |
| 15940 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 15941 | } |
| 15942 | rc = 0; |
| 15943 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 15944 | memset(dmabuf->virt, 0, hw_page_size); |
| 15945 | cnt = page_idx + dmabuf->buffer_tag; |
| 15946 | rq_create->u.request.page[cnt].addr_lo = |
| 15947 | putPaddrLow(dmabuf->phys); |
| 15948 | rq_create->u.request.page[cnt].addr_hi = |
| 15949 | putPaddrHigh(dmabuf->phys); |
| 15950 | rc++; |
| 15951 | } |
| 15952 | page_idx += rc; |
| 15953 | |
| 15954 | rc = 0; |
| 15955 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15956 | memset(dmabuf->virt, 0, hw_page_size); |
| 15957 | cnt = page_idx + dmabuf->buffer_tag; |
| 15958 | rq_create->u.request.page[cnt].addr_lo = |
| 15959 | putPaddrLow(dmabuf->phys); |
| 15960 | rq_create->u.request.page[cnt].addr_hi = |
| 15961 | putPaddrHigh(dmabuf->phys); |
| 15962 | rc++; |
| 15963 | } |
| 15964 | page_idx += rc; |
| 15965 | |
| 15966 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15967 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15968 | hrq->type = LPFC_HRQ; |
| 15969 | hrq->assoc_qid = cq->queue_id; |
| 15970 | hrq->subtype = subtype; |
| 15971 | hrq->host_index = 0; |
| 15972 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15973 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15974 | |
| 15975 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 15976 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15977 | drq->type = LPFC_DRQ; |
| 15978 | drq->assoc_qid = cq->queue_id; |
| 15979 | drq->subtype = subtype; |
| 15980 | drq->host_index = 0; |
| 15981 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15982 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15983 | |
| 15984 | list_add_tail(&hrq->list, &cq->child_list); |
| 15985 | list_add_tail(&drq->list, &cq->child_list); |
| 15986 | } |
| 15987 | |
| 15988 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15989 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15990 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15991 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15992 | if (shdr_status || shdr_add_status || rc) { |
| 15993 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15994 | "3120 RQ_CREATE mailbox failed with " |
| 15995 | "status x%x add_status x%x, mbx status x%x\n", |
| 15996 | shdr_status, shdr_add_status, rc); |
| 15997 | status = -ENXIO; |
| 15998 | goto out; |
| 15999 | } |
| 16000 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16001 | if (rc == 0xFFFF) { |
| 16002 | status = -ENXIO; |
| 16003 | goto out; |
| 16004 | } |
| 16005 | |
| 16006 | /* Initialize all RQs with associated queue id */ |
| 16007 | for (idx = 0; idx < numrq; idx++) { |
| 16008 | hrq = hrqp[idx]; |
| 16009 | hrq->queue_id = rc + (2 * idx); |
| 16010 | drq = drqp[idx]; |
| 16011 | drq->queue_id = rc + (2 * idx) + 1; |
| 16012 | } |
| 16013 | |
| 16014 | out: |
| 16015 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16016 | return status; |
| 16017 | } |
| 16018 | |
| 16019 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16020 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 16021 | * @eq: The queue structure associated with the queue to destroy. |
| 16022 | * |
| 16023 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16024 | * command, specific to the type of queue, to the HBA. |
| 16025 | * |
| 16026 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16027 | * |
| 16028 | * 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] | 16029 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16030 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16031 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16032 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16033 | { |
| 16034 | LPFC_MBOXQ_t *mbox; |
| 16035 | int rc, length, status = 0; |
| 16036 | uint32_t shdr_status, shdr_add_status; |
| 16037 | union lpfc_sli4_cfg_shdr *shdr; |
| 16038 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16039 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16040 | if (!eq) |
| 16041 | return -ENODEV; |
| 16042 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16043 | if (!mbox) |
| 16044 | return -ENOMEM; |
| 16045 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16046 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16047 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16048 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16049 | length, LPFC_SLI4_MBX_EMBED); |
| 16050 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16051 | eq->queue_id); |
| 16052 | mbox->vport = eq->phba->pport; |
| 16053 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16054 | |
| 16055 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16056 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16057 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16058 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16059 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16060 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16061 | if (shdr_status || shdr_add_status || rc) { |
| 16062 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16063 | "2505 EQ_DESTROY mailbox failed with " |
| 16064 | "status x%x add_status x%x, mbx status x%x\n", |
| 16065 | shdr_status, shdr_add_status, rc); |
| 16066 | status = -ENXIO; |
| 16067 | } |
| 16068 | |
| 16069 | /* Remove eq from any list */ |
| 16070 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16071 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16072 | return status; |
| 16073 | } |
| 16074 | |
| 16075 | /** |
| 16076 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 16077 | * @cq: The queue structure associated with the queue to destroy. |
| 16078 | * |
| 16079 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16080 | * command, specific to the type of queue, to the HBA. |
| 16081 | * |
| 16082 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16083 | * |
| 16084 | * 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] | 16085 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16086 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16087 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16088 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16089 | { |
| 16090 | LPFC_MBOXQ_t *mbox; |
| 16091 | int rc, length, status = 0; |
| 16092 | uint32_t shdr_status, shdr_add_status; |
| 16093 | union lpfc_sli4_cfg_shdr *shdr; |
| 16094 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16095 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16096 | if (!cq) |
| 16097 | return -ENODEV; |
| 16098 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16099 | if (!mbox) |
| 16100 | return -ENOMEM; |
| 16101 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16102 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16103 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16104 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16105 | length, LPFC_SLI4_MBX_EMBED); |
| 16106 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16107 | cq->queue_id); |
| 16108 | mbox->vport = cq->phba->pport; |
| 16109 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16110 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16111 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16112 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16113 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16114 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16115 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16116 | if (shdr_status || shdr_add_status || rc) { |
| 16117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16118 | "2506 CQ_DESTROY mailbox failed with " |
| 16119 | "status x%x add_status x%x, mbx status x%x\n", |
| 16120 | shdr_status, shdr_add_status, rc); |
| 16121 | status = -ENXIO; |
| 16122 | } |
| 16123 | /* Remove cq from any list */ |
| 16124 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16125 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16126 | return status; |
| 16127 | } |
| 16128 | |
| 16129 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16130 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 16131 | * @qm: The queue structure associated with the queue to destroy. |
| 16132 | * |
| 16133 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16134 | * command, specific to the type of queue, to the HBA. |
| 16135 | * |
| 16136 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16137 | * |
| 16138 | * 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] | 16139 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16140 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16141 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16142 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16143 | { |
| 16144 | LPFC_MBOXQ_t *mbox; |
| 16145 | int rc, length, status = 0; |
| 16146 | uint32_t shdr_status, shdr_add_status; |
| 16147 | union lpfc_sli4_cfg_shdr *shdr; |
| 16148 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16149 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16150 | if (!mq) |
| 16151 | return -ENODEV; |
| 16152 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16153 | if (!mbox) |
| 16154 | return -ENOMEM; |
| 16155 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16156 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16157 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16158 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16159 | length, LPFC_SLI4_MBX_EMBED); |
| 16160 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16161 | mq->queue_id); |
| 16162 | mbox->vport = mq->phba->pport; |
| 16163 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16164 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16165 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16166 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16167 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16168 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16169 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16170 | if (shdr_status || shdr_add_status || rc) { |
| 16171 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16172 | "2507 MQ_DESTROY mailbox failed with " |
| 16173 | "status x%x add_status x%x, mbx status x%x\n", |
| 16174 | shdr_status, shdr_add_status, rc); |
| 16175 | status = -ENXIO; |
| 16176 | } |
| 16177 | /* Remove mq from any list */ |
| 16178 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16179 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16180 | return status; |
| 16181 | } |
| 16182 | |
| 16183 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16184 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16185 | * @wq: The queue structure associated with the queue to destroy. |
| 16186 | * |
| 16187 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16188 | * command, specific to the type of queue, to the HBA. |
| 16189 | * |
| 16190 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16191 | * |
| 16192 | * 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] | 16193 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16194 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16195 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16196 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16197 | { |
| 16198 | LPFC_MBOXQ_t *mbox; |
| 16199 | int rc, length, status = 0; |
| 16200 | uint32_t shdr_status, shdr_add_status; |
| 16201 | union lpfc_sli4_cfg_shdr *shdr; |
| 16202 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16203 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16204 | if (!wq) |
| 16205 | return -ENODEV; |
| 16206 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16207 | if (!mbox) |
| 16208 | return -ENOMEM; |
| 16209 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16210 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16211 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16212 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16213 | length, LPFC_SLI4_MBX_EMBED); |
| 16214 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16215 | wq->queue_id); |
| 16216 | mbox->vport = wq->phba->pport; |
| 16217 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16218 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16219 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16220 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16221 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16222 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16223 | if (shdr_status || shdr_add_status || rc) { |
| 16224 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16225 | "2508 WQ_DESTROY mailbox failed with " |
| 16226 | "status x%x add_status x%x, mbx status x%x\n", |
| 16227 | shdr_status, shdr_add_status, rc); |
| 16228 | status = -ENXIO; |
| 16229 | } |
| 16230 | /* Remove wq from any list */ |
| 16231 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16232 | kfree(wq->pring); |
| 16233 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16234 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16235 | return status; |
| 16236 | } |
| 16237 | |
| 16238 | /** |
| 16239 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16240 | * @rq: The queue structure associated with the queue to destroy. |
| 16241 | * |
| 16242 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16243 | * command, specific to the type of queue, to the HBA. |
| 16244 | * |
| 16245 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16246 | * |
| 16247 | * 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] | 16248 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16249 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16250 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16251 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16252 | struct lpfc_queue *drq) |
| 16253 | { |
| 16254 | LPFC_MBOXQ_t *mbox; |
| 16255 | int rc, length, status = 0; |
| 16256 | uint32_t shdr_status, shdr_add_status; |
| 16257 | union lpfc_sli4_cfg_shdr *shdr; |
| 16258 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16259 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16260 | if (!hrq || !drq) |
| 16261 | return -ENODEV; |
| 16262 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16263 | if (!mbox) |
| 16264 | return -ENOMEM; |
| 16265 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16266 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16267 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16268 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16269 | length, LPFC_SLI4_MBX_EMBED); |
| 16270 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16271 | hrq->queue_id); |
| 16272 | mbox->vport = hrq->phba->pport; |
| 16273 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16274 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16275 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16276 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16277 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16278 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16279 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16280 | if (shdr_status || shdr_add_status || rc) { |
| 16281 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16282 | "2509 RQ_DESTROY mailbox failed with " |
| 16283 | "status x%x add_status x%x, mbx status x%x\n", |
| 16284 | shdr_status, shdr_add_status, rc); |
| 16285 | if (rc != MBX_TIMEOUT) |
| 16286 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16287 | return -ENXIO; |
| 16288 | } |
| 16289 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16290 | drq->queue_id); |
| 16291 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16292 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16293 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16294 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16295 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16296 | if (shdr_status || shdr_add_status || rc) { |
| 16297 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16298 | "2510 RQ_DESTROY mailbox failed with " |
| 16299 | "status x%x add_status x%x, mbx status x%x\n", |
| 16300 | shdr_status, shdr_add_status, rc); |
| 16301 | status = -ENXIO; |
| 16302 | } |
| 16303 | list_del_init(&hrq->list); |
| 16304 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16305 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16306 | return status; |
| 16307 | } |
| 16308 | |
| 16309 | /** |
| 16310 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16311 | * @phba: The virtual port for which this call being executed. |
| 16312 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16313 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16314 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16315 | * |
| 16316 | * This routine will post the sgl pages for the IO that has the xritag |
| 16317 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16318 | * creation and persists for as long as the driver is loaded. |
| 16319 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16320 | * pdma_phys_addr1 should be 0. |
| 16321 | * If the caller needs to map more than 256 scatter gather segment then |
| 16322 | * pdma_phys_addr1 should be a valid physical address. |
| 16323 | * physical address for SGLs must be 64 byte aligned. |
| 16324 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16325 | * the second sgl can have between 1 and 256 entries. |
| 16326 | * |
| 16327 | * Return codes: |
| 16328 | * 0 - Success |
| 16329 | * -ENXIO, -ENOMEM - Failure |
| 16330 | **/ |
| 16331 | int |
| 16332 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16333 | dma_addr_t pdma_phys_addr0, |
| 16334 | dma_addr_t pdma_phys_addr1, |
| 16335 | uint16_t xritag) |
| 16336 | { |
| 16337 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16338 | LPFC_MBOXQ_t *mbox; |
| 16339 | int rc; |
| 16340 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16341 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16342 | union lpfc_sli4_cfg_shdr *shdr; |
| 16343 | |
| 16344 | if (xritag == NO_XRI) { |
| 16345 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16346 | "0364 Invalid param:\n"); |
| 16347 | return -EINVAL; |
| 16348 | } |
| 16349 | |
| 16350 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16351 | if (!mbox) |
| 16352 | return -ENOMEM; |
| 16353 | |
| 16354 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16355 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16356 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16357 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16358 | |
| 16359 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16360 | &mbox->u.mqe.un.post_sgl_pages; |
| 16361 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16362 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16363 | |
| 16364 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16365 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16366 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16367 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16368 | |
| 16369 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16370 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16371 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16372 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16373 | if (!phba->sli4_hba.intr_enable) |
| 16374 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16375 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16376 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16377 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16378 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16379 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16380 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16381 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16382 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16383 | if (rc != MBX_TIMEOUT) |
| 16384 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16385 | if (shdr_status || shdr_add_status || rc) { |
| 16386 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16387 | "2511 POST_SGL mailbox failed with " |
| 16388 | "status x%x add_status x%x, mbx status x%x\n", |
| 16389 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16390 | } |
| 16391 | return 0; |
| 16392 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16393 | |
| 16394 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16395 | * 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] | 16396 | * @phba: pointer to lpfc hba data structure. |
| 16397 | * |
| 16398 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16399 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16400 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16401 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16402 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16403 | * Returns |
| 16404 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16405 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16406 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16407 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16408 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16409 | { |
| 16410 | unsigned long xri; |
| 16411 | |
| 16412 | /* |
| 16413 | * Fetch the next logical xri. Because this index is logical, |
| 16414 | * the driver starts at 0 each time. |
| 16415 | */ |
| 16416 | spin_lock_irq(&phba->hbalock); |
| 16417 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16418 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16419 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16420 | spin_unlock_irq(&phba->hbalock); |
| 16421 | return NO_XRI; |
| 16422 | } else { |
| 16423 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16424 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16425 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16426 | spin_unlock_irq(&phba->hbalock); |
| 16427 | return xri; |
| 16428 | } |
| 16429 | |
| 16430 | /** |
| 16431 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16432 | * @phba: pointer to lpfc hba data structure. |
| 16433 | * |
| 16434 | * This routine is invoked to release an xri to the pool of |
| 16435 | * available rpis maintained by the driver. |
| 16436 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16437 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16438 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16439 | { |
| 16440 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16441 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16442 | } |
| 16443 | } |
| 16444 | |
| 16445 | /** |
| 16446 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16447 | * @phba: pointer to lpfc hba data structure. |
| 16448 | * |
| 16449 | * This routine is invoked to release an xri to the pool of |
| 16450 | * available rpis maintained by the driver. |
| 16451 | **/ |
| 16452 | void |
| 16453 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16454 | { |
| 16455 | spin_lock_irq(&phba->hbalock); |
| 16456 | __lpfc_sli4_free_xri(phba, xri); |
| 16457 | spin_unlock_irq(&phba->hbalock); |
| 16458 | } |
| 16459 | |
| 16460 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16461 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16462 | * @phba: Pointer to HBA context object. |
| 16463 | * |
| 16464 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16465 | * it will return 0xffff. |
| 16466 | * The function returns the allocated xritag if successful, else returns zero. |
| 16467 | * Zero is not a valid xritag. |
| 16468 | * The caller is not required to hold any lock. |
| 16469 | **/ |
| 16470 | uint16_t |
| 16471 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16472 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16473 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16474 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16475 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16476 | if (xri_index == NO_XRI) |
| 16477 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16478 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16479 | " Max XRI is %d, Used XRI is %d\n", |
| 16480 | xri_index, |
| 16481 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16482 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16483 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16484 | } |
| 16485 | |
| 16486 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16487 | * 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] | 16488 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16489 | * @post_sgl_list: pointer to els sgl entry list. |
| 16490 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16491 | * |
| 16492 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16493 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16494 | * is only called when the driver is loading and after all IO has been |
| 16495 | * stopped. |
| 16496 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16497 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16498 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16499 | struct list_head *post_sgl_list, |
| 16500 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16501 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16502 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16503 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16504 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16505 | void *viraddr; |
| 16506 | LPFC_MBOXQ_t *mbox; |
| 16507 | uint32_t reqlen, alloclen, pg_pairs; |
| 16508 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16509 | uint16_t xritag_start = 0; |
| 16510 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16511 | uint32_t shdr_status, shdr_add_status; |
| 16512 | union lpfc_sli4_cfg_shdr *shdr; |
| 16513 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16514 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16515 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16516 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16518 | "2559 Block sgl registration required DMA " |
| 16519 | "size (%d) great than a page\n", reqlen); |
| 16520 | return -ENOMEM; |
| 16521 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16522 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16523 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16524 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16525 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16526 | |
| 16527 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16528 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16529 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16530 | LPFC_SLI4_MBX_NEMBED); |
| 16531 | |
| 16532 | if (alloclen < reqlen) { |
| 16533 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16534 | "0285 Allocated DMA memory size (%d) is " |
| 16535 | "less than the requested DMA memory " |
| 16536 | "size (%d)\n", alloclen, reqlen); |
| 16537 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16538 | return -ENOMEM; |
| 16539 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16540 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16541 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16542 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16543 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16544 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16545 | pg_pairs = 0; |
| 16546 | 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] | 16547 | /* Set up the sge entry */ |
| 16548 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16549 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16550 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16551 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16552 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16553 | cpu_to_le32(putPaddrLow(0)); |
| 16554 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16555 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16556 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16557 | /* Keep the first xritag on the list */ |
| 16558 | if (pg_pairs == 0) |
| 16559 | xritag_start = sglq_entry->sli4_xritag; |
| 16560 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16561 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16562 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16563 | |
| 16564 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16565 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16566 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16567 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16568 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16569 | if (!phba->sli4_hba.intr_enable) |
| 16570 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16571 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16572 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16573 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16574 | } |
| 16575 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16576 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16577 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16578 | if (rc != MBX_TIMEOUT) |
| 16579 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16580 | if (shdr_status || shdr_add_status || rc) { |
| 16581 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16582 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16583 | "status x%x add_status x%x mbx status x%x\n", |
| 16584 | shdr_status, shdr_add_status, rc); |
| 16585 | rc = -ENXIO; |
| 16586 | } |
| 16587 | return rc; |
| 16588 | } |
| 16589 | |
| 16590 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16591 | * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16592 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16593 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16594 | * @count: number of scsi buffers on the list. |
| 16595 | * |
| 16596 | * This routine is invoked to post a block of @count scsi sgl pages from a |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16597 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16598 | * No Lock is held. |
| 16599 | * |
| 16600 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16601 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16602 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 16603 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16604 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16605 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16606 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16607 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16608 | void *viraddr; |
| 16609 | LPFC_MBOXQ_t *mbox; |
| 16610 | uint32_t reqlen, alloclen, pg_pairs; |
| 16611 | uint32_t mbox_tmo; |
| 16612 | uint16_t xritag_start = 0; |
| 16613 | int rc = 0; |
| 16614 | uint32_t shdr_status, shdr_add_status; |
| 16615 | dma_addr_t pdma_phys_bpl1; |
| 16616 | union lpfc_sli4_cfg_shdr *shdr; |
| 16617 | |
| 16618 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16619 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16620 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16621 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16622 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16623 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16624 | "size (%d) great than a page\n", reqlen); |
| 16625 | return -ENOMEM; |
| 16626 | } |
| 16627 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16628 | if (!mbox) { |
| 16629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16630 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16631 | return -ENOMEM; |
| 16632 | } |
| 16633 | |
| 16634 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16635 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16636 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16637 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16638 | |
| 16639 | if (alloclen < reqlen) { |
| 16640 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16641 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16642 | "less than the requested DMA memory " |
| 16643 | "size (%d)\n", alloclen, reqlen); |
| 16644 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16645 | return -ENOMEM; |
| 16646 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16647 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16648 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16649 | viraddr = mbox->sge_array->addr[0]; |
| 16650 | |
| 16651 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16652 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16653 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16654 | |
| 16655 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16656 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16657 | /* Set up the sge entry */ |
| 16658 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16659 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16660 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16661 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16662 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16663 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 16664 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16665 | else |
| 16666 | pdma_phys_bpl1 = 0; |
| 16667 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16668 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16669 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16670 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16671 | /* Keep the first xritag on the list */ |
| 16672 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16673 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16674 | sgl_pg_pairs++; |
| 16675 | pg_pairs++; |
| 16676 | } |
| 16677 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16678 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16679 | /* Perform endian conversion if necessary */ |
| 16680 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16681 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16682 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16683 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16684 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16685 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16686 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16687 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16688 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16689 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16690 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16691 | if (rc != MBX_TIMEOUT) |
| 16692 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16693 | if (shdr_status || shdr_add_status || rc) { |
| 16694 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16695 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16696 | "status x%x add_status x%x mbx status x%x\n", |
| 16697 | shdr_status, shdr_add_status, rc); |
| 16698 | rc = -ENXIO; |
| 16699 | } |
| 16700 | return rc; |
| 16701 | } |
| 16702 | |
| 16703 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16704 | * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16705 | * @phba: pointer to lpfc hba data structure. |
| 16706 | * @post_nblist: pointer to the nvme buffer list. |
| 16707 | * |
| 16708 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 16709 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 16710 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 16711 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 16712 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 16713 | * must be local list, thus no lock is needed when manipulate the list. |
| 16714 | * |
| 16715 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 16716 | **/ |
| 16717 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16718 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 16719 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16720 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16721 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16722 | int status, sgl_size; |
| 16723 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 16724 | dma_addr_t pdma_phys_sgl1; |
| 16725 | int last_xritag = NO_XRI; |
| 16726 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16727 | LIST_HEAD(prep_nblist); |
| 16728 | LIST_HEAD(blck_nblist); |
| 16729 | LIST_HEAD(nvme_nblist); |
| 16730 | |
| 16731 | /* sanity check */ |
| 16732 | if (sb_count <= 0) |
| 16733 | return -EINVAL; |
| 16734 | |
| 16735 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 16736 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 16737 | list_del_init(&lpfc_ncmd->list); |
| 16738 | block_cnt++; |
| 16739 | if ((last_xritag != NO_XRI) && |
| 16740 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 16741 | /* a hole in xri block, form a sgl posting block */ |
| 16742 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16743 | post_cnt = block_cnt - 1; |
| 16744 | /* prepare list for next posting block */ |
| 16745 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 16746 | block_cnt = 1; |
| 16747 | } else { |
| 16748 | /* prepare list for next posting block */ |
| 16749 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 16750 | /* enough sgls for non-embed sgl mbox command */ |
| 16751 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 16752 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16753 | post_cnt = block_cnt; |
| 16754 | block_cnt = 0; |
| 16755 | } |
| 16756 | } |
| 16757 | num_posting++; |
| 16758 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 16759 | |
| 16760 | /* end of repost sgl list condition for NVME buffers */ |
| 16761 | if (num_posting == sb_count) { |
| 16762 | if (post_cnt == 0) { |
| 16763 | /* last sgl posting block */ |
| 16764 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16765 | post_cnt = block_cnt; |
| 16766 | } else if (block_cnt == 1) { |
| 16767 | /* last single sgl with non-contiguous xri */ |
| 16768 | if (sgl_size > SGL_PAGE_SIZE) |
| 16769 | pdma_phys_sgl1 = |
| 16770 | lpfc_ncmd->dma_phys_sgl + |
| 16771 | SGL_PAGE_SIZE; |
| 16772 | else |
| 16773 | pdma_phys_sgl1 = 0; |
| 16774 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 16775 | status = lpfc_sli4_post_sgl( |
| 16776 | phba, lpfc_ncmd->dma_phys_sgl, |
| 16777 | pdma_phys_sgl1, cur_xritag); |
| 16778 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16779 | /* Post error. Buffer unavailable. */ |
| 16780 | lpfc_ncmd->flags |= |
| 16781 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16782 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16783 | /* Post success. Bffer available. */ |
| 16784 | lpfc_ncmd->flags &= |
| 16785 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16786 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 16787 | num_posted++; |
| 16788 | } |
| 16789 | /* success, put on NVME buffer sgl list */ |
| 16790 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 16791 | } |
| 16792 | } |
| 16793 | |
| 16794 | /* continue until a nembed page worth of sgls */ |
| 16795 | if (post_cnt == 0) |
| 16796 | continue; |
| 16797 | |
| 16798 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16799 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 16800 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16801 | |
| 16802 | /* don't reset xirtag due to hole in xri block */ |
| 16803 | if (block_cnt == 0) |
| 16804 | last_xritag = NO_XRI; |
| 16805 | |
| 16806 | /* reset NVME buffer post count for next round of posting */ |
| 16807 | post_cnt = 0; |
| 16808 | |
| 16809 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 16810 | while (!list_empty(&blck_nblist)) { |
| 16811 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16812 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16813 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16814 | /* Post error. Mark buffer unavailable. */ |
| 16815 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16816 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16817 | /* Post success, Mark buffer available. */ |
| 16818 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16819 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 16820 | num_posted++; |
| 16821 | } |
| 16822 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 16823 | } |
| 16824 | } |
| 16825 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16826 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 16827 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16828 | return num_posted; |
| 16829 | } |
| 16830 | |
| 16831 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16832 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16833 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16834 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16835 | * |
| 16836 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16837 | * valid type of frame that the LPFC driver will handle. This function will |
| 16838 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16839 | * frame does not pass the check. |
| 16840 | **/ |
| 16841 | static int |
| 16842 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16843 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16844 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16845 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16846 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16847 | |
| 16848 | switch (fc_hdr->fh_r_ctl) { |
| 16849 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16850 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16851 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16852 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16853 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16854 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16855 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16856 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16857 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16858 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16859 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16860 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16861 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16862 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16863 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16864 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16865 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16866 | case FC_RCTL_BA_PRMT: |
| 16867 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16868 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 16869 | case FC_RCTL_P_RJT: /* port reject */ |
| 16870 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 16871 | case FC_RCTL_P_BSY: /* port busy */ |
| 16872 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 16873 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 16874 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16875 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16876 | case FC_RCTL_END: /* end */ |
| 16877 | break; |
| 16878 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 16879 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16880 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 16881 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 16882 | default: |
| 16883 | goto drop; |
| 16884 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16885 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16886 | switch (fc_hdr->fh_type) { |
| 16887 | case FC_TYPE_BLS: |
| 16888 | case FC_TYPE_ELS: |
| 16889 | case FC_TYPE_FCP: |
| 16890 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16891 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16892 | break; |
| 16893 | case FC_TYPE_IP: |
| 16894 | case FC_TYPE_ILS: |
| 16895 | default: |
| 16896 | goto drop; |
| 16897 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16898 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16899 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16900 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 16901 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16902 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 16903 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 16904 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 16905 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 16906 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16907 | return 0; |
| 16908 | drop: |
| 16909 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16910 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 16911 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16912 | return 1; |
| 16913 | } |
| 16914 | |
| 16915 | /** |
| 16916 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 16917 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16918 | * |
| 16919 | * This function processes the FC header to retrieve the VFI from the VF |
| 16920 | * header, if one exists. This function will return the VFI if one exists |
| 16921 | * or 0 if no VSAN Header exists. |
| 16922 | **/ |
| 16923 | static uint32_t |
| 16924 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 16925 | { |
| 16926 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16927 | |
| 16928 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 16929 | return 0; |
| 16930 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 16931 | } |
| 16932 | |
| 16933 | /** |
| 16934 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 16935 | * @phba: Pointer to the HBA structure to search for the vport on |
| 16936 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16937 | * @fcfi: The FC Fabric ID that the frame came from |
| 16938 | * |
| 16939 | * This function searches the @phba for a vport that matches the content of the |
| 16940 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 16941 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 16942 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 16943 | * vport. |
| 16944 | **/ |
| 16945 | static struct lpfc_vport * |
| 16946 | 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] | 16947 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16948 | { |
| 16949 | struct lpfc_vport **vports; |
| 16950 | struct lpfc_vport *vport = NULL; |
| 16951 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16952 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 16953 | if (did == Fabric_DID) |
| 16954 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16955 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 16956 | !(phba->link_state == LPFC_HBA_READY)) |
| 16957 | return phba->pport; |
| 16958 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16959 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16960 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16961 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 16962 | if (phba->fcf.fcfi == fcfi && |
| 16963 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 16964 | vports[i]->fc_myDID == did) { |
| 16965 | vport = vports[i]; |
| 16966 | break; |
| 16967 | } |
| 16968 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16969 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16970 | lpfc_destroy_vport_work_array(phba, vports); |
| 16971 | return vport; |
| 16972 | } |
| 16973 | |
| 16974 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16975 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 16976 | * @vport: The vport to work on. |
| 16977 | * |
| 16978 | * This function updates the receive sequence time stamp for this vport. The |
| 16979 | * receive sequence time stamp indicates the time that the last frame of the |
| 16980 | * the sequence that has been idle for the longest amount of time was received. |
| 16981 | * the driver uses this time stamp to indicate if any received sequences have |
| 16982 | * timed out. |
| 16983 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16984 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16985 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 16986 | { |
| 16987 | struct lpfc_dmabuf *h_buf; |
| 16988 | struct hbq_dmabuf *dmabuf = NULL; |
| 16989 | |
| 16990 | /* get the oldest sequence on the rcv list */ |
| 16991 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 16992 | struct lpfc_dmabuf, list); |
| 16993 | if (!h_buf) |
| 16994 | return; |
| 16995 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16996 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 16997 | } |
| 16998 | |
| 16999 | /** |
| 17000 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17001 | * @vport: The vport that the received sequences were sent to. |
| 17002 | * |
| 17003 | * This function cleans up all outstanding received sequences. This is called |
| 17004 | * by the driver when a link event or user action invalidates all the received |
| 17005 | * sequences. |
| 17006 | **/ |
| 17007 | void |
| 17008 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17009 | { |
| 17010 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17011 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17012 | struct hbq_dmabuf *dmabuf = NULL; |
| 17013 | |
| 17014 | /* start with the oldest sequence on the rcv list */ |
| 17015 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17016 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17017 | list_del_init(&dmabuf->hbuf.list); |
| 17018 | list_for_each_entry_safe(d_buf, dnext, |
| 17019 | &dmabuf->dbuf.list, list) { |
| 17020 | list_del_init(&d_buf->list); |
| 17021 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17022 | } |
| 17023 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17024 | } |
| 17025 | } |
| 17026 | |
| 17027 | /** |
| 17028 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17029 | * @vport: The vport that the received sequences were sent to. |
| 17030 | * |
| 17031 | * This function determines whether any received sequences have timed out by |
| 17032 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17033 | * indicates that there is at least one timed out sequence this routine will |
| 17034 | * go through the received sequences one at a time from most inactive to most |
| 17035 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17036 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17037 | * without sending an abort. |
| 17038 | **/ |
| 17039 | void |
| 17040 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17041 | { |
| 17042 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17043 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17044 | struct hbq_dmabuf *dmabuf = NULL; |
| 17045 | unsigned long timeout; |
| 17046 | int abort_count = 0; |
| 17047 | |
| 17048 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17049 | vport->rcv_buffer_time_stamp); |
| 17050 | if (list_empty(&vport->rcv_buffer_list) || |
| 17051 | time_before(jiffies, timeout)) |
| 17052 | return; |
| 17053 | /* start with the oldest sequence on the rcv list */ |
| 17054 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17055 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17056 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17057 | dmabuf->time_stamp); |
| 17058 | if (time_before(jiffies, timeout)) |
| 17059 | break; |
| 17060 | abort_count++; |
| 17061 | list_del_init(&dmabuf->hbuf.list); |
| 17062 | list_for_each_entry_safe(d_buf, dnext, |
| 17063 | &dmabuf->dbuf.list, list) { |
| 17064 | list_del_init(&d_buf->list); |
| 17065 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17066 | } |
| 17067 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17068 | } |
| 17069 | if (abort_count) |
| 17070 | lpfc_update_rcv_time_stamp(vport); |
| 17071 | } |
| 17072 | |
| 17073 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17074 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 17075 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17076 | * |
| 17077 | * This function searches through the existing incomplete sequences that have |
| 17078 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17079 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17080 | * make up that sequence. If no sequence is found that matches this frame then |
| 17081 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17082 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17083 | * the frame was linked to. |
| 17084 | **/ |
| 17085 | static struct hbq_dmabuf * |
| 17086 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17087 | { |
| 17088 | struct fc_frame_header *new_hdr; |
| 17089 | struct fc_frame_header *temp_hdr; |
| 17090 | struct lpfc_dmabuf *d_buf; |
| 17091 | struct lpfc_dmabuf *h_buf; |
| 17092 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17093 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17094 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17095 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17096 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17097 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17098 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17099 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17100 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17101 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17102 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17103 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17104 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17105 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17106 | continue; |
| 17107 | /* found a pending sequence that matches this frame */ |
| 17108 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17109 | break; |
| 17110 | } |
| 17111 | if (!seq_dmabuf) { |
| 17112 | /* |
| 17113 | * This indicates first frame received for this sequence. |
| 17114 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17115 | */ |
| 17116 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17117 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17118 | return dmabuf; |
| 17119 | } |
| 17120 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17121 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17122 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17123 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17124 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17125 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17126 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17127 | return dmabuf; |
| 17128 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17129 | /* move this sequence to the tail to indicate a young sequence */ |
| 17130 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17131 | seq_dmabuf->time_stamp = jiffies; |
| 17132 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17133 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 17134 | temp_hdr = dmabuf->hbuf.virt; |
| 17135 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17136 | return seq_dmabuf; |
| 17137 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17138 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17139 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17140 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17141 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17142 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17143 | /* |
| 17144 | * If the frame's sequence count is greater than the frame on |
| 17145 | * the list then insert the frame right after this frame |
| 17146 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17147 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17148 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17149 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17150 | found = 1; |
| 17151 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17152 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17153 | |
| 17154 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17155 | break; |
| 17156 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17157 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17158 | |
| 17159 | if (found) |
| 17160 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17161 | return NULL; |
| 17162 | } |
| 17163 | |
| 17164 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17165 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17166 | * @vport: pointer to a vitural port |
| 17167 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17168 | * |
| 17169 | * This function tries to abort from the partially assembed sequence, described |
| 17170 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17171 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17172 | * the frames from the partially assembled sequence. |
| 17173 | * |
| 17174 | * Return |
| 17175 | * true -- if there is matching partially assembled sequence present and all |
| 17176 | * the frames freed with the sequence; |
| 17177 | * false -- if there is no matching partially assembled sequence present so |
| 17178 | * nothing got aborted in the lower layer driver |
| 17179 | **/ |
| 17180 | static bool |
| 17181 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17182 | struct hbq_dmabuf *dmabuf) |
| 17183 | { |
| 17184 | struct fc_frame_header *new_hdr; |
| 17185 | struct fc_frame_header *temp_hdr; |
| 17186 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 17187 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17188 | |
| 17189 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 17190 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 17191 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 17192 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17193 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17194 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17195 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17196 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17197 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17198 | continue; |
| 17199 | /* found a pending sequence that matches this frame */ |
| 17200 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17201 | break; |
| 17202 | } |
| 17203 | |
| 17204 | /* Free up all the frames from the partially assembled sequence */ |
| 17205 | if (seq_dmabuf) { |
| 17206 | list_for_each_entry_safe(d_buf, n_buf, |
| 17207 | &seq_dmabuf->dbuf.list, list) { |
| 17208 | list_del_init(&d_buf->list); |
| 17209 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17210 | } |
| 17211 | return true; |
| 17212 | } |
| 17213 | return false; |
| 17214 | } |
| 17215 | |
| 17216 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17217 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 17218 | * @vport: pointer to a vitural port |
| 17219 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17220 | * |
| 17221 | * This function tries to abort from the assembed sequence from upper level |
| 17222 | * protocol, described by the information from basic abbort @dmabuf. It |
| 17223 | * checks to see whether such pending context exists at upper level protocol. |
| 17224 | * If so, it shall clean up the pending context. |
| 17225 | * |
| 17226 | * Return |
| 17227 | * true -- if there is matching pending context of the sequence cleaned |
| 17228 | * at ulp; |
| 17229 | * false -- if there is no matching pending context of the sequence present |
| 17230 | * at ulp. |
| 17231 | **/ |
| 17232 | static bool |
| 17233 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17234 | { |
| 17235 | struct lpfc_hba *phba = vport->phba; |
| 17236 | int handled; |
| 17237 | |
| 17238 | /* Accepting abort at ulp with SLI4 only */ |
| 17239 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 17240 | return false; |
| 17241 | |
| 17242 | /* Register all caring upper level protocols to attend abort */ |
| 17243 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 17244 | if (handled) |
| 17245 | return true; |
| 17246 | |
| 17247 | return false; |
| 17248 | } |
| 17249 | |
| 17250 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17251 | * 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] | 17252 | * @phba: Pointer to HBA context object. |
| 17253 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 17254 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 17255 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17256 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17257 | * event. It properly releases the memory allocated to the sequence abort |
| 17258 | * accept iocb. |
| 17259 | **/ |
| 17260 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17261 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17262 | struct lpfc_iocbq *cmd_iocbq, |
| 17263 | struct lpfc_iocbq *rsp_iocbq) |
| 17264 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17265 | struct lpfc_nodelist *ndlp; |
| 17266 | |
| 17267 | if (cmd_iocbq) { |
| 17268 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 17269 | lpfc_nlp_put(ndlp); |
| 17270 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17271 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17272 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17273 | |
| 17274 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 17275 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 17276 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17277 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17278 | rsp_iocbq->iocb.ulpStatus, |
| 17279 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17280 | } |
| 17281 | |
| 17282 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17283 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17284 | * @phba: Pointer to HBA context object. |
| 17285 | * @xri: xri id in transaction. |
| 17286 | * |
| 17287 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17288 | * used by the driver. |
| 17289 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17290 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17291 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17292 | uint16_t xri) |
| 17293 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17294 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17295 | |
| 17296 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17297 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17298 | return i; |
| 17299 | } |
| 17300 | return NO_XRI; |
| 17301 | } |
| 17302 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17303 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17304 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17305 | * @phba: Pointer to HBA context object. |
| 17306 | * @fc_hdr: pointer to a FC frame header. |
| 17307 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17308 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17309 | * event after aborting the sequence handling. |
| 17310 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17311 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17312 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17313 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17314 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17315 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17316 | struct lpfc_iocbq *ctiocb = NULL; |
| 17317 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17318 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17319 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17320 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17321 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17322 | |
| 17323 | if (!lpfc_is_link_up(phba)) |
| 17324 | return; |
| 17325 | |
| 17326 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17327 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17328 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17329 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17330 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17331 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17332 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17333 | if (!ndlp) { |
| 17334 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17335 | "1268 Failed to allocate ndlp for " |
| 17336 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17337 | return; |
| 17338 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17339 | /* Put ndlp onto pport node list */ |
| 17340 | lpfc_enqueue_node(vport, ndlp); |
| 17341 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17342 | /* re-setup ndlp without removing from node list */ |
| 17343 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17344 | if (!ndlp) { |
| 17345 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17346 | "3275 Failed to active ndlp found " |
| 17347 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17348 | return; |
| 17349 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17350 | } |
| 17351 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17352 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17353 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17354 | if (!ctiocb) |
| 17355 | return; |
| 17356 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17357 | /* Extract the F_CTL field from FC_HDR */ |
| 17358 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17359 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17360 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17361 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17362 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17363 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17364 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17365 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17366 | |
| 17367 | /* Fill in the rest of iocb fields */ |
| 17368 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17369 | icmd->ulpBdeCount = 0; |
| 17370 | icmd->ulpLe = 1; |
| 17371 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17372 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17373 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17374 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17375 | ctiocb->iocb_cmpl = NULL; |
| 17376 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17377 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17378 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17379 | ctiocb->sli4_xritag = NO_XRI; |
| 17380 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17381 | if (fctl & FC_FC_EX_CTX) |
| 17382 | /* Exchange responder sent the abort so we |
| 17383 | * own the oxid. |
| 17384 | */ |
| 17385 | xri = oxid; |
| 17386 | else |
| 17387 | xri = rxid; |
| 17388 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17389 | if (lxri != NO_XRI) |
| 17390 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17391 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17392 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17393 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17394 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17395 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17396 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17397 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17398 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17399 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17400 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17401 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17402 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17403 | } |
| 17404 | |
| 17405 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17406 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17407 | * the IOCB for a BA_RJT. |
| 17408 | */ |
| 17409 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17410 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17411 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17412 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17413 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17414 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17415 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17416 | if (fctl & FC_FC_EX_CTX) { |
| 17417 | /* ABTS sent by responder to CT exchange, construction |
| 17418 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17419 | * field and RX_ID from ABTS for RX_ID field. |
| 17420 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17421 | 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] | 17422 | } else { |
| 17423 | /* ABTS sent by initiator to CT exchange, construction |
| 17424 | * 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] | 17425 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17426 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17427 | 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] | 17428 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17429 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17430 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17431 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17432 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17433 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17434 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17435 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17436 | |
| 17437 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17438 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17439 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17440 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17441 | "xri x%x, Data x%x\n", |
| 17442 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17443 | phba->link_state); |
| 17444 | lpfc_nlp_put(ndlp); |
| 17445 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17446 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17447 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17448 | } |
| 17449 | |
| 17450 | /** |
| 17451 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17452 | * @vport: Pointer to the vport on which this sequence was received |
| 17453 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17454 | * |
| 17455 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17456 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17457 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17458 | * unsolicited receive sequence has been completely assembled and passed to |
| 17459 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17460 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17461 | * accept to accept the abort. |
| 17462 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17463 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17464 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17465 | struct hbq_dmabuf *dmabuf) |
| 17466 | { |
| 17467 | struct lpfc_hba *phba = vport->phba; |
| 17468 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17469 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17470 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17471 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17472 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17473 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17474 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17475 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17476 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17477 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17478 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17479 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17480 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17481 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17482 | if (aborted == false) |
| 17483 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17484 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17485 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17486 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17487 | if (phba->nvmet_support) { |
| 17488 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17489 | return; |
| 17490 | } |
| 17491 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17492 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17493 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17494 | } |
| 17495 | |
| 17496 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17497 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 17498 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17499 | * |
| 17500 | * This function checks the sequence, starting with the frame described by |
| 17501 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 17502 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 17503 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 17504 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 17505 | * set. 3) That there are no holes in the sequence count. The function will |
| 17506 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 17507 | **/ |
| 17508 | static int |
| 17509 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 17510 | { |
| 17511 | struct fc_frame_header *hdr; |
| 17512 | struct lpfc_dmabuf *d_buf; |
| 17513 | struct hbq_dmabuf *seq_dmabuf; |
| 17514 | uint32_t fctl; |
| 17515 | int seq_count = 0; |
| 17516 | |
| 17517 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17518 | /* make sure first fame of sequence has a sequence count of zero */ |
| 17519 | if (hdr->fh_seq_cnt != seq_count) |
| 17520 | return 0; |
| 17521 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17522 | hdr->fh_f_ctl[1] << 8 | |
| 17523 | hdr->fh_f_ctl[2]); |
| 17524 | /* If last frame of sequence we can return success. */ |
| 17525 | if (fctl & FC_FC_END_SEQ) |
| 17526 | return 1; |
| 17527 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 17528 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17529 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17530 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17531 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17532 | return 0; |
| 17533 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17534 | hdr->fh_f_ctl[1] << 8 | |
| 17535 | hdr->fh_f_ctl[2]); |
| 17536 | /* If last frame of sequence we can return success. */ |
| 17537 | if (fctl & FC_FC_END_SEQ) |
| 17538 | return 1; |
| 17539 | } |
| 17540 | return 0; |
| 17541 | } |
| 17542 | |
| 17543 | /** |
| 17544 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 17545 | * @vport: Pointer to the vport on which this sequence was received |
| 17546 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17547 | * |
| 17548 | * This function takes a sequence, described by a list of frames, and creates |
| 17549 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 17550 | * used to issue to the generic unsolicited sequence handler. This routine |
| 17551 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 17552 | * to allocate an iocbq then it throw out the received frames that were not |
| 17553 | * able to be described and return a pointer to the first iocbq. If unable to |
| 17554 | * allocate any iocbqs (including the first) this function will return NULL. |
| 17555 | **/ |
| 17556 | static struct lpfc_iocbq * |
| 17557 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 17558 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17559 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17560 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 17561 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 17562 | struct fc_frame_header *fc_hdr; |
| 17563 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17564 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17565 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17566 | |
| 17567 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17568 | /* remove from receive buffer list */ |
| 17569 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17570 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17571 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17572 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17573 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17574 | /* Get an iocbq struct to fill in. */ |
| 17575 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17576 | if (first_iocbq) { |
| 17577 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17578 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17579 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17580 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17581 | |
| 17582 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17583 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17584 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17585 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17586 | sli4_did_from_fc_hdr(fc_hdr); |
| 17587 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17588 | } else |
| 17589 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17590 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 17591 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 17592 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 17593 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 17594 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 17595 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17596 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17597 | tot_len = bf_get(lpfc_rcqe_length, |
| 17598 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17599 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17600 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 17601 | first_iocbq->context3 = NULL; |
| 17602 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17603 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 17604 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17605 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17606 | else |
| 17607 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 17608 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17609 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17610 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17611 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17612 | } |
| 17613 | iocbq = first_iocbq; |
| 17614 | /* |
| 17615 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17616 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17617 | */ |
| 17618 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17619 | if (!iocbq) { |
| 17620 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17621 | continue; |
| 17622 | } |
| 17623 | if (!iocbq->context3) { |
| 17624 | iocbq->context3 = d_buf; |
| 17625 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17626 | /* We need to get the size out of the right CQE */ |
| 17627 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17628 | len = bf_get(lpfc_rcqe_length, |
| 17629 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17630 | pbde = (struct ulp_bde64 *) |
| 17631 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17632 | if (len > LPFC_DATA_BUF_SIZE) |
| 17633 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17634 | else |
| 17635 | pbde->tus.f.bdeSize = len; |
| 17636 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17637 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17638 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17639 | } else { |
| 17640 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17641 | if (!iocbq) { |
| 17642 | if (first_iocbq) { |
| 17643 | first_iocbq->iocb.ulpStatus = |
| 17644 | IOSTAT_FCP_RSP_ERROR; |
| 17645 | first_iocbq->iocb.un.ulpWord[4] = |
| 17646 | IOERR_NO_RESOURCES; |
| 17647 | } |
| 17648 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17649 | continue; |
| 17650 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17651 | /* We need to get the size out of the right CQE */ |
| 17652 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17653 | len = bf_get(lpfc_rcqe_length, |
| 17654 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17655 | iocbq->context2 = d_buf; |
| 17656 | iocbq->context3 = NULL; |
| 17657 | iocbq->iocb.ulpBdeCount = 1; |
| 17658 | if (len > LPFC_DATA_BUF_SIZE) |
| 17659 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17660 | LPFC_DATA_BUF_SIZE; |
| 17661 | else |
| 17662 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17663 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17664 | tot_len += len; |
| 17665 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17666 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17667 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17668 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17669 | } |
| 17670 | } |
| 17671 | return first_iocbq; |
| 17672 | } |
| 17673 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17674 | static void |
| 17675 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17676 | struct hbq_dmabuf *seq_dmabuf) |
| 17677 | { |
| 17678 | struct fc_frame_header *fc_hdr; |
| 17679 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17680 | struct lpfc_hba *phba = vport->phba; |
| 17681 | |
| 17682 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17683 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17684 | if (!iocbq) { |
| 17685 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17686 | "2707 Ring %d handler: Failed to allocate " |
| 17687 | "iocb Rctl x%x Type x%x received\n", |
| 17688 | LPFC_ELS_RING, |
| 17689 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17690 | return; |
| 17691 | } |
| 17692 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17693 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17694 | iocbq, fc_hdr->fh_r_ctl, |
| 17695 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17696 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17697 | "2540 Ring %d handler: unexpected Rctl " |
| 17698 | "x%x Type x%x received\n", |
| 17699 | LPFC_ELS_RING, |
| 17700 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17701 | |
| 17702 | /* Free iocb created in lpfc_prep_seq */ |
| 17703 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17704 | &iocbq->list, list) { |
| 17705 | list_del_init(&curr_iocb->list); |
| 17706 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17707 | } |
| 17708 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17709 | } |
| 17710 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17711 | static void |
| 17712 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17713 | struct lpfc_iocbq *rspiocb) |
| 17714 | { |
| 17715 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17716 | |
| 17717 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17718 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17719 | kfree(pcmd); |
| 17720 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17721 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17722 | } |
| 17723 | |
| 17724 | static void |
| 17725 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17726 | struct hbq_dmabuf *dmabuf) |
| 17727 | { |
| 17728 | struct fc_frame_header *fc_hdr; |
| 17729 | struct lpfc_hba *phba = vport->phba; |
| 17730 | struct lpfc_iocbq *iocbq = NULL; |
| 17731 | union lpfc_wqe *wqe; |
| 17732 | struct lpfc_dmabuf *pcmd = NULL; |
| 17733 | uint32_t frame_len; |
| 17734 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17735 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17736 | |
| 17737 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17738 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17739 | |
| 17740 | /* Send the received frame back */ |
| 17741 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17742 | if (!iocbq) { |
| 17743 | /* Queue cq event and wakeup worker thread to process it */ |
| 17744 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 17745 | list_add_tail(&dmabuf->cq_event.list, |
| 17746 | &phba->sli4_hba.sp_queue_event); |
| 17747 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 17748 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 17749 | lpfc_worker_wake_up(phba); |
| 17750 | return; |
| 17751 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17752 | |
| 17753 | /* Allocate buffer for command payload */ |
| 17754 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17755 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17756 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17757 | &pcmd->phys); |
| 17758 | if (!pcmd || !pcmd->virt) |
| 17759 | goto exit; |
| 17760 | |
| 17761 | INIT_LIST_HEAD(&pcmd->list); |
| 17762 | |
| 17763 | /* copyin the payload */ |
| 17764 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17765 | |
| 17766 | /* fill in BDE's for command */ |
| 17767 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17768 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17769 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17770 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17771 | |
| 17772 | iocbq->context2 = pcmd; |
| 17773 | iocbq->vport = vport; |
| 17774 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17775 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17776 | |
| 17777 | /* |
| 17778 | * Setup rest of the iocb as though it were a WQE |
| 17779 | * Build the SEND_FRAME WQE |
| 17780 | */ |
| 17781 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17782 | |
| 17783 | wqe->send_frame.frame_len = frame_len; |
| 17784 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17785 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17786 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17787 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17788 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17789 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17790 | |
| 17791 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17792 | iocbq->iocb.ulpLe = 1; |
| 17793 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17794 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17795 | if (rc == IOCB_ERROR) |
| 17796 | goto exit; |
| 17797 | |
| 17798 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17799 | return; |
| 17800 | |
| 17801 | exit: |
| 17802 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17803 | "2023 Unable to process MDS loopback frame\n"); |
| 17804 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17805 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17806 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17807 | if (iocbq) |
| 17808 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17809 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17810 | } |
| 17811 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17812 | /** |
| 17813 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17814 | * @phba: Pointer to HBA context object. |
| 17815 | * |
| 17816 | * This function is called with no lock held. This function processes all |
| 17817 | * the received buffers and gives it to upper layers when a received buffer |
| 17818 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17819 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17820 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17821 | * appropriate receive function when the final frame in a sequence is received. |
| 17822 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17823 | void |
| 17824 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17825 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17826 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17827 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17828 | struct fc_frame_header *fc_hdr; |
| 17829 | struct lpfc_vport *vport; |
| 17830 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17831 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17832 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17833 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17834 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17835 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17836 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 17837 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 17838 | vport = phba->pport; |
| 17839 | /* Handle MDS Loopback frames */ |
| 17840 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17841 | return; |
| 17842 | } |
| 17843 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17844 | /* check to see if this a valid type of frame */ |
| 17845 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17846 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17847 | return; |
| 17848 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17849 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17850 | if ((bf_get(lpfc_cqe_code, |
| 17851 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17852 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17853 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17854 | else |
| 17855 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17856 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17857 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17858 | /* d_id this frame is directed to */ |
| 17859 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17860 | |
| 17861 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17862 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17863 | /* throw out the frame */ |
| 17864 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17865 | return; |
| 17866 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17867 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17868 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 17869 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 17870 | (did != Fabric_DID)) { |
| 17871 | /* |
| 17872 | * Throw out the frame if we are not pt2pt. |
| 17873 | * The pt2pt protocol allows for discovery frames |
| 17874 | * to be received without a registered VPI. |
| 17875 | */ |
| 17876 | if (!(vport->fc_flag & FC_PT2PT) || |
| 17877 | (phba->link_state == LPFC_HBA_READY)) { |
| 17878 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17879 | return; |
| 17880 | } |
| 17881 | } |
| 17882 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17883 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 17884 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 17885 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 17886 | return; |
| 17887 | } |
| 17888 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17889 | /* Link this frame */ |
| 17890 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 17891 | if (!seq_dmabuf) { |
| 17892 | /* unable to add frame to vport - throw it out */ |
| 17893 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17894 | return; |
| 17895 | } |
| 17896 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17897 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17898 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17899 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17900 | /* Send the complete sequence to the upper layer protocol */ |
| 17901 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17902 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17903 | |
| 17904 | /** |
| 17905 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 17906 | * @phba: pointer to lpfc hba data structure. |
| 17907 | * |
| 17908 | * This routine is invoked to post rpi header templates to the |
| 17909 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17910 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17911 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17912 | * |
| 17913 | * This routine does not require any locks. It's usage is expected |
| 17914 | * to be driver load or reset recovery when the driver is |
| 17915 | * sequential. |
| 17916 | * |
| 17917 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17918 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17919 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17920 | * When this error occurs, the driver is not guaranteed |
| 17921 | * to have any rpi regions posted to the device and |
| 17922 | * must either attempt to repost the regions or take a |
| 17923 | * fatal error. |
| 17924 | **/ |
| 17925 | int |
| 17926 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 17927 | { |
| 17928 | struct lpfc_rpi_hdr *rpi_page; |
| 17929 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17930 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17931 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17932 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17933 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17934 | goto exit; |
| 17935 | if (phba->sli4_hba.extents_in_use) |
| 17936 | return -EIO; |
| 17937 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17938 | 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] | 17939 | /* |
| 17940 | * Assign the rpi headers a physical rpi only if the driver |
| 17941 | * has not initialized those resources. A port reset only |
| 17942 | * needs the headers posted. |
| 17943 | */ |
| 17944 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 17945 | LPFC_RPI_RSRC_RDY) |
| 17946 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 17947 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17948 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 17949 | if (rc != MBX_SUCCESS) { |
| 17950 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17951 | "2008 Error %d posting all rpi " |
| 17952 | "headers\n", rc); |
| 17953 | rc = -EIO; |
| 17954 | break; |
| 17955 | } |
| 17956 | } |
| 17957 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17958 | exit: |
| 17959 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 17960 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17961 | return rc; |
| 17962 | } |
| 17963 | |
| 17964 | /** |
| 17965 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 17966 | * @phba: pointer to lpfc hba data structure. |
| 17967 | * @rpi_page: pointer to the rpi memory region. |
| 17968 | * |
| 17969 | * This routine is invoked to post a single rpi header to the |
| 17970 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 17971 | * maps up to 64 rpi context regions. |
| 17972 | * |
| 17973 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17974 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17975 | * -ENOMEM - No available memory |
| 17976 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17977 | **/ |
| 17978 | int |
| 17979 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 17980 | { |
| 17981 | LPFC_MBOXQ_t *mboxq; |
| 17982 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 17983 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17984 | uint32_t shdr_status, shdr_add_status; |
| 17985 | union lpfc_sli4_cfg_shdr *shdr; |
| 17986 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17987 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17988 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17989 | return rc; |
| 17990 | if (phba->sli4_hba.extents_in_use) |
| 17991 | return -EIO; |
| 17992 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17993 | /* The port is notified of the header region via a mailbox command. */ |
| 17994 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17995 | if (!mboxq) { |
| 17996 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17997 | "2001 Unable to allocate memory for issuing " |
| 17998 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 17999 | return -ENOMEM; |
| 18000 | } |
| 18001 | |
| 18002 | /* Post all rpi memory regions to the port. */ |
| 18003 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18004 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18005 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18006 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18007 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18008 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18009 | |
| 18010 | |
| 18011 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18012 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18013 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18014 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18015 | hdr_tmpl, rpi_page->page_count); |
| 18016 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18017 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18018 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18019 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18020 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18021 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18022 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18023 | if (rc != MBX_TIMEOUT) |
| 18024 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18025 | if (shdr_status || shdr_add_status || rc) { |
| 18026 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18027 | "2514 POST_RPI_HDR mailbox failed with " |
| 18028 | "status x%x add_status x%x, mbx status x%x\n", |
| 18029 | shdr_status, shdr_add_status, rc); |
| 18030 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18031 | } else { |
| 18032 | /* |
| 18033 | * The next_rpi stores the next logical module-64 rpi value used |
| 18034 | * to post physical rpis in subsequent rpi postings. |
| 18035 | */ |
| 18036 | spin_lock_irq(&phba->hbalock); |
| 18037 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18038 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18039 | } |
| 18040 | return rc; |
| 18041 | } |
| 18042 | |
| 18043 | /** |
| 18044 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18045 | * @phba: pointer to lpfc hba data structure. |
| 18046 | * |
| 18047 | * This routine is invoked to post rpi header templates to the |
| 18048 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18049 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18050 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18051 | * |
| 18052 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18053 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18054 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18055 | **/ |
| 18056 | int |
| 18057 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18058 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18059 | unsigned long rpi; |
| 18060 | uint16_t max_rpi, rpi_limit; |
| 18061 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18062 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18063 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18064 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18065 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18066 | * Fetch the next logical rpi. Because this index is logical, |
| 18067 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18068 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18069 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18070 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18071 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18072 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18073 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18074 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18075 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18076 | else { |
| 18077 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18078 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18079 | phba->sli4_hba.rpi_count++; |
| 18080 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18081 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 18082 | "0001 rpi:%x max:%x lim:%x\n", |
| 18083 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18084 | |
| 18085 | /* |
| 18086 | * 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] | 18087 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18088 | */ |
| 18089 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18090 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18091 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18092 | return rpi; |
| 18093 | } |
| 18094 | |
| 18095 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18096 | * RPI header postings are not required for SLI4 ports capable of |
| 18097 | * extents. |
| 18098 | */ |
| 18099 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18100 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18101 | return rpi; |
| 18102 | } |
| 18103 | |
| 18104 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18105 | * If the driver is running low on rpi resources, allocate another |
| 18106 | * page now. Note that the next_rpi value is used because |
| 18107 | * it represents how many are actually in use whereas max_rpi notes |
| 18108 | * how many are supported max by the device. |
| 18109 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18110 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18111 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18112 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18113 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18114 | if (!rpi_hdr) { |
| 18115 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18116 | "2002 Error Could not grow rpi " |
| 18117 | "count\n"); |
| 18118 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18119 | lrpi = rpi_hdr->start_rpi; |
| 18120 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18121 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18122 | } |
| 18123 | } |
| 18124 | |
| 18125 | return rpi; |
| 18126 | } |
| 18127 | |
| 18128 | /** |
| 18129 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18130 | * @phba: pointer to lpfc hba data structure. |
| 18131 | * |
| 18132 | * This routine is invoked to release an rpi to the pool of |
| 18133 | * available rpis maintained by the driver. |
| 18134 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18135 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18136 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18137 | { |
| 18138 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18139 | phba->sli4_hba.rpi_count--; |
| 18140 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 18141 | } |
| 18142 | } |
| 18143 | |
| 18144 | /** |
| 18145 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18146 | * @phba: pointer to lpfc hba data structure. |
| 18147 | * |
| 18148 | * This routine is invoked to release an rpi to the pool of |
| 18149 | * available rpis maintained by the driver. |
| 18150 | **/ |
| 18151 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18152 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18153 | { |
| 18154 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18155 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18156 | spin_unlock_irq(&phba->hbalock); |
| 18157 | } |
| 18158 | |
| 18159 | /** |
| 18160 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 18161 | * @phba: pointer to lpfc hba data structure. |
| 18162 | * |
| 18163 | * This routine is invoked to remove the memory region that |
| 18164 | * provided rpi via a bitmask. |
| 18165 | **/ |
| 18166 | void |
| 18167 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 18168 | { |
| 18169 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18170 | kfree(phba->sli4_hba.rpi_ids); |
| 18171 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18172 | } |
| 18173 | |
| 18174 | /** |
| 18175 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 18176 | * @phba: pointer to lpfc hba data structure. |
| 18177 | * |
| 18178 | * This routine is invoked to remove the memory region that |
| 18179 | * provided rpi via a bitmask. |
| 18180 | **/ |
| 18181 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18182 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 18183 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18184 | { |
| 18185 | LPFC_MBOXQ_t *mboxq; |
| 18186 | struct lpfc_hba *phba = ndlp->phba; |
| 18187 | int rc; |
| 18188 | |
| 18189 | /* The port is notified of the header region via a mailbox command. */ |
| 18190 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18191 | if (!mboxq) |
| 18192 | return -ENOMEM; |
| 18193 | |
| 18194 | /* Post all rpi memory regions to the port. */ |
| 18195 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18196 | if (cmpl) { |
| 18197 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 18198 | mboxq->ctx_buf = arg; |
| 18199 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 18200 | } else |
| 18201 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18202 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18203 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18204 | if (rc == MBX_NOT_FINISHED) { |
| 18205 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18206 | "2010 Resume RPI Mailbox failed " |
| 18207 | "status %d, mbxStatus x%x\n", rc, |
| 18208 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 18209 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18210 | return -EIO; |
| 18211 | } |
| 18212 | return 0; |
| 18213 | } |
| 18214 | |
| 18215 | /** |
| 18216 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18217 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18218 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18219 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18220 | * |
| 18221 | * Returns: |
| 18222 | * 0 success |
| 18223 | * -Evalue otherwise |
| 18224 | **/ |
| 18225 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18226 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18227 | { |
| 18228 | LPFC_MBOXQ_t *mboxq; |
| 18229 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18230 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18231 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18232 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18233 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18234 | if (!mboxq) |
| 18235 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18236 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18237 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18238 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18239 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18240 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18241 | "2022 INIT VPI Mailbox failed " |
| 18242 | "status %d, mbxStatus x%x\n", rc, |
| 18243 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18244 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18245 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18246 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18247 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18248 | |
| 18249 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18250 | } |
| 18251 | |
| 18252 | /** |
| 18253 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 18254 | * @phba: pointer to lpfc hba data structure. |
| 18255 | * @mboxq: Pointer to mailbox object. |
| 18256 | * |
| 18257 | * This routine is invoked to manually add a single FCF record. The caller |
| 18258 | * must pass a completely initialized FCF_Record. This routine takes |
| 18259 | * care of the nonembedded mailbox operations. |
| 18260 | **/ |
| 18261 | static void |
| 18262 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 18263 | { |
| 18264 | void *virt_addr; |
| 18265 | union lpfc_sli4_cfg_shdr *shdr; |
| 18266 | uint32_t shdr_status, shdr_add_status; |
| 18267 | |
| 18268 | virt_addr = mboxq->sge_array->addr[0]; |
| 18269 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18270 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 18271 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18272 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18273 | |
| 18274 | if ((shdr_status || shdr_add_status) && |
| 18275 | (shdr_status != STATUS_FCF_IN_USE)) |
| 18276 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18277 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 18278 | "status x%x add_status x%x\n", |
| 18279 | shdr_status, shdr_add_status); |
| 18280 | |
| 18281 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18282 | } |
| 18283 | |
| 18284 | /** |
| 18285 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 18286 | * @phba: pointer to lpfc hba data structure. |
| 18287 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18288 | * |
| 18289 | * This routine is invoked to manually add a single FCF record. The caller |
| 18290 | * must pass a completely initialized FCF_Record. This routine takes |
| 18291 | * care of the nonembedded mailbox operations. |
| 18292 | **/ |
| 18293 | int |
| 18294 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18295 | { |
| 18296 | int rc = 0; |
| 18297 | LPFC_MBOXQ_t *mboxq; |
| 18298 | uint8_t *bytep; |
| 18299 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18300 | struct lpfc_mbx_sge sge; |
| 18301 | uint32_t alloc_len, req_len; |
| 18302 | uint32_t fcfindex; |
| 18303 | |
| 18304 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18305 | if (!mboxq) { |
| 18306 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18307 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18308 | return -ENOMEM; |
| 18309 | } |
| 18310 | |
| 18311 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18312 | sizeof(uint32_t); |
| 18313 | |
| 18314 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18315 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18316 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18317 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18318 | if (alloc_len < req_len) { |
| 18319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18320 | "2523 Allocated DMA memory size (x%x) is " |
| 18321 | "less than the requested DMA memory " |
| 18322 | "size (x%x)\n", alloc_len, req_len); |
| 18323 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18324 | return -ENOMEM; |
| 18325 | } |
| 18326 | |
| 18327 | /* |
| 18328 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18329 | * routine only uses a single SGE. |
| 18330 | */ |
| 18331 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18332 | virt_addr = mboxq->sge_array->addr[0]; |
| 18333 | /* |
| 18334 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18335 | * hardcoded default and gets used in nonFIP mode. |
| 18336 | */ |
| 18337 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18338 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18339 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18340 | |
| 18341 | /* |
| 18342 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18343 | * the FCoE header plus word10. The data copy needs to be endian |
| 18344 | * correct. |
| 18345 | */ |
| 18346 | bytep += sizeof(uint32_t); |
| 18347 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18348 | mboxq->vport = phba->pport; |
| 18349 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18350 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18351 | if (rc == MBX_NOT_FINISHED) { |
| 18352 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18353 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18354 | "status 0x%x\n", rc); |
| 18355 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18356 | rc = -EIO; |
| 18357 | } else |
| 18358 | rc = 0; |
| 18359 | |
| 18360 | return rc; |
| 18361 | } |
| 18362 | |
| 18363 | /** |
| 18364 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18365 | * @phba: pointer to lpfc hba data structure. |
| 18366 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18367 | * @fcf_index: FCF table entry index. |
| 18368 | * |
| 18369 | * This routine is invoked to build the driver's default FCF record. The |
| 18370 | * values used are hardcoded. This routine handles memory initialization. |
| 18371 | * |
| 18372 | **/ |
| 18373 | void |
| 18374 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18375 | struct fcf_record *fcf_record, |
| 18376 | uint16_t fcf_index) |
| 18377 | { |
| 18378 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18379 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18380 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18381 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18382 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18383 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18384 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18385 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18386 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18387 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18388 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18389 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18390 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18391 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18392 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18393 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18394 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18395 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18396 | /* Set the VLAN bit map */ |
| 18397 | if (phba->valid_vlan) { |
| 18398 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18399 | = 1 << (phba->vlan_id % 8); |
| 18400 | } |
| 18401 | } |
| 18402 | |
| 18403 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18404 | * 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] | 18405 | * @phba: pointer to lpfc hba data structure. |
| 18406 | * @fcf_index: FCF table entry offset. |
| 18407 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18408 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18409 | * record and processing it one at a time starting from the @fcf_index |
| 18410 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18411 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18412 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18413 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18414 | **/ |
| 18415 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18416 | 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] | 18417 | { |
| 18418 | int rc = 0, error; |
| 18419 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18420 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18421 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18422 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18423 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18424 | if (!mboxq) { |
| 18425 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18426 | "2000 Failed to allocate mbox for " |
| 18427 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18428 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18429 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18430 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18431 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18432 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18433 | if (rc) { |
| 18434 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18435 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18436 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18437 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18438 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18439 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18440 | |
| 18441 | spin_lock_irq(&phba->hbalock); |
| 18442 | phba->hba_flag |= FCF_TS_INPROG; |
| 18443 | spin_unlock_irq(&phba->hbalock); |
| 18444 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18445 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18446 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18447 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18448 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18449 | /* Reset eligible FCF count for new scan */ |
| 18450 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18451 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18452 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18453 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18454 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18455 | if (error) { |
| 18456 | if (mboxq) |
| 18457 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18458 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18459 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18460 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18461 | spin_unlock_irq(&phba->hbalock); |
| 18462 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18463 | return error; |
| 18464 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18465 | |
| 18466 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18467 | * 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] | 18468 | * @phba: pointer to lpfc hba data structure. |
| 18469 | * @fcf_index: FCF table entry offset. |
| 18470 | * |
| 18471 | * 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] | 18472 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18473 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18474 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18475 | * otherwise. |
| 18476 | **/ |
| 18477 | int |
| 18478 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18479 | { |
| 18480 | int rc = 0, error; |
| 18481 | LPFC_MBOXQ_t *mboxq; |
| 18482 | |
| 18483 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18484 | if (!mboxq) { |
| 18485 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18486 | "2763 Failed to allocate mbox for " |
| 18487 | "READ_FCF cmd\n"); |
| 18488 | error = -ENOMEM; |
| 18489 | goto fail_fcf_read; |
| 18490 | } |
| 18491 | /* Construct the read FCF record mailbox command */ |
| 18492 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18493 | if (rc) { |
| 18494 | error = -EINVAL; |
| 18495 | goto fail_fcf_read; |
| 18496 | } |
| 18497 | /* Issue the mailbox command asynchronously */ |
| 18498 | mboxq->vport = phba->pport; |
| 18499 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 18500 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18501 | if (rc == MBX_NOT_FINISHED) |
| 18502 | error = -EIO; |
| 18503 | else |
| 18504 | error = 0; |
| 18505 | |
| 18506 | fail_fcf_read: |
| 18507 | if (error && mboxq) |
| 18508 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18509 | return error; |
| 18510 | } |
| 18511 | |
| 18512 | /** |
| 18513 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 18514 | * @phba: pointer to lpfc hba data structure. |
| 18515 | * @fcf_index: FCF table entry offset. |
| 18516 | * |
| 18517 | * 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] | 18518 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18519 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18520 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18521 | * otherwise. |
| 18522 | **/ |
| 18523 | int |
| 18524 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18525 | { |
| 18526 | int rc = 0, error; |
| 18527 | LPFC_MBOXQ_t *mboxq; |
| 18528 | |
| 18529 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18530 | if (!mboxq) { |
| 18531 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18532 | "2758 Failed to allocate mbox for " |
| 18533 | "READ_FCF cmd\n"); |
| 18534 | error = -ENOMEM; |
| 18535 | goto fail_fcf_read; |
| 18536 | } |
| 18537 | /* Construct the read FCF record mailbox command */ |
| 18538 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18539 | if (rc) { |
| 18540 | error = -EINVAL; |
| 18541 | goto fail_fcf_read; |
| 18542 | } |
| 18543 | /* Issue the mailbox command asynchronously */ |
| 18544 | mboxq->vport = phba->pport; |
| 18545 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 18546 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18547 | if (rc == MBX_NOT_FINISHED) |
| 18548 | error = -EIO; |
| 18549 | else |
| 18550 | error = 0; |
| 18551 | |
| 18552 | fail_fcf_read: |
| 18553 | if (error && mboxq) |
| 18554 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18555 | return error; |
| 18556 | } |
| 18557 | |
| 18558 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18559 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18560 | * phba pointer to the lpfc_hba struct for this port. |
| 18561 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 18562 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 18563 | * rr_bmask based on their priority level. Starting from the highest priority |
| 18564 | * to the lowest. The most likely FCF candidate will be in the highest |
| 18565 | * priority group. When this routine is called it searches the fcf_pri list for |
| 18566 | * next lowest priority group and repopulates the rr_bmask with only those |
| 18567 | * fcf_indexes. |
| 18568 | * returns: |
| 18569 | * 1=success 0=failure |
| 18570 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18571 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18572 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 18573 | { |
| 18574 | uint16_t next_fcf_pri; |
| 18575 | uint16_t last_index; |
| 18576 | struct lpfc_fcf_pri *fcf_pri; |
| 18577 | int rc; |
| 18578 | int ret = 0; |
| 18579 | |
| 18580 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 18581 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18582 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 18583 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18584 | |
| 18585 | /* Verify the priority list has 2 or more entries */ |
| 18586 | spin_lock_irq(&phba->hbalock); |
| 18587 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 18588 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 18589 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18590 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 18591 | "3061 Last IDX %d\n", last_index); |
| 18592 | return 0; /* Empty rr list */ |
| 18593 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18594 | spin_unlock_irq(&phba->hbalock); |
| 18595 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18596 | next_fcf_pri = 0; |
| 18597 | /* |
| 18598 | * Clear the rr_bmask and set all of the bits that are at this |
| 18599 | * priority. |
| 18600 | */ |
| 18601 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 18602 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 18603 | spin_lock_irq(&phba->hbalock); |
| 18604 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18605 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 18606 | continue; |
| 18607 | /* |
| 18608 | * the 1st priority that has not FLOGI failed |
| 18609 | * will be the highest. |
| 18610 | */ |
| 18611 | if (!next_fcf_pri) |
| 18612 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18613 | spin_unlock_irq(&phba->hbalock); |
| 18614 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18615 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18616 | fcf_pri->fcf_rec.fcf_index); |
| 18617 | if (rc) |
| 18618 | return 0; |
| 18619 | } |
| 18620 | spin_lock_irq(&phba->hbalock); |
| 18621 | } |
| 18622 | /* |
| 18623 | * if next_fcf_pri was not set above and the list is not empty then |
| 18624 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18625 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18626 | */ |
| 18627 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18628 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18629 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18630 | /* |
| 18631 | * the 1st priority that has not FLOGI failed |
| 18632 | * will be the highest. |
| 18633 | */ |
| 18634 | if (!next_fcf_pri) |
| 18635 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18636 | spin_unlock_irq(&phba->hbalock); |
| 18637 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18638 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18639 | fcf_pri->fcf_rec.fcf_index); |
| 18640 | if (rc) |
| 18641 | return 0; |
| 18642 | } |
| 18643 | spin_lock_irq(&phba->hbalock); |
| 18644 | } |
| 18645 | } else |
| 18646 | ret = 1; |
| 18647 | spin_unlock_irq(&phba->hbalock); |
| 18648 | |
| 18649 | return ret; |
| 18650 | } |
| 18651 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18652 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18653 | * @phba: pointer to lpfc hba data structure. |
| 18654 | * |
| 18655 | * This routine is to get the next eligible FCF record index in a round |
| 18656 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18657 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18658 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18659 | * shall be returned. |
| 18660 | **/ |
| 18661 | uint16_t |
| 18662 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18663 | { |
| 18664 | uint16_t next_fcf_index; |
| 18665 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18666 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18667 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18668 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18669 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18670 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18671 | /* Determine the next fcf index to check */ |
| 18672 | 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] | 18673 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18674 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18675 | next_fcf_index); |
| 18676 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18677 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18678 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18679 | /* |
| 18680 | * If we have wrapped then we need to clear the bits that |
| 18681 | * have been tested so that we can detect when we should |
| 18682 | * change the priority level. |
| 18683 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18684 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18685 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18686 | } |
| 18687 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18688 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18689 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18690 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18691 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18692 | /* |
| 18693 | * If next fcf index is not found check if there are lower |
| 18694 | * Priority level fcf's in the fcf_priority list. |
| 18695 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18696 | * at that level and continue the selection process. |
| 18697 | */ |
| 18698 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18699 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18700 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18701 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 18702 | |
| 18703 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18704 | } |
| 18705 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18706 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18707 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18708 | LPFC_FCF_FLOGI_FAILED) { |
| 18709 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18710 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18711 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18712 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18713 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18714 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18715 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18716 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18717 | next_fcf_index); |
| 18718 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18719 | return next_fcf_index; |
| 18720 | } |
| 18721 | |
| 18722 | /** |
| 18723 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18724 | * @phba: pointer to lpfc hba data structure. |
| 18725 | * |
| 18726 | * 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] | 18727 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18728 | * does not go beyond the range of the driver allocated bmask dimension |
| 18729 | * before setting the bit. |
| 18730 | * |
| 18731 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18732 | * -EINVAL. |
| 18733 | **/ |
| 18734 | int |
| 18735 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18736 | { |
| 18737 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18738 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18739 | "2610 FCF (x%x) reached driver's book " |
| 18740 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18741 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18742 | return -EINVAL; |
| 18743 | } |
| 18744 | /* Set the eligible FCF record index bmask */ |
| 18745 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18746 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18747 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18748 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18749 | "bmask\n", fcf_index); |
| 18750 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18751 | return 0; |
| 18752 | } |
| 18753 | |
| 18754 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18755 | * 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] | 18756 | * @phba: pointer to lpfc hba data structure. |
| 18757 | * |
| 18758 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18759 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18760 | * does not go beyond the range of the driver allocated bmask dimension |
| 18761 | * before clearing the bit. |
| 18762 | **/ |
| 18763 | void |
| 18764 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18765 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18766 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18767 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18768 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18769 | "2762 FCF (x%x) reached driver's book " |
| 18770 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18771 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18772 | return; |
| 18773 | } |
| 18774 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18775 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18776 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18777 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18778 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18779 | list_del_init(&fcf_pri->list); |
| 18780 | break; |
| 18781 | } |
| 18782 | } |
| 18783 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18784 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18785 | |
| 18786 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18787 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18788 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18789 | } |
| 18790 | |
| 18791 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18792 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18793 | * @phba: pointer to lpfc hba data structure. |
| 18794 | * |
| 18795 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18796 | * command. If the mailbox command returned failure, it will try to stop the |
| 18797 | * FCF rediscover wait timer. |
| 18798 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18799 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18800 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18801 | { |
| 18802 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18803 | uint32_t shdr_status, shdr_add_status; |
| 18804 | |
| 18805 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18806 | |
| 18807 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18808 | &redisc_fcf->header.cfg_shdr.response); |
| 18809 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18810 | &redisc_fcf->header.cfg_shdr.response); |
| 18811 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18812 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18813 | "2746 Requesting for FCF rediscovery failed " |
| 18814 | "status x%x add_status x%x\n", |
| 18815 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18816 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18817 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18818 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18819 | spin_unlock_irq(&phba->hbalock); |
| 18820 | /* |
| 18821 | * CVL event triggered FCF rediscover request failed, |
| 18822 | * last resort to re-try current registered FCF entry. |
| 18823 | */ |
| 18824 | lpfc_retry_pport_discovery(phba); |
| 18825 | } else { |
| 18826 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18827 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18828 | spin_unlock_irq(&phba->hbalock); |
| 18829 | /* |
| 18830 | * DEAD FCF event triggered FCF rediscover request |
| 18831 | * failed, last resort to fail over as a link down |
| 18832 | * to FCF registration. |
| 18833 | */ |
| 18834 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18835 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18836 | } else { |
| 18837 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18838 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18839 | /* |
| 18840 | * Start FCF rediscovery wait timer for pending FCF |
| 18841 | * before rescan FCF record table. |
| 18842 | */ |
| 18843 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18844 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18845 | |
| 18846 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18847 | } |
| 18848 | |
| 18849 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18850 | * 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] | 18851 | * @phba: pointer to lpfc hba data structure. |
| 18852 | * |
| 18853 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18854 | * by the port. |
| 18855 | **/ |
| 18856 | int |
| 18857 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18858 | { |
| 18859 | LPFC_MBOXQ_t *mbox; |
| 18860 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18861 | int rc, length; |
| 18862 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18863 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18864 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18865 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18866 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18867 | if (!mbox) { |
| 18868 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18869 | "2745 Failed to allocate mbox for " |
| 18870 | "requesting FCF rediscover.\n"); |
| 18871 | return -ENOMEM; |
| 18872 | } |
| 18873 | |
| 18874 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 18875 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 18876 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18877 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 18878 | length, LPFC_SLI4_MBX_EMBED); |
| 18879 | |
| 18880 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18881 | /* Set count to 0 for invalidating the entire FCF database */ |
| 18882 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 18883 | |
| 18884 | /* Issue the mailbox command asynchronously */ |
| 18885 | mbox->vport = phba->pport; |
| 18886 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 18887 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 18888 | |
| 18889 | if (rc == MBX_NOT_FINISHED) { |
| 18890 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18891 | return -EIO; |
| 18892 | } |
| 18893 | return 0; |
| 18894 | } |
| 18895 | |
| 18896 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18897 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 18898 | * @phba: pointer to lpfc hba data structure. |
| 18899 | * |
| 18900 | * This function is the failover routine as a last resort to the FCF DEAD |
| 18901 | * event when driver failed to perform fast FCF failover. |
| 18902 | **/ |
| 18903 | void |
| 18904 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 18905 | { |
| 18906 | uint32_t link_state; |
| 18907 | |
| 18908 | /* |
| 18909 | * Last resort as FCF DEAD event failover will treat this as |
| 18910 | * a link down, but save the link state because we don't want |
| 18911 | * it to be changed to Link Down unless it is already down. |
| 18912 | */ |
| 18913 | link_state = phba->link_state; |
| 18914 | lpfc_linkdown(phba); |
| 18915 | phba->link_state = link_state; |
| 18916 | |
| 18917 | /* Unregister FCF if no devices connected to it */ |
| 18918 | lpfc_unregister_unused_fcf(phba); |
| 18919 | } |
| 18920 | |
| 18921 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18922 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18923 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18924 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18925 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18926 | * This function gets SLI3 port configure region 23 data through memory dump |
| 18927 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18928 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18929 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18930 | static uint32_t |
| 18931 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18932 | { |
| 18933 | LPFC_MBOXQ_t *pmb = NULL; |
| 18934 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18935 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18936 | int rc; |
| 18937 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18938 | if (!rgn23_data) |
| 18939 | return 0; |
| 18940 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18941 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18942 | if (!pmb) { |
| 18943 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18944 | "2600 failed to allocate mailbox memory\n"); |
| 18945 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18946 | } |
| 18947 | mb = &pmb->u.mb; |
| 18948 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18949 | do { |
| 18950 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 18951 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 18952 | |
| 18953 | if (rc != MBX_SUCCESS) { |
| 18954 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18955 | "2601 failed to read config " |
| 18956 | "region 23, rc 0x%x Status 0x%x\n", |
| 18957 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18958 | mb->un.varDmp.word_cnt = 0; |
| 18959 | } |
| 18960 | /* |
| 18961 | * dump mem may return a zero when finished or we got a |
| 18962 | * mailbox error, either way we are done. |
| 18963 | */ |
| 18964 | if (mb->un.varDmp.word_cnt == 0) |
| 18965 | break; |
| 18966 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 18967 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 18968 | |
| 18969 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18970 | rgn23_data + offset, |
| 18971 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18972 | offset += mb->un.varDmp.word_cnt; |
| 18973 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 18974 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18975 | mempool_free(pmb, phba->mbox_mem_pool); |
| 18976 | return offset; |
| 18977 | } |
| 18978 | |
| 18979 | /** |
| 18980 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 18981 | * @phba: pointer to lpfc hba data structure. |
| 18982 | * @rgn23_data: pointer to configure region 23 data. |
| 18983 | * |
| 18984 | * This function gets SLI4 port configure region 23 data through memory dump |
| 18985 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18986 | * will be returned, otherwise, 0 will be returned. |
| 18987 | **/ |
| 18988 | static uint32_t |
| 18989 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 18990 | { |
| 18991 | LPFC_MBOXQ_t *mboxq = NULL; |
| 18992 | struct lpfc_dmabuf *mp = NULL; |
| 18993 | struct lpfc_mqe *mqe; |
| 18994 | uint32_t data_length = 0; |
| 18995 | int rc; |
| 18996 | |
| 18997 | if (!rgn23_data) |
| 18998 | return 0; |
| 18999 | |
| 19000 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19001 | if (!mboxq) { |
| 19002 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19003 | "3105 failed to allocate mailbox memory\n"); |
| 19004 | return 0; |
| 19005 | } |
| 19006 | |
| 19007 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19008 | goto out; |
| 19009 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19010 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19011 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19012 | if (rc) |
| 19013 | goto out; |
| 19014 | data_length = mqe->un.mb_words[5]; |
| 19015 | if (data_length == 0) |
| 19016 | goto out; |
| 19017 | if (data_length > DMP_RGN23_SIZE) { |
| 19018 | data_length = 0; |
| 19019 | goto out; |
| 19020 | } |
| 19021 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19022 | out: |
| 19023 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19024 | if (mp) { |
| 19025 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19026 | kfree(mp); |
| 19027 | } |
| 19028 | return data_length; |
| 19029 | } |
| 19030 | |
| 19031 | /** |
| 19032 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19033 | * @phba: pointer to lpfc hba data structure. |
| 19034 | * |
| 19035 | * This function read region 23 and parse TLV for port status to |
| 19036 | * decide if the user disaled the port. If the TLV indicates the |
| 19037 | * port is disabled, the hba_flag is set accordingly. |
| 19038 | **/ |
| 19039 | void |
| 19040 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19041 | { |
| 19042 | uint8_t *rgn23_data = NULL; |
| 19043 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19044 | uint32_t offset = 0; |
| 19045 | |
| 19046 | /* Get adapter Region 23 data */ |
| 19047 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19048 | if (!rgn23_data) |
| 19049 | goto out; |
| 19050 | |
| 19051 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19052 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19053 | else { |
| 19054 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19055 | &phba->sli4_hba.sli_intf); |
| 19056 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19057 | goto out; |
| 19058 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19059 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19060 | |
| 19061 | if (!data_size) |
| 19062 | goto out; |
| 19063 | |
| 19064 | /* Check the region signature first */ |
| 19065 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 19066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19067 | "2619 Config region 23 has bad signature\n"); |
| 19068 | goto out; |
| 19069 | } |
| 19070 | offset += 4; |
| 19071 | |
| 19072 | /* Check the data structure version */ |
| 19073 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 19074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19075 | "2620 Config region 23 has bad version\n"); |
| 19076 | goto out; |
| 19077 | } |
| 19078 | offset += 4; |
| 19079 | |
| 19080 | /* Parse TLV entries in the region */ |
| 19081 | while (offset < data_size) { |
| 19082 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19083 | break; |
| 19084 | /* |
| 19085 | * If the TLV is not driver specific TLV or driver id is |
| 19086 | * not linux driver id, skip the record. |
| 19087 | */ |
| 19088 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19089 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19090 | (rgn23_data[offset + 3] != 0)) { |
| 19091 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19092 | continue; |
| 19093 | } |
| 19094 | |
| 19095 | /* Driver found a driver specific TLV in the config region */ |
| 19096 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19097 | offset += 4; |
| 19098 | tlv_offset = 0; |
| 19099 | |
| 19100 | /* |
| 19101 | * Search for configured port state sub-TLV. |
| 19102 | */ |
| 19103 | while ((offset < data_size) && |
| 19104 | (tlv_offset < sub_tlv_len)) { |
| 19105 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19106 | offset += 4; |
| 19107 | tlv_offset += 4; |
| 19108 | break; |
| 19109 | } |
| 19110 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19111 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19112 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19113 | continue; |
| 19114 | } |
| 19115 | |
| 19116 | /* This HBA contains PORT_STE configured */ |
| 19117 | if (!rgn23_data[offset + 2]) |
| 19118 | phba->hba_flag |= LINK_DISABLED; |
| 19119 | |
| 19120 | goto out; |
| 19121 | } |
| 19122 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19123 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19124 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19125 | kfree(rgn23_data); |
| 19126 | return; |
| 19127 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19128 | |
| 19129 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19130 | * lpfc_wr_object - write an object to the firmware |
| 19131 | * @phba: HBA structure that indicates port to create a queue on. |
| 19132 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19133 | * @size: the total byte value of the objects to write to the port. |
| 19134 | * @offset: the current offset to be used to start the transfer. |
| 19135 | * |
| 19136 | * This routine will create a wr_object mailbox command to send to the port. |
| 19137 | * the mailbox command will be constructed using the dma buffers described in |
| 19138 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19139 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19140 | * used to indicate the starting offset of the transfer and will also return |
| 19141 | * the offset after the write object mailbox has completed. @size is used to |
| 19142 | * determine the end of the object and whether the eof bit should be set. |
| 19143 | * |
| 19144 | * Return 0 is successful and offset will contain the the new offset to use |
| 19145 | * for the next write. |
| 19146 | * Return negative value for error cases. |
| 19147 | **/ |
| 19148 | int |
| 19149 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 19150 | uint32_t size, uint32_t *offset) |
| 19151 | { |
| 19152 | struct lpfc_mbx_wr_object *wr_object; |
| 19153 | LPFC_MBOXQ_t *mbox; |
| 19154 | int rc = 0, i = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19155 | uint32_t shdr_status, shdr_add_status, shdr_change_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19156 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19157 | struct lpfc_dmabuf *dmabuf; |
| 19158 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19159 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19160 | |
| 19161 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19162 | if (!mbox) |
| 19163 | return -ENOMEM; |
| 19164 | |
| 19165 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 19166 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 19167 | sizeof(struct lpfc_mbx_wr_object) - |
| 19168 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 19169 | |
| 19170 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 19171 | wr_object->u.request.write_offset = *offset; |
| 19172 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 19173 | wr_object->u.request.object_name[0] = |
| 19174 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 19175 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 19176 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 19177 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 19178 | break; |
| 19179 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 19180 | wr_object->u.request.bde[i].addrHigh = |
| 19181 | putPaddrHigh(dmabuf->phys); |
| 19182 | if (written + SLI4_PAGE_SIZE >= size) { |
| 19183 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19184 | (size - written); |
| 19185 | written += (size - written); |
| 19186 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19187 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 19188 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19189 | } else { |
| 19190 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19191 | SLI4_PAGE_SIZE; |
| 19192 | written += SLI4_PAGE_SIZE; |
| 19193 | } |
| 19194 | i++; |
| 19195 | } |
| 19196 | wr_object->u.request.bde_count = i; |
| 19197 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 19198 | if (!phba->sli4_hba.intr_enable) |
| 19199 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 19200 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19201 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19202 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 19203 | } |
| 19204 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19205 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19206 | &wr_object->header.cfg_shdr.response); |
| 19207 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19208 | &wr_object->header.cfg_shdr.response); |
| 19209 | if (check_change_status) { |
| 19210 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 19211 | &wr_object->u.response); |
| 19212 | switch (shdr_change_status) { |
| 19213 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 19214 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19215 | "3198 Firmware write complete: System " |
| 19216 | "reboot required to instantiate\n"); |
| 19217 | break; |
| 19218 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 19219 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19220 | "3199 Firmware write complete: Firmware" |
| 19221 | " reset required to instantiate\n"); |
| 19222 | break; |
| 19223 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 19224 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19225 | "3200 Firmware write complete: Port " |
| 19226 | "Migration or PCI Reset required to " |
| 19227 | "instantiate\n"); |
| 19228 | break; |
| 19229 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 19230 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19231 | "3201 Firmware write complete: PCI " |
| 19232 | "Reset required to instantiate\n"); |
| 19233 | break; |
| 19234 | default: |
| 19235 | break; |
| 19236 | } |
| 19237 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19238 | if (rc != MBX_TIMEOUT) |
| 19239 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19240 | if (shdr_status || shdr_add_status || rc) { |
| 19241 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19242 | "3025 Write Object mailbox failed with " |
| 19243 | "status x%x add_status x%x, mbx status x%x\n", |
| 19244 | shdr_status, shdr_add_status, rc); |
| 19245 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 19246 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19247 | } else |
| 19248 | *offset += wr_object->u.response.actual_write_length; |
| 19249 | return rc; |
| 19250 | } |
| 19251 | |
| 19252 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19253 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 19254 | * @vport: pointer to vport data structure. |
| 19255 | * |
| 19256 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 19257 | * and REG_VPI mailbox commands associated with the vport. This function |
| 19258 | * is called when driver want to restart discovery of the vport due to |
| 19259 | * a Clear Virtual Link event. |
| 19260 | **/ |
| 19261 | void |
| 19262 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 19263 | { |
| 19264 | struct lpfc_hba *phba = vport->phba; |
| 19265 | LPFC_MBOXQ_t *mb, *nextmb; |
| 19266 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19267 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19268 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19269 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19270 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19271 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19272 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19273 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19274 | spin_lock_irq(&phba->hbalock); |
| 19275 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 19276 | if (mb->vport != vport) |
| 19277 | continue; |
| 19278 | |
| 19279 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19280 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19281 | continue; |
| 19282 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19283 | list_del(&mb->list); |
| 19284 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 19285 | } |
| 19286 | /* Clean up active mailbox command with the vport */ |
| 19287 | mb = phba->sli.mbox_active; |
| 19288 | if (mb && (mb->vport == vport)) { |
| 19289 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 19290 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 19291 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19292 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19293 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19294 | /* Put reference count for delayed processing */ |
| 19295 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 19296 | /* Unregister the RPI when mailbox complete */ |
| 19297 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19298 | } |
| 19299 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19300 | /* Cleanup any mailbox completions which are not yet processed */ |
| 19301 | do { |
| 19302 | restart_loop = 0; |
| 19303 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 19304 | /* |
| 19305 | * If this mailox is already processed or it is |
| 19306 | * for another vport ignore it. |
| 19307 | */ |
| 19308 | if ((mb->vport != vport) || |
| 19309 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 19310 | continue; |
| 19311 | |
| 19312 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19313 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19314 | continue; |
| 19315 | |
| 19316 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19317 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19318 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19319 | /* Unregister the RPI when mailbox complete */ |
| 19320 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19321 | restart_loop = 1; |
| 19322 | spin_unlock_irq(&phba->hbalock); |
| 19323 | spin_lock(shost->host_lock); |
| 19324 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19325 | spin_unlock(shost->host_lock); |
| 19326 | spin_lock_irq(&phba->hbalock); |
| 19327 | break; |
| 19328 | } |
| 19329 | } |
| 19330 | } while (restart_loop); |
| 19331 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19332 | spin_unlock_irq(&phba->hbalock); |
| 19333 | |
| 19334 | /* Release the cleaned-up mailbox commands */ |
| 19335 | while (!list_empty(&mbox_cmd_list)) { |
| 19336 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19337 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19338 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19339 | if (mp) { |
| 19340 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19341 | kfree(mp); |
| 19342 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19343 | mb->ctx_buf = NULL; |
| 19344 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 19345 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19346 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19347 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19348 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19349 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19350 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19351 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19352 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19353 | mempool_free(mb, phba->mbox_mem_pool); |
| 19354 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19355 | |
| 19356 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19357 | if (act_mbx_ndlp) { |
| 19358 | spin_lock(shost->host_lock); |
| 19359 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19360 | spin_unlock(shost->host_lock); |
| 19361 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19362 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19363 | } |
| 19364 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19365 | /** |
| 19366 | * lpfc_drain_txq - Drain the txq |
| 19367 | * @phba: Pointer to HBA context object. |
| 19368 | * |
| 19369 | * This function attempt to submit IOCBs on the txq |
| 19370 | * to the adapter. For SLI4 adapters, the txq contains |
| 19371 | * ELS IOCBs that have been deferred because the there |
| 19372 | * are no SGLs. This congestion can occur with large |
| 19373 | * vport counts during node discovery. |
| 19374 | **/ |
| 19375 | |
| 19376 | uint32_t |
| 19377 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19378 | { |
| 19379 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19380 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19381 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19382 | unsigned long iflags = 0; |
| 19383 | char *fail_msg = NULL; |
| 19384 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19385 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19386 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19387 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19388 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19389 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19390 | /* MDS WQE are posted only to first WQ*/ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 19391 | wq = phba->sli4_hba.hdwq[0].fcp_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19392 | if (unlikely(!wq)) |
| 19393 | return 0; |
| 19394 | pring = wq->pring; |
| 19395 | } else { |
| 19396 | wq = phba->sli4_hba.els_wq; |
| 19397 | if (unlikely(!wq)) |
| 19398 | return 0; |
| 19399 | pring = lpfc_phba_elsring(phba); |
| 19400 | } |
| 19401 | |
| 19402 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19403 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19404 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19405 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19406 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19407 | txq_cnt++; |
| 19408 | } |
| 19409 | |
| 19410 | if (txq_cnt > pring->txq_max) |
| 19411 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19412 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19413 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19414 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19415 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19416 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19417 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19418 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19419 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19420 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19421 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19422 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19423 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19424 | break; |
| 19425 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19426 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19427 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19428 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19429 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19430 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19431 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19432 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19433 | |
| 19434 | /* The xri and iocb resources secured, |
| 19435 | * attempt to issue request |
| 19436 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19437 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19438 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19439 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19440 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19441 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19442 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19443 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19444 | fail_msg = " - Wq is full"; |
| 19445 | else |
| 19446 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19447 | |
| 19448 | if (fail_msg) { |
| 19449 | /* Failed means we can't issue and need to cancel */ |
| 19450 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19451 | "2822 IOCB failed %s iotag 0x%x " |
| 19452 | "xri 0x%x\n", |
| 19453 | fail_msg, |
| 19454 | piocbq->iotag, piocbq->sli4_xritag); |
| 19455 | list_add_tail(&piocbq->list, &completions); |
| 19456 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19457 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19458 | } |
| 19459 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19460 | /* Cancel all the IOCBs that cannot be issued */ |
| 19461 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 19462 | IOERR_SLI_ABORTED); |
| 19463 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19464 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19465 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19466 | |
| 19467 | /** |
| 19468 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 19469 | * @phba: Pointer to HBA context object. |
| 19470 | * @pwqe: Pointer to command WQE. |
| 19471 | * @sglq: Pointer to the scatter gather queue object. |
| 19472 | * |
| 19473 | * This routine converts the bpl or bde that is in the WQE |
| 19474 | * to a sgl list for the sli4 hardware. The physical address |
| 19475 | * of the bpl/bde is converted back to a virtual address. |
| 19476 | * If the WQE contains a BPL then the list of BDE's is |
| 19477 | * converted to sli4_sge's. If the WQE contains a single |
| 19478 | * BDE then it is converted to a single sli_sge. |
| 19479 | * The WQE is still in cpu endianness so the contents of |
| 19480 | * the bpl can be used without byte swapping. |
| 19481 | * |
| 19482 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 19483 | */ |
| 19484 | static uint16_t |
| 19485 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 19486 | struct lpfc_sglq *sglq) |
| 19487 | { |
| 19488 | uint16_t xritag = NO_XRI; |
| 19489 | struct ulp_bde64 *bpl = NULL; |
| 19490 | struct ulp_bde64 bde; |
| 19491 | struct sli4_sge *sgl = NULL; |
| 19492 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19493 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19494 | int numBdes = 0; |
| 19495 | int i = 0; |
| 19496 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 19497 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 19498 | uint32_t cmd; |
| 19499 | |
| 19500 | if (!pwqeq || !sglq) |
| 19501 | return xritag; |
| 19502 | |
| 19503 | sgl = (struct sli4_sge *)sglq->sgl; |
| 19504 | wqe = &pwqeq->wqe; |
| 19505 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 19506 | |
| 19507 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 19508 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 19509 | return sglq->sli4_xritag; |
| 19510 | numBdes = pwqeq->rsvd2; |
| 19511 | if (numBdes) { |
| 19512 | /* The addrHigh and addrLow fields within the WQE |
| 19513 | * have not been byteswapped yet so there is no |
| 19514 | * need to swap them back. |
| 19515 | */ |
| 19516 | if (pwqeq->context3) |
| 19517 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 19518 | else |
| 19519 | return xritag; |
| 19520 | |
| 19521 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 19522 | if (!bpl) |
| 19523 | return xritag; |
| 19524 | |
| 19525 | for (i = 0; i < numBdes; i++) { |
| 19526 | /* Should already be byte swapped. */ |
| 19527 | sgl->addr_hi = bpl->addrHigh; |
| 19528 | sgl->addr_lo = bpl->addrLow; |
| 19529 | |
| 19530 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19531 | if ((i+1) == numBdes) |
| 19532 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19533 | else |
| 19534 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 19535 | /* swap the size field back to the cpu so we |
| 19536 | * can assign it to the sgl. |
| 19537 | */ |
| 19538 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 19539 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 19540 | /* The offsets in the sgl need to be accumulated |
| 19541 | * separately for the request and reply lists. |
| 19542 | * The request is always first, the reply follows. |
| 19543 | */ |
| 19544 | switch (cmd) { |
| 19545 | case CMD_GEN_REQUEST64_WQE: |
| 19546 | /* add up the reply sg entries */ |
| 19547 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 19548 | inbound++; |
| 19549 | /* first inbound? reset the offset */ |
| 19550 | if (inbound == 1) |
| 19551 | offset = 0; |
| 19552 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19553 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19554 | LPFC_SGE_TYPE_DATA); |
| 19555 | offset += bde.tus.f.bdeSize; |
| 19556 | break; |
| 19557 | case CMD_FCP_TRSP64_WQE: |
| 19558 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 19559 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19560 | LPFC_SGE_TYPE_DATA); |
| 19561 | break; |
| 19562 | case CMD_FCP_TSEND64_WQE: |
| 19563 | case CMD_FCP_TRECEIVE64_WQE: |
| 19564 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19565 | bpl->tus.f.bdeFlags); |
| 19566 | if (i < 3) |
| 19567 | offset = 0; |
| 19568 | else |
| 19569 | offset += bde.tus.f.bdeSize; |
| 19570 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19571 | break; |
| 19572 | } |
| 19573 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19574 | bpl++; |
| 19575 | sgl++; |
| 19576 | } |
| 19577 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 19578 | /* The addrHigh and addrLow fields of the BDE have not |
| 19579 | * been byteswapped yet so they need to be swapped |
| 19580 | * before putting them in the sgl. |
| 19581 | */ |
| 19582 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 19583 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 19584 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19585 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19586 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19587 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 19588 | } |
| 19589 | return sglq->sli4_xritag; |
| 19590 | } |
| 19591 | |
| 19592 | /** |
| 19593 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 19594 | * @phba: Pointer to HBA context object. |
| 19595 | * @ring_number: Base sli ring number |
| 19596 | * @pwqe: Pointer to command WQE. |
| 19597 | **/ |
| 19598 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19599 | lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19600 | struct lpfc_iocbq *pwqe) |
| 19601 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19602 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19603 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19604 | struct lpfc_queue *wq; |
| 19605 | struct lpfc_sglq *sglq; |
| 19606 | struct lpfc_sli_ring *pring; |
| 19607 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19608 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19609 | |
| 19610 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 19611 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 19612 | pring = phba->sli4_hba.nvmels_wq->pring; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19613 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19614 | qp, wq_access); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19615 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 19616 | if (!sglq) { |
| 19617 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19618 | return WQE_BUSY; |
| 19619 | } |
| 19620 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19621 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19622 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 19623 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19624 | return WQE_ERROR; |
| 19625 | } |
| 19626 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19627 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19628 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 19629 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19630 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19631 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19632 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19633 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19634 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19635 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19636 | return 0; |
| 19637 | } |
| 19638 | |
| 19639 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 19640 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 19641 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19642 | wq = qp->nvme_wq; |
| 19643 | pring = wq->pring; |
| 19644 | |
| 19645 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->nvme_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19646 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19647 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19648 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19649 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19650 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19651 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19652 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19653 | } |
| 19654 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19655 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19656 | return 0; |
| 19657 | } |
| 19658 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19659 | /* NVMET requests */ |
| 19660 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 19661 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19662 | wq = qp->nvme_wq; |
| 19663 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19664 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19665 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19666 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19667 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19668 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19669 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19670 | } |
| 19671 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19672 | pwqe->sli4_xritag); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19673 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->nvme_cq_map); |
| 19674 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19675 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19676 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19677 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19678 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19679 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19680 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19681 | } |
| 19682 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19683 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19684 | return 0; |
| 19685 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19686 | return WQE_ERROR; |
| 19687 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19688 | |
| 19689 | #ifdef LPFC_MXP_STAT |
| 19690 | /** |
| 19691 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 19692 | * @phba: pointer to lpfc hba data structure. |
| 19693 | * @hwqid: belong to which HWQ. |
| 19694 | * |
| 19695 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 19696 | * 15 seconds after a test case is running. |
| 19697 | * |
| 19698 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 19699 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 19700 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 19701 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 19702 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 19703 | **/ |
| 19704 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 19705 | { |
| 19706 | struct lpfc_sli4_hdw_queue *qp; |
| 19707 | struct lpfc_multixri_pool *multixri_pool; |
| 19708 | struct lpfc_pvt_pool *pvt_pool; |
| 19709 | struct lpfc_pbl_pool *pbl_pool; |
| 19710 | u32 txcmplq_cnt; |
| 19711 | |
| 19712 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19713 | multixri_pool = qp->p_multixri_pool; |
| 19714 | if (!multixri_pool) |
| 19715 | return; |
| 19716 | |
| 19717 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 19718 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 19719 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 19720 | txcmplq_cnt = qp->fcp_wq->pring->txcmplq_cnt; |
| 19721 | if (qp->nvme_wq) |
| 19722 | txcmplq_cnt += qp->nvme_wq->pring->txcmplq_cnt; |
| 19723 | |
| 19724 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 19725 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 19726 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 19727 | } |
| 19728 | |
| 19729 | multixri_pool->stat_snapshot_taken++; |
| 19730 | } |
| 19731 | #endif |
| 19732 | |
| 19733 | /** |
| 19734 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 19735 | * @phba: pointer to lpfc hba data structure. |
| 19736 | * @hwqid: belong to which HWQ. |
| 19737 | * |
| 19738 | * This routine moves some XRIs from private to public pool when private pool |
| 19739 | * is not busy. |
| 19740 | **/ |
| 19741 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 19742 | { |
| 19743 | struct lpfc_multixri_pool *multixri_pool; |
| 19744 | u32 io_req_count; |
| 19745 | u32 prev_io_req_count; |
| 19746 | |
| 19747 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 19748 | if (!multixri_pool) |
| 19749 | return; |
| 19750 | io_req_count = multixri_pool->io_req_count; |
| 19751 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 19752 | |
| 19753 | if (prev_io_req_count != io_req_count) { |
| 19754 | /* Private pool is busy */ |
| 19755 | multixri_pool->prev_io_req_count = io_req_count; |
| 19756 | } else { |
| 19757 | /* Private pool is not busy. |
| 19758 | * Move XRIs from private to public pool. |
| 19759 | */ |
| 19760 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 19761 | } |
| 19762 | } |
| 19763 | |
| 19764 | /** |
| 19765 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 19766 | * @phba: pointer to lpfc hba data structure. |
| 19767 | * @hwqid: belong to which HWQ. |
| 19768 | * |
| 19769 | * This routine sets high watermark as number of outstanding XRIs, |
| 19770 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 19771 | **/ |
| 19772 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 19773 | { |
| 19774 | u32 new_watermark; |
| 19775 | u32 watermark_max; |
| 19776 | u32 watermark_min; |
| 19777 | u32 xri_limit; |
| 19778 | u32 txcmplq_cnt; |
| 19779 | u32 abts_io_bufs; |
| 19780 | struct lpfc_multixri_pool *multixri_pool; |
| 19781 | struct lpfc_sli4_hdw_queue *qp; |
| 19782 | |
| 19783 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19784 | multixri_pool = qp->p_multixri_pool; |
| 19785 | if (!multixri_pool) |
| 19786 | return; |
| 19787 | xri_limit = multixri_pool->xri_limit; |
| 19788 | |
| 19789 | watermark_max = xri_limit; |
| 19790 | watermark_min = xri_limit / 2; |
| 19791 | |
| 19792 | txcmplq_cnt = qp->fcp_wq->pring->txcmplq_cnt; |
| 19793 | abts_io_bufs = qp->abts_scsi_io_bufs; |
| 19794 | if (qp->nvme_wq) { |
| 19795 | txcmplq_cnt += qp->nvme_wq->pring->txcmplq_cnt; |
| 19796 | abts_io_bufs += qp->abts_nvme_io_bufs; |
| 19797 | } |
| 19798 | |
| 19799 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 19800 | new_watermark = min(watermark_max, new_watermark); |
| 19801 | new_watermark = max(watermark_min, new_watermark); |
| 19802 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 19803 | |
| 19804 | #ifdef LPFC_MXP_STAT |
| 19805 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 19806 | new_watermark); |
| 19807 | #endif |
| 19808 | } |
| 19809 | |
| 19810 | /** |
| 19811 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 19812 | * @phba: pointer to lpfc hba data structure. |
| 19813 | * @hwqid: belong to which HWQ. |
| 19814 | * |
| 19815 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 19816 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 19817 | * The first step moves (all - low_watermark) amount of XRIs. |
| 19818 | * The second step moves the rest of XRIs. |
| 19819 | **/ |
| 19820 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 19821 | { |
| 19822 | struct lpfc_pbl_pool *pbl_pool; |
| 19823 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19824 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19825 | struct lpfc_io_buf *lpfc_ncmd; |
| 19826 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 19827 | unsigned long iflag; |
| 19828 | struct list_head tmp_list; |
| 19829 | u32 tmp_count; |
| 19830 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19831 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19832 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 19833 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19834 | tmp_count = 0; |
| 19835 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19836 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 19837 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19838 | |
| 19839 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 19840 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 19841 | * to pbl_pool |
| 19842 | */ |
| 19843 | |
| 19844 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 19845 | INIT_LIST_HEAD(&tmp_list); |
| 19846 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 19847 | &pvt_pool->list, list) { |
| 19848 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 19849 | tmp_count++; |
| 19850 | if (tmp_count >= pvt_pool->low_watermark) |
| 19851 | break; |
| 19852 | } |
| 19853 | |
| 19854 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 19855 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 19856 | |
| 19857 | /* Move all bufs from tmp_list to pvt_pool */ |
| 19858 | list_splice(&tmp_list, &pvt_pool->list); |
| 19859 | |
| 19860 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 19861 | pvt_pool->count = tmp_count; |
| 19862 | } else { |
| 19863 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 19864 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 19865 | pbl_pool->count += pvt_pool->count; |
| 19866 | pvt_pool->count = 0; |
| 19867 | } |
| 19868 | |
| 19869 | spin_unlock(&pvt_pool->lock); |
| 19870 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 19871 | } |
| 19872 | |
| 19873 | /** |
| 19874 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 19875 | * @phba: pointer to lpfc hba data structure |
| 19876 | * @pbl_pool: specified public free XRI pool |
| 19877 | * @pvt_pool: specified private free XRI pool |
| 19878 | * @count: number of XRIs to move |
| 19879 | * |
| 19880 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 19881 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 19882 | * enough in public pool. |
| 19883 | * |
| 19884 | * Return: |
| 19885 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 19886 | * specified pvt_pool |
| 19887 | * false - if the specified pbl_pool is empty or locked by someone else |
| 19888 | **/ |
| 19889 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19890 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 19891 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19892 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 19893 | { |
| 19894 | struct lpfc_io_buf *lpfc_ncmd; |
| 19895 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 19896 | unsigned long iflag; |
| 19897 | int ret; |
| 19898 | |
| 19899 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 19900 | if (ret) { |
| 19901 | if (pbl_pool->count) { |
| 19902 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19903 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19904 | list_for_each_entry_safe(lpfc_ncmd, |
| 19905 | lpfc_ncmd_next, |
| 19906 | &pbl_pool->list, |
| 19907 | list) { |
| 19908 | list_move_tail(&lpfc_ncmd->list, |
| 19909 | &pvt_pool->list); |
| 19910 | pvt_pool->count++; |
| 19911 | pbl_pool->count--; |
| 19912 | count--; |
| 19913 | if (count == 0) |
| 19914 | break; |
| 19915 | } |
| 19916 | |
| 19917 | spin_unlock(&pvt_pool->lock); |
| 19918 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 19919 | return true; |
| 19920 | } |
| 19921 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 19922 | } |
| 19923 | |
| 19924 | return false; |
| 19925 | } |
| 19926 | |
| 19927 | /** |
| 19928 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 19929 | * @phba: pointer to lpfc hba data structure. |
| 19930 | * @hwqid: belong to which HWQ. |
| 19931 | * @count: number of XRIs to move |
| 19932 | * |
| 19933 | * This routine tries to find some free common bufs in one of public pools with |
| 19934 | * Round Robin method. The search always starts from local hwqid, then the next |
| 19935 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 19936 | * a batch of free common bufs are moved to private pool on hwqid. |
| 19937 | * It might move less than count XRIs if there's not enough in public pool. |
| 19938 | **/ |
| 19939 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 19940 | { |
| 19941 | struct lpfc_multixri_pool *multixri_pool; |
| 19942 | struct lpfc_multixri_pool *next_multixri_pool; |
| 19943 | struct lpfc_pvt_pool *pvt_pool; |
| 19944 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19945 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19946 | u32 next_hwqid; |
| 19947 | u32 hwq_count; |
| 19948 | int ret; |
| 19949 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19950 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19951 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19952 | pvt_pool = &multixri_pool->pvt_pool; |
| 19953 | pbl_pool = &multixri_pool->pbl_pool; |
| 19954 | |
| 19955 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19956 | ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19957 | if (ret) { |
| 19958 | #ifdef LPFC_MXP_STAT |
| 19959 | multixri_pool->local_pbl_hit_count++; |
| 19960 | #endif |
| 19961 | return; |
| 19962 | } |
| 19963 | |
| 19964 | hwq_count = phba->cfg_hdw_queue; |
| 19965 | |
| 19966 | /* Get the next hwqid which was found last time */ |
| 19967 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 19968 | |
| 19969 | do { |
| 19970 | /* Go to next hwq */ |
| 19971 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 19972 | |
| 19973 | next_multixri_pool = |
| 19974 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 19975 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 19976 | |
| 19977 | /* Check if the public free xri pool is available */ |
| 19978 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 19979 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19980 | |
| 19981 | /* Exit while-loop if success or all hwqid are checked */ |
| 19982 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 19983 | |
| 19984 | /* Starting point for the next time */ |
| 19985 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 19986 | |
| 19987 | if (!ret) { |
| 19988 | /* stats: all public pools are empty*/ |
| 19989 | multixri_pool->pbl_empty_count++; |
| 19990 | } |
| 19991 | |
| 19992 | #ifdef LPFC_MXP_STAT |
| 19993 | if (ret) { |
| 19994 | if (next_hwqid == hwqid) |
| 19995 | multixri_pool->local_pbl_hit_count++; |
| 19996 | else |
| 19997 | multixri_pool->other_pbl_hit_count++; |
| 19998 | } |
| 19999 | #endif |
| 20000 | } |
| 20001 | |
| 20002 | /** |
| 20003 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 20004 | * @phba: pointer to lpfc hba data structure. |
| 20005 | * @qp: belong to which HWQ. |
| 20006 | * |
| 20007 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 20008 | * low watermark. |
| 20009 | **/ |
| 20010 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 20011 | { |
| 20012 | struct lpfc_multixri_pool *multixri_pool; |
| 20013 | struct lpfc_pvt_pool *pvt_pool; |
| 20014 | |
| 20015 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20016 | pvt_pool = &multixri_pool->pvt_pool; |
| 20017 | |
| 20018 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 20019 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20020 | } |
| 20021 | |
| 20022 | /** |
| 20023 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 20024 | * @phba: pointer to lpfc hba data structure. |
| 20025 | * @lpfc_ncmd: IO buf to be returned. |
| 20026 | * @qp: belong to which HWQ. |
| 20027 | * |
| 20028 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 20029 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 20030 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 20031 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 20032 | * lpfc_io_buf_list_put. |
| 20033 | **/ |
| 20034 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 20035 | struct lpfc_sli4_hdw_queue *qp) |
| 20036 | { |
| 20037 | unsigned long iflag; |
| 20038 | struct lpfc_pbl_pool *pbl_pool; |
| 20039 | struct lpfc_pvt_pool *pvt_pool; |
| 20040 | struct lpfc_epd_pool *epd_pool; |
| 20041 | u32 txcmplq_cnt; |
| 20042 | u32 xri_owned; |
| 20043 | u32 xri_limit; |
| 20044 | u32 abts_io_bufs; |
| 20045 | |
| 20046 | /* MUST zero fields if buffer is reused by another protocol */ |
| 20047 | lpfc_ncmd->nvmeCmd = NULL; |
| 20048 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 20049 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 20050 | |
| 20051 | if (phba->cfg_xri_rebalancing) { |
| 20052 | if (lpfc_ncmd->expedite) { |
| 20053 | /* Return to expedite pool */ |
| 20054 | epd_pool = &phba->epd_pool; |
| 20055 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20056 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 20057 | epd_pool->count++; |
| 20058 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20059 | return; |
| 20060 | } |
| 20061 | |
| 20062 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 20063 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 20064 | * Nothing much can be done at this point. |
| 20065 | */ |
| 20066 | if (!qp->p_multixri_pool) |
| 20067 | return; |
| 20068 | |
| 20069 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20070 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20071 | |
| 20072 | txcmplq_cnt = qp->fcp_wq->pring->txcmplq_cnt; |
| 20073 | abts_io_bufs = qp->abts_scsi_io_bufs; |
| 20074 | if (qp->nvme_wq) { |
| 20075 | txcmplq_cnt += qp->nvme_wq->pring->txcmplq_cnt; |
| 20076 | abts_io_bufs += qp->abts_nvme_io_bufs; |
| 20077 | } |
| 20078 | |
| 20079 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 20080 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 20081 | |
| 20082 | #ifdef LPFC_MXP_STAT |
| 20083 | if (xri_owned <= xri_limit) |
| 20084 | qp->p_multixri_pool->below_limit_count++; |
| 20085 | else |
| 20086 | qp->p_multixri_pool->above_limit_count++; |
| 20087 | #endif |
| 20088 | |
| 20089 | /* XRI goes to either public or private free xri pool |
| 20090 | * based on watermark and xri_limit |
| 20091 | */ |
| 20092 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 20093 | (xri_owned < xri_limit && |
| 20094 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 20095 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 20096 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20097 | list_add_tail(&lpfc_ncmd->list, |
| 20098 | &pvt_pool->list); |
| 20099 | pvt_pool->count++; |
| 20100 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20101 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 20102 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 20103 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20104 | list_add_tail(&lpfc_ncmd->list, |
| 20105 | &pbl_pool->list); |
| 20106 | pbl_pool->count++; |
| 20107 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20108 | } |
| 20109 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 20110 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 20111 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20112 | list_add_tail(&lpfc_ncmd->list, |
| 20113 | &qp->lpfc_io_buf_list_put); |
| 20114 | qp->put_io_bufs++; |
| 20115 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 20116 | iflag); |
| 20117 | } |
| 20118 | } |
| 20119 | |
| 20120 | /** |
| 20121 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 20122 | * @phba: pointer to lpfc hba data structure. |
| 20123 | * @pvt_pool: pointer to private pool data structure. |
| 20124 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20125 | * |
| 20126 | * This routine tries to get one free IO buf from private pool. |
| 20127 | * |
| 20128 | * Return: |
| 20129 | * pointer to one free IO buf - if private pool is not empty |
| 20130 | * NULL - if private pool is empty |
| 20131 | **/ |
| 20132 | static struct lpfc_io_buf * |
| 20133 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 20134 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20135 | struct lpfc_pvt_pool *pvt_pool, |
| 20136 | struct lpfc_nodelist *ndlp) |
| 20137 | { |
| 20138 | struct lpfc_io_buf *lpfc_ncmd; |
| 20139 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20140 | unsigned long iflag; |
| 20141 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 20142 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20143 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20144 | &pvt_pool->list, list) { |
| 20145 | if (lpfc_test_rrq_active( |
| 20146 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 20147 | continue; |
| 20148 | list_del(&lpfc_ncmd->list); |
| 20149 | pvt_pool->count--; |
| 20150 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20151 | return lpfc_ncmd; |
| 20152 | } |
| 20153 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20154 | |
| 20155 | return NULL; |
| 20156 | } |
| 20157 | |
| 20158 | /** |
| 20159 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 20160 | * @phba: pointer to lpfc hba data structure. |
| 20161 | * |
| 20162 | * This routine tries to get one free IO buf from expedite pool. |
| 20163 | * |
| 20164 | * Return: |
| 20165 | * pointer to one free IO buf - if expedite pool is not empty |
| 20166 | * NULL - if expedite pool is empty |
| 20167 | **/ |
| 20168 | static struct lpfc_io_buf * |
| 20169 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 20170 | { |
| 20171 | struct lpfc_io_buf *lpfc_ncmd; |
| 20172 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20173 | unsigned long iflag; |
| 20174 | struct lpfc_epd_pool *epd_pool; |
| 20175 | |
| 20176 | epd_pool = &phba->epd_pool; |
| 20177 | lpfc_ncmd = NULL; |
| 20178 | |
| 20179 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20180 | if (epd_pool->count > 0) { |
| 20181 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20182 | &epd_pool->list, list) { |
| 20183 | list_del(&lpfc_ncmd->list); |
| 20184 | epd_pool->count--; |
| 20185 | break; |
| 20186 | } |
| 20187 | } |
| 20188 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20189 | |
| 20190 | return lpfc_ncmd; |
| 20191 | } |
| 20192 | |
| 20193 | /** |
| 20194 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 20195 | * @phba: pointer to lpfc hba data structure. |
| 20196 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20197 | * @hwqid: belong to which HWQ |
| 20198 | * @expedite: 1 means this request is urgent. |
| 20199 | * |
| 20200 | * This routine will do the following actions and then return a pointer to |
| 20201 | * one free IO buf. |
| 20202 | * |
| 20203 | * 1. If private free xri count is empty, move some XRIs from public to |
| 20204 | * private pool. |
| 20205 | * 2. Get one XRI from private free xri pool. |
| 20206 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 20207 | * get one free xri from expedite pool. |
| 20208 | * |
| 20209 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20210 | * The caller should pass NULL for ndlp on NVME side. |
| 20211 | * |
| 20212 | * Return: |
| 20213 | * pointer to one free IO buf - if private pool is not empty |
| 20214 | * NULL - if private pool is empty |
| 20215 | **/ |
| 20216 | static struct lpfc_io_buf * |
| 20217 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 20218 | struct lpfc_nodelist *ndlp, |
| 20219 | int hwqid, int expedite) |
| 20220 | { |
| 20221 | struct lpfc_sli4_hdw_queue *qp; |
| 20222 | struct lpfc_multixri_pool *multixri_pool; |
| 20223 | struct lpfc_pvt_pool *pvt_pool; |
| 20224 | struct lpfc_io_buf *lpfc_ncmd; |
| 20225 | |
| 20226 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20227 | lpfc_ncmd = NULL; |
| 20228 | multixri_pool = qp->p_multixri_pool; |
| 20229 | pvt_pool = &multixri_pool->pvt_pool; |
| 20230 | multixri_pool->io_req_count++; |
| 20231 | |
| 20232 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 20233 | if (pvt_pool->count == 0) |
| 20234 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20235 | |
| 20236 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 20237 | lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20238 | |
| 20239 | if (lpfc_ncmd) { |
| 20240 | lpfc_ncmd->hdwq = qp; |
| 20241 | lpfc_ncmd->hdwq_no = hwqid; |
| 20242 | } else if (expedite) { |
| 20243 | /* If we fail to get one from pvt_pool and this is an expedite |
| 20244 | * request, get one free xri from expedite pool. |
| 20245 | */ |
| 20246 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 20247 | } |
| 20248 | |
| 20249 | return lpfc_ncmd; |
| 20250 | } |
| 20251 | |
| 20252 | static inline struct lpfc_io_buf * |
| 20253 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 20254 | { |
| 20255 | struct lpfc_sli4_hdw_queue *qp; |
| 20256 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 20257 | |
| 20258 | qp = &phba->sli4_hba.hdwq[idx]; |
| 20259 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 20260 | &qp->lpfc_io_buf_list_get, list) { |
| 20261 | if (lpfc_test_rrq_active(phba, ndlp, |
| 20262 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 20263 | continue; |
| 20264 | |
| 20265 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 20266 | continue; |
| 20267 | |
| 20268 | list_del_init(&lpfc_cmd->list); |
| 20269 | qp->get_io_bufs--; |
| 20270 | lpfc_cmd->hdwq = qp; |
| 20271 | lpfc_cmd->hdwq_no = idx; |
| 20272 | return lpfc_cmd; |
| 20273 | } |
| 20274 | return NULL; |
| 20275 | } |
| 20276 | |
| 20277 | /** |
| 20278 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 20279 | * @phba: The HBA for which this call is being executed. |
| 20280 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20281 | * @hwqid: belong to which HWQ |
| 20282 | * @expedite: 1 means this request is urgent. |
| 20283 | * |
| 20284 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 20285 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 20286 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 20287 | * |
| 20288 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20289 | * The caller should pass NULL for ndlp on NVME side. |
| 20290 | * |
| 20291 | * Return codes: |
| 20292 | * NULL - Error |
| 20293 | * Pointer to lpfc_io_buf - Success |
| 20294 | **/ |
| 20295 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 20296 | struct lpfc_nodelist *ndlp, |
| 20297 | u32 hwqid, int expedite) |
| 20298 | { |
| 20299 | struct lpfc_sli4_hdw_queue *qp; |
| 20300 | unsigned long iflag; |
| 20301 | struct lpfc_io_buf *lpfc_cmd; |
| 20302 | |
| 20303 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20304 | lpfc_cmd = NULL; |
| 20305 | |
| 20306 | if (phba->cfg_xri_rebalancing) |
| 20307 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 20308 | phba, ndlp, hwqid, expedite); |
| 20309 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 20310 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 20311 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20312 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 20313 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20314 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame^] | 20315 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 20316 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20317 | list_splice(&qp->lpfc_io_buf_list_put, |
| 20318 | &qp->lpfc_io_buf_list_get); |
| 20319 | qp->get_io_bufs += qp->put_io_bufs; |
| 20320 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 20321 | qp->put_io_bufs = 0; |
| 20322 | spin_unlock(&qp->io_buf_list_put_lock); |
| 20323 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 20324 | expedite) |
| 20325 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20326 | } |
| 20327 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 20328 | } |
| 20329 | |
| 20330 | return lpfc_cmd; |
| 20331 | } |