| 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 | 145e5a8 | 2020-01-27 16:23:12 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2020 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> |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 38 | #include <linux/crash_dump.h> |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 39 | #ifdef CONFIG_X86 |
| 40 | #include <asm/set_memory.h> |
| 41 | #endif |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 43 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | #include "lpfc_hw.h" |
| 45 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 46 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 47 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 50 | #include "lpfc_scsi.h" |
| 51 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 52 | #include "lpfc_crtn.h" |
| 53 | #include "lpfc_logmsg.h" |
| 54 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 55 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 56 | #include "lpfc_vport.h" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 57 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | |
| 59 | /* There are only four IOCB completion types. */ |
| 60 | typedef enum _lpfc_iocb_type { |
| 61 | LPFC_UNKNOWN_IOCB, |
| 62 | LPFC_UNSOL_IOCB, |
| 63 | LPFC_SOL_IOCB, |
| 64 | LPFC_ABORT_IOCB |
| 65 | } lpfc_iocb_type; |
| 66 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 67 | |
| 68 | /* Provide function prototypes local to this module. */ |
| 69 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 70 | uint32_t); |
| 71 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 72 | uint8_t *, uint32_t *); |
| 73 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 74 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 75 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 76 | struct hbq_dmabuf *); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 77 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 78 | struct hbq_dmabuf *dmabuf); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 79 | static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, |
| 80 | struct lpfc_queue *cq, struct lpfc_cqe *cqe); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 81 | static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 82 | int); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 83 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 84 | struct lpfc_queue *eq, |
| 85 | struct lpfc_eqe *eqe); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 86 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 87 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 88 | static struct lpfc_cqe *lpfc_sli4_cq_get(struct lpfc_queue *q); |
| 89 | static void __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, |
| 90 | struct lpfc_queue *cq, |
| 91 | struct lpfc_cqe *cqe); |
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 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 113 | static void |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 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; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 153 | temp_wqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 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 | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 163 | if (!((q->host_index + 1) % q->notify_interval)) |
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 |
James Smart | 1543af3 | 2020-03-22 11:12:58 -0700 | [diff] [blame] | 231 | * pointers. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 232 | **/ |
James Smart | 1543af3 | 2020-03-22 11:12:58 -0700 | [diff] [blame] | 233 | static void |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 234 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 235 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 236 | /* sanity check on queue memory */ |
| 237 | if (unlikely(!q)) |
James Smart | 1543af3 | 2020-03-22 11:12:58 -0700 | [diff] [blame] | 238 | return; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 239 | |
James Smart | 1543af3 | 2020-03-22 11:12:58 -0700 | [diff] [blame] | 240 | q->hba_index = index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /** |
| 244 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 245 | * @q: The Mailbox Queue to operate on. |
| 246 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 247 | * |
| 248 | * This routine will copy the contents of @mqe to the next available entry on |
| 249 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 250 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 251 | * successful. If no entries are available on @q then this function will return |
| 252 | * -ENOMEM. |
| 253 | * The caller is expected to hold the hbalock when calling this routine. |
| 254 | **/ |
| 255 | static uint32_t |
| 256 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 257 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 258 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 259 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 260 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 261 | /* sanity check on queue memory */ |
| 262 | if (unlikely(!q)) |
| 263 | return -ENOMEM; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 264 | temp_mqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 265 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 266 | /* If the host has not yet processed the next entry then we are done */ |
| 267 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 268 | return -ENOMEM; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 269 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 270 | /* Save off the mailbox pointer for completion */ |
| 271 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 272 | |
| 273 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 274 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 275 | |
| 276 | /* Ring Doorbell */ |
| 277 | doorbell.word0 = 0; |
| 278 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 279 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 280 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 286 | * @q: The Mailbox Queue to operate on. |
| 287 | * |
| 288 | * This routine will update the HBA index of a queue to reflect consumption of |
| 289 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 290 | * an entry the host calls this function to update the queue's internal |
| 291 | * pointers. This routine returns the number of entries that were consumed by |
| 292 | * the HBA. |
| 293 | **/ |
| 294 | static uint32_t |
| 295 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 296 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 297 | /* sanity check on queue memory */ |
| 298 | if (unlikely(!q)) |
| 299 | return 0; |
| 300 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 301 | /* Clear the mailbox pointer for completion */ |
| 302 | q->phba->mbox = NULL; |
| 303 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 304 | return 1; |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 309 | * @q: The Event Queue to get the first valid EQE from |
| 310 | * |
| 311 | * This routine will get the first valid Event Queue Entry from @q, update |
| 312 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 313 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 314 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 315 | **/ |
| 316 | static struct lpfc_eqe * |
| 317 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 318 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 319 | struct lpfc_eqe *eqe; |
| 320 | |
| 321 | /* sanity check on queue memory */ |
| 322 | if (unlikely(!q)) |
| 323 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 324 | eqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 325 | |
| 326 | /* If the next EQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 327 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 328 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 329 | |
| 330 | /* |
| 331 | * insert barrier for instruction interlock : data from the hardware |
| 332 | * 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] | 333 | * upon. Speculative instructions were allowing a bcopy at the start |
| 334 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 335 | * after our return, to copy data before the valid bit check above |
| 336 | * was done. As such, some of the copied data was stale. The barrier |
| 337 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 338 | */ |
| 339 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 340 | return eqe; |
| 341 | } |
| 342 | |
| 343 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 344 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 345 | * @q: The Event Queue to disable interrupts |
| 346 | * |
| 347 | **/ |
James Smart | 92f3b32 | 2019-03-20 10:44:22 -0700 | [diff] [blame] | 348 | void |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 349 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 350 | { |
| 351 | struct lpfc_register doorbell; |
| 352 | |
| 353 | doorbell.word0 = 0; |
| 354 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 355 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 356 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 357 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 358 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 359 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 363 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ |
| 364 | * @q: The Event Queue to disable interrupts |
| 365 | * |
| 366 | **/ |
James Smart | 92f3b32 | 2019-03-20 10:44:22 -0700 | [diff] [blame] | 367 | void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 368 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) |
| 369 | { |
| 370 | struct lpfc_register doorbell; |
| 371 | |
| 372 | doorbell.word0 = 0; |
James Smart | aad59d5 | 2018-09-10 10:30:47 -0700 | [diff] [blame] | 373 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 374 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 375 | } |
| 376 | |
| 377 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 378 | * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 379 | * @phba: adapter with EQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 380 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 381 | * @count: Number of elements that have been consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 382 | * @arm: Indicates whether the host wants to arms this CQ. |
| 383 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 384 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 385 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 386 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 387 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 388 | void |
| 389 | lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 390 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 391 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 392 | struct lpfc_register doorbell; |
| 393 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 394 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 395 | if (unlikely(!q || (count == 0 && !arm))) |
| 396 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 397 | |
| 398 | /* ring doorbell for number popped */ |
| 399 | doorbell.word0 = 0; |
| 400 | if (arm) { |
| 401 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 402 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 403 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 404 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 405 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 406 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 407 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 408 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 409 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 410 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 411 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 412 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 416 | * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 417 | * @phba: adapter with EQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 418 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 419 | * @count: Number of elements that have been consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 420 | * @arm: Indicates whether the host wants to arms this CQ. |
| 421 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 422 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 423 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 424 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 425 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 426 | void |
| 427 | lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 428 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 429 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 430 | struct lpfc_register doorbell; |
| 431 | |
| 432 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 433 | if (unlikely(!q || (count == 0 && !arm))) |
| 434 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 435 | |
| 436 | /* ring doorbell for number popped */ |
| 437 | doorbell.word0 = 0; |
| 438 | if (arm) |
| 439 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 440 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 441 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
| 442 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 443 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 444 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 445 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | static void |
| 449 | __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 450 | struct lpfc_eqe *eqe) |
| 451 | { |
| 452 | if (!phba->sli4_hba.pc_sli4_params.eqav) |
| 453 | bf_set_le32(lpfc_eqe_valid, eqe, 0); |
| 454 | |
| 455 | eq->host_index = ((eq->host_index + 1) % eq->entry_count); |
| 456 | |
| 457 | /* if the index wrapped around, toggle the valid bit */ |
| 458 | if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index) |
| 459 | eq->qe_valid = (eq->qe_valid) ? 0 : 1; |
| 460 | } |
| 461 | |
| 462 | static void |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 463 | lpfc_sli4_eqcq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 464 | { |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 465 | struct lpfc_eqe *eqe = NULL; |
| 466 | u32 eq_count = 0, cq_count = 0; |
| 467 | struct lpfc_cqe *cqe = NULL; |
| 468 | struct lpfc_queue *cq = NULL, *childq = NULL; |
| 469 | int cqid = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 470 | |
| 471 | /* walk all the EQ entries and drop on the floor */ |
| 472 | eqe = lpfc_sli4_eq_get(eq); |
| 473 | while (eqe) { |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 474 | /* Get the reference to the corresponding CQ */ |
| 475 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 476 | cq = NULL; |
| 477 | |
| 478 | list_for_each_entry(childq, &eq->child_list, list) { |
| 479 | if (childq->queue_id == cqid) { |
| 480 | cq = childq; |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | /* If CQ is valid, iterate through it and drop all the CQEs */ |
| 485 | if (cq) { |
| 486 | cqe = lpfc_sli4_cq_get(cq); |
| 487 | while (cqe) { |
| 488 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 489 | cq_count++; |
| 490 | cqe = lpfc_sli4_cq_get(cq); |
| 491 | } |
| 492 | /* Clear and re-arm the CQ */ |
| 493 | phba->sli4_hba.sli4_write_cq_db(phba, cq, cq_count, |
| 494 | LPFC_QUEUE_REARM); |
| 495 | cq_count = 0; |
| 496 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 497 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 498 | eq_count++; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 499 | eqe = lpfc_sli4_eq_get(eq); |
| 500 | } |
| 501 | |
| 502 | /* Clear and re-arm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 503 | phba->sli4_hba.sli4_write_eq_db(phba, eq, eq_count, LPFC_QUEUE_REARM); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static int |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 507 | lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 508 | uint8_t rearm) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 509 | { |
| 510 | struct lpfc_eqe *eqe; |
| 511 | int count = 0, consumed = 0; |
| 512 | |
| 513 | if (cmpxchg(&eq->queue_claimed, 0, 1) != 0) |
| 514 | goto rearm_and_exit; |
| 515 | |
| 516 | eqe = lpfc_sli4_eq_get(eq); |
| 517 | while (eqe) { |
| 518 | lpfc_sli4_hba_handle_eqe(phba, eq, eqe); |
| 519 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
| 520 | |
| 521 | consumed++; |
| 522 | if (!(++count % eq->max_proc_limit)) |
| 523 | break; |
| 524 | |
| 525 | if (!(count % eq->notify_interval)) { |
| 526 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, |
| 527 | LPFC_QUEUE_NOARM); |
| 528 | consumed = 0; |
| 529 | } |
| 530 | |
| 531 | eqe = lpfc_sli4_eq_get(eq); |
| 532 | } |
| 533 | eq->EQ_processed += count; |
| 534 | |
| 535 | /* Track the max number of EQEs processed in 1 intr */ |
| 536 | if (count > eq->EQ_max_eqe) |
| 537 | eq->EQ_max_eqe = count; |
| 538 | |
Dick Kennedy | 164ba8d | 2020-05-01 14:43:03 -0700 | [diff] [blame] | 539 | xchg(&eq->queue_claimed, 0); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 540 | |
| 541 | rearm_and_exit: |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 542 | /* Always clear the EQ. */ |
| 543 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, rearm); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 544 | |
| 545 | return count; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 549 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 550 | * @q: The Completion Queue to get the first valid CQE from |
| 551 | * |
| 552 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 553 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 554 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 555 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 556 | **/ |
| 557 | static struct lpfc_cqe * |
| 558 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 559 | { |
| 560 | struct lpfc_cqe *cqe; |
| 561 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 562 | /* sanity check on queue memory */ |
| 563 | if (unlikely(!q)) |
| 564 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 565 | cqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 566 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 567 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 568 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 569 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 570 | |
| 571 | /* |
| 572 | * insert barrier for instruction interlock : data from the hardware |
| 573 | * 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] | 574 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 575 | * instructions allowing action on content before valid bit checked, |
| 576 | * add barrier here as well. May not be needed as "content" is a |
| 577 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 578 | */ |
| 579 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 580 | return cqe; |
| 581 | } |
| 582 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 583 | static void |
| 584 | __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 585 | struct lpfc_cqe *cqe) |
| 586 | { |
| 587 | if (!phba->sli4_hba.pc_sli4_params.cqav) |
| 588 | bf_set_le32(lpfc_cqe_valid, cqe, 0); |
| 589 | |
| 590 | cq->host_index = ((cq->host_index + 1) % cq->entry_count); |
| 591 | |
| 592 | /* if the index wrapped around, toggle the valid bit */ |
| 593 | if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index) |
| 594 | cq->qe_valid = (cq->qe_valid) ? 0 : 1; |
| 595 | } |
| 596 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 597 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 598 | * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state. |
| 599 | * @phba: the adapter with the CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 600 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 601 | * @count: the number of elements that were consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 602 | * @arm: Indicates whether the host wants to arms this CQ. |
| 603 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 604 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 605 | * CQEs have been processed. The @arm parameter specifies whether the |
| 606 | * queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 607 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 608 | void |
| 609 | lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 610 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 611 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 612 | struct lpfc_register doorbell; |
| 613 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 614 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 615 | if (unlikely(!q || (count == 0 && !arm))) |
| 616 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 617 | |
| 618 | /* ring doorbell for number popped */ |
| 619 | doorbell.word0 = 0; |
| 620 | if (arm) |
| 621 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 622 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 623 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 624 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 625 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 626 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 627 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 631 | * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state. |
| 632 | * @phba: the adapter with the CQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 633 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 634 | * @count: the number of elements that were consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 635 | * @arm: Indicates whether the host wants to arms this CQ. |
| 636 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 637 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 638 | * CQEs have been processed. The @arm parameter specifies whether the |
| 639 | * queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 640 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 641 | void |
| 642 | lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 643 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 644 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 645 | struct lpfc_register doorbell; |
| 646 | |
| 647 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 648 | if (unlikely(!q || (count == 0 && !arm))) |
| 649 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 650 | |
| 651 | /* ring doorbell for number popped */ |
| 652 | doorbell.word0 = 0; |
| 653 | if (arm) |
| 654 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 655 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 656 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 657 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 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; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 687 | temp_hrqe = lpfc_sli4_qe(hq, hq_put_index); |
| 688 | temp_drqe = lpfc_sli4_qe(dq, dq_put_index); |
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 | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 706 | if (!(hq->host_index % hq->notify_interval)) { |
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, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 710 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 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, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 714 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 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); |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 927 | if (!rrq->send_rrq) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 928 | /* this call will free the rrq */ |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 929 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 930 | } else if (lpfc_send_rrq(phba, rrq)) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 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 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1014 | * This function returns: |
| 1015 | * 0 = rrq not active for this xri |
| 1016 | * 1 = rrq is valid for this xri. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 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 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1022 | if (!ndlp) |
| 1023 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1024 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1025 | return 0; |
| 1026 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
Colin Ian King | 258f84f | 2019-02-12 15:29:45 +0000 | [diff] [blame] | 1027 | return 1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1028 | else |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1034 | * @phba: Pointer to HBA context object. |
| 1035 | * @ndlp: nodelist pointer for this target. |
| 1036 | * @xritag: xri used in this exchange. |
| 1037 | * @rxid: Remote Exchange ID. |
| 1038 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1039 | * |
| 1040 | * This function takes the hbalock. |
| 1041 | * The active bit is always set in the active rrq xri_bitmap even |
| 1042 | * if there is no slot avaiable for the other rrq information. |
| 1043 | * |
| 1044 | * returns 0 rrq actived for this xri |
| 1045 | * < 0 No memory or invalid ndlp. |
| 1046 | **/ |
| 1047 | int |
| 1048 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1049 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1050 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1051 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1052 | struct lpfc_node_rrq *rrq; |
| 1053 | int empty; |
| 1054 | |
| 1055 | if (!ndlp) |
| 1056 | return -EINVAL; |
| 1057 | |
| 1058 | if (!phba->cfg_enable_rrq) |
| 1059 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1060 | |
| 1061 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1062 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1063 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1064 | goto out; |
| 1065 | } |
| 1066 | |
| 1067 | /* |
| 1068 | * set the active bit even if there is no mem available. |
| 1069 | */ |
| 1070 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 1071 | goto out; |
| 1072 | |
| 1073 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1074 | goto out; |
| 1075 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1076 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1077 | goto out; |
| 1078 | |
| 1079 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1080 | goto out; |
| 1081 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1082 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
Dick Kennedy | 9dace1f | 2020-06-30 14:49:53 -0700 | [diff] [blame] | 1083 | rrq = mempool_alloc(phba->rrq_pool, GFP_ATOMIC); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1084 | if (!rrq) { |
| 1085 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1086 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1087 | " DID:0x%x Send:%d\n", |
| 1088 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1089 | return -EINVAL; |
| 1090 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1091 | if (phba->cfg_enable_rrq == 1) |
| 1092 | rrq->send_rrq = send_rrq; |
| 1093 | else |
| 1094 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1095 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1096 | rrq->rrq_stop_time = jiffies + |
| 1097 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1098 | rrq->ndlp = ndlp; |
| 1099 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1100 | rrq->vport = ndlp->vport; |
| 1101 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1102 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1103 | empty = list_empty(&phba->active_rrq_list); |
| 1104 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1105 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1106 | if (empty) |
| 1107 | lpfc_worker_wake_up(phba); |
| 1108 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1109 | return 0; |
| 1110 | out: |
| 1111 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1112 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1113 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1114 | " DID:0x%x Send:%d\n", |
| 1115 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1116 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1120 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1121 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1122 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1123 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1124 | * The driver calls this function with either the nvme ls ring lock |
| 1125 | * or the fc els ring lock held depending on the iocb usage. This function |
| 1126 | * gets a new driver sglq object from the sglq list. If the list is not empty |
| 1127 | * then it is successful, it returns pointer to the newly allocated sglq |
| 1128 | * object else it returns NULL. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 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; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1138 | struct lpfc_sli_ring *pring = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1139 | int found = 0; |
| 1140 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1141 | if (piocbq->iocb_flag & LPFC_IO_NVME_LS) |
| 1142 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 1143 | else |
| 1144 | pring = lpfc_phba_elsring(phba); |
| 1145 | |
| 1146 | lockdep_assert_held(&pring->ring_lock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1147 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1148 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1149 | lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1150 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1151 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1152 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1153 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1154 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1155 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1156 | ndlp = NULL; |
| 1157 | else |
| 1158 | ndlp = piocbq->context_un.ndlp; |
| 1159 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1160 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1161 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1162 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1163 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1164 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1165 | start_sglq = sglq; |
| 1166 | while (!found) { |
| 1167 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1168 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1169 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1170 | test_bit(sglq->sli4_lxritag, |
| 1171 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1172 | /* This xri has an rrq outstanding for this DID. |
| 1173 | * put it back in the list and get another xri. |
| 1174 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1175 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1176 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1177 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1178 | struct lpfc_sglq, list); |
| 1179 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1180 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1181 | sglq = NULL; |
| 1182 | break; |
| 1183 | } else |
| 1184 | continue; |
| 1185 | } |
| 1186 | sglq->ndlp = ndlp; |
| 1187 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1188 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1189 | sglq->state = SGL_ALLOCATED; |
| 1190 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1191 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1192 | return sglq; |
| 1193 | } |
| 1194 | |
| 1195 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1196 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1197 | * @phba: Pointer to HBA context object. |
| 1198 | * @piocb: Pointer to the iocbq. |
| 1199 | * |
| 1200 | * This function is called with the sgl_list lock held. This function |
| 1201 | * gets a new driver sglq object from the sglq list. If the |
| 1202 | * list is not empty then it is successful, it returns pointer to the newly |
| 1203 | * allocated sglq object else it returns NULL. |
| 1204 | **/ |
| 1205 | struct lpfc_sglq * |
| 1206 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1207 | { |
| 1208 | struct list_head *lpfc_nvmet_sgl_list; |
| 1209 | struct lpfc_sglq *sglq = NULL; |
| 1210 | |
| 1211 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1212 | |
| 1213 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1214 | |
| 1215 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1216 | if (!sglq) |
| 1217 | return NULL; |
| 1218 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1219 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | return sglq; |
| 1221 | } |
| 1222 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1223 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1224 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1225 | * @phba: Pointer to HBA context object. |
| 1226 | * |
| 1227 | * This function is called with no lock held. This function |
| 1228 | * allocates a new driver iocb object from the iocb pool. If the |
| 1229 | * allocation is successful, it returns pointer to the newly |
| 1230 | * allocated iocb object else it returns NULL. |
| 1231 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1232 | struct lpfc_iocbq * |
| 1233 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1234 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1235 | struct lpfc_iocbq * iocbq = NULL; |
| 1236 | unsigned long iflags; |
| 1237 | |
| 1238 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1239 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1240 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1241 | return iocbq; |
| 1242 | } |
| 1243 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1244 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1245 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1246 | * @phba: Pointer to HBA context object. |
| 1247 | * @iocbq: Pointer to driver iocb object. |
| 1248 | * |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1249 | * This function is called to release the driver iocb object |
| 1250 | * to the iocb pool. The iotag in the iocb object |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1251 | * does not change for each use of the iocb object. This function |
| 1252 | * clears all other fields of the iocb object when it is freed. |
| 1253 | * The sqlq structure that holds the xritag and phys and virtual |
| 1254 | * mappings for the scatter gather list is retrieved from the |
| 1255 | * active array of sglq. The get of the sglq pointer also clears |
| 1256 | * the entry in the array. If the status of the IO indiactes that |
| 1257 | * this IO was aborted then the sglq entry it put on the |
| 1258 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1259 | * IO has good status or fails for any other reason then the sglq |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1260 | * entry is added to the free list (lpfc_els_sgl_list). The hbalock is |
| 1261 | * asserted held in the code path calling this routine. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1262 | **/ |
| 1263 | static void |
| 1264 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1265 | { |
| 1266 | struct lpfc_sglq *sglq; |
| 1267 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1268 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1269 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1270 | |
| 1271 | if (iocbq->sli4_xritag == NO_XRI) |
| 1272 | sglq = NULL; |
| 1273 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1274 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1275 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1276 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1277 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1278 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1279 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1280 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1281 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1282 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1283 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1284 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1285 | spin_unlock_irqrestore( |
| 1286 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1287 | goto out; |
| 1288 | } |
| 1289 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1290 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1291 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1292 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1293 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1294 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1295 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1296 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1297 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1298 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1299 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1300 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1301 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1302 | sglq->state = SGL_FREED; |
| 1303 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1304 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1305 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1306 | spin_unlock_irqrestore( |
| 1307 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1308 | |
| 1309 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1310 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1311 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1312 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1313 | } |
| 1314 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1315 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1316 | /* |
| 1317 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1318 | */ |
| 1319 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1320 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1321 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1322 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1323 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1324 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1325 | } |
| 1326 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1327 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1328 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1329 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1330 | * @phba: Pointer to HBA context object. |
| 1331 | * @iocbq: Pointer to driver iocb object. |
| 1332 | * |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1333 | * This function is called to release the driver iocb object to the |
| 1334 | * iocb pool. The iotag in the iocb object does not change for each |
| 1335 | * use of the iocb object. This function clears all other fields of |
| 1336 | * the iocb object when it is freed. The hbalock is asserted held in |
| 1337 | * the code path calling this routine. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1338 | **/ |
| 1339 | static void |
| 1340 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1341 | { |
| 1342 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1343 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1344 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1345 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1346 | */ |
| 1347 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1348 | iocbq->sli4_xritag = NO_XRI; |
| 1349 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1350 | } |
| 1351 | |
| 1352 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1353 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1354 | * @phba: Pointer to HBA context object. |
| 1355 | * @iocbq: Pointer to driver iocb object. |
| 1356 | * |
| 1357 | * This function is called with hbalock held to release driver |
| 1358 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1359 | * does not change for each use of the iocb object. This function |
| 1360 | * clears all other fields of the iocb object when it is freed. |
| 1361 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1362 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1363 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1364 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1365 | lockdep_assert_held(&phba->hbalock); |
| 1366 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1367 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1368 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1369 | } |
| 1370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1371 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1372 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1373 | * @phba: Pointer to HBA context object. |
| 1374 | * @iocbq: Pointer to driver iocb object. |
| 1375 | * |
| 1376 | * This function is called with no lock held to release the iocb to |
| 1377 | * iocb pool. |
| 1378 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1379 | void |
| 1380 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1381 | { |
| 1382 | unsigned long iflags; |
| 1383 | |
| 1384 | /* |
| 1385 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1386 | */ |
| 1387 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1388 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1389 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1390 | } |
| 1391 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1392 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1393 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1394 | * @phba: Pointer to HBA context object. |
| 1395 | * @iocblist: List of IOCBs. |
| 1396 | * @ulpstatus: ULP status in IOCB command field. |
| 1397 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1398 | * |
| 1399 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1400 | * on the list by invoking the complete callback function associated with the |
| 1401 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1402 | * fields. |
| 1403 | **/ |
| 1404 | void |
| 1405 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1406 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1407 | { |
| 1408 | struct lpfc_iocbq *piocb; |
| 1409 | |
| 1410 | while (!list_empty(iocblist)) { |
| 1411 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | 84f2ddf | 2019-08-14 16:56:55 -0700 | [diff] [blame] | 1412 | if (!piocb->iocb_cmpl) { |
| 1413 | if (piocb->iocb_flag & LPFC_IO_NVME) |
| 1414 | lpfc_nvme_cancel_iocb(phba, piocb); |
| 1415 | else |
| 1416 | lpfc_sli_release_iocbq(phba, piocb); |
| 1417 | } else { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1418 | piocb->iocb.ulpStatus = ulpstatus; |
| 1419 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1420 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1421 | } |
| 1422 | } |
| 1423 | return; |
| 1424 | } |
| 1425 | |
| 1426 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1427 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1428 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1429 | * |
| 1430 | * This function is called by ring event handler function to get the iocb type. |
| 1431 | * This function translates the iocb command to an iocb command type used to |
| 1432 | * decide the final disposition of each completed IOCB. |
| 1433 | * The function returns |
| 1434 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1435 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1436 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1437 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1438 | * |
| 1439 | * The caller is not required to hold any lock. |
| 1440 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1441 | static lpfc_iocb_type |
| 1442 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1443 | { |
| 1444 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1445 | |
| 1446 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1447 | return 0; |
| 1448 | |
| 1449 | switch (iocb_cmnd) { |
| 1450 | case CMD_XMIT_SEQUENCE_CR: |
| 1451 | case CMD_XMIT_SEQUENCE_CX: |
| 1452 | case CMD_XMIT_BCAST_CN: |
| 1453 | case CMD_XMIT_BCAST_CX: |
| 1454 | case CMD_ELS_REQUEST_CR: |
| 1455 | case CMD_ELS_REQUEST_CX: |
| 1456 | case CMD_CREATE_XRI_CR: |
| 1457 | case CMD_CREATE_XRI_CX: |
| 1458 | case CMD_GET_RPI_CN: |
| 1459 | case CMD_XMIT_ELS_RSP_CX: |
| 1460 | case CMD_GET_RPI_CR: |
| 1461 | case CMD_FCP_IWRITE_CR: |
| 1462 | case CMD_FCP_IWRITE_CX: |
| 1463 | case CMD_FCP_IREAD_CR: |
| 1464 | case CMD_FCP_IREAD_CX: |
| 1465 | case CMD_FCP_ICMND_CR: |
| 1466 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1467 | case CMD_FCP_TSEND_CX: |
| 1468 | case CMD_FCP_TRSP_CX: |
| 1469 | case CMD_FCP_TRECEIVE_CX: |
| 1470 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | case CMD_ADAPTER_MSG: |
| 1472 | case CMD_ADAPTER_DUMP: |
| 1473 | case CMD_XMIT_SEQUENCE64_CR: |
| 1474 | case CMD_XMIT_SEQUENCE64_CX: |
| 1475 | case CMD_XMIT_BCAST64_CN: |
| 1476 | case CMD_XMIT_BCAST64_CX: |
| 1477 | case CMD_ELS_REQUEST64_CR: |
| 1478 | case CMD_ELS_REQUEST64_CX: |
| 1479 | case CMD_FCP_IWRITE64_CR: |
| 1480 | case CMD_FCP_IWRITE64_CX: |
| 1481 | case CMD_FCP_IREAD64_CR: |
| 1482 | case CMD_FCP_IREAD64_CX: |
| 1483 | case CMD_FCP_ICMND64_CR: |
| 1484 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1485 | case CMD_FCP_TSEND64_CX: |
| 1486 | case CMD_FCP_TRSP64_CX: |
| 1487 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | case CMD_GEN_REQUEST64_CR: |
| 1489 | case CMD_GEN_REQUEST64_CX: |
| 1490 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1491 | case DSSCMD_IWRITE64_CR: |
| 1492 | case DSSCMD_IWRITE64_CX: |
| 1493 | case DSSCMD_IREAD64_CR: |
| 1494 | case DSSCMD_IREAD64_CX: |
Dick Kennedy | c93764a | 2020-06-30 14:49:49 -0700 | [diff] [blame] | 1495 | case CMD_SEND_FRAME: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | type = LPFC_SOL_IOCB; |
| 1497 | break; |
| 1498 | case CMD_ABORT_XRI_CN: |
| 1499 | case CMD_ABORT_XRI_CX: |
| 1500 | case CMD_CLOSE_XRI_CN: |
| 1501 | case CMD_CLOSE_XRI_CX: |
| 1502 | case CMD_XRI_ABORTED_CX: |
| 1503 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1504 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1505 | type = LPFC_ABORT_IOCB; |
| 1506 | break; |
| 1507 | case CMD_RCV_SEQUENCE_CX: |
| 1508 | case CMD_RCV_ELS_REQ_CX: |
| 1509 | case CMD_RCV_SEQUENCE64_CX: |
| 1510 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1511 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1512 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1513 | case CMD_IOCB_RCV_ELS64_CX: |
| 1514 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1515 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1516 | type = LPFC_UNSOL_IOCB; |
| 1517 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1518 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1519 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1520 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1521 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1522 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1523 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1524 | case CMD_IOCB_RET_HBQE64_CN: |
| 1525 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1526 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1527 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1528 | case CMD_IOCB_LOGENTRY_CN: |
| 1529 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1530 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1531 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1532 | type = LPFC_UNKNOWN_IOCB; |
| 1533 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | default: |
| 1535 | type = LPFC_UNKNOWN_IOCB; |
| 1536 | break; |
| 1537 | } |
| 1538 | |
| 1539 | return type; |
| 1540 | } |
| 1541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1543 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1544 | * @phba: Pointer to HBA context object. |
| 1545 | * |
| 1546 | * This function is called from SLI initialization code |
| 1547 | * to configure every ring of the HBA's SLI interface. The |
| 1548 | * caller is not required to hold any lock. This function issues |
| 1549 | * a config_ring mailbox command for each ring. |
| 1550 | * This function returns zero if successful else returns a negative |
| 1551 | * error code. |
| 1552 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1554 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1555 | { |
| 1556 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1557 | LPFC_MBOXQ_t *pmb; |
| 1558 | MAILBOX_t *pmbox; |
| 1559 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1561 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1562 | if (!pmb) |
| 1563 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1564 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1565 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1566 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1567 | lpfc_config_ring(phba, i, pmb); |
| 1568 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1569 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1570 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1571 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1572 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1573 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1574 | rc, pmbox->mbxCommand, |
| 1575 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1576 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1577 | ret = -ENXIO; |
| 1578 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | } |
| 1580 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1581 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1582 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1583 | } |
| 1584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1585 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1586 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1587 | * @phba: Pointer to HBA context object. |
| 1588 | * @pring: Pointer to driver SLI ring object. |
| 1589 | * @piocb: Pointer to the driver iocb object. |
| 1590 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1591 | * The driver calls this function with the hbalock held for SLI3 ports or |
| 1592 | * the ring lock held for SLI4 ports. The function adds the |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1593 | * new iocb to txcmplq of the given ring. This function always returns |
| 1594 | * 0. If this function is called for ELS ring, this function checks if |
| 1595 | * there is a vport associated with the ELS command. This function also |
| 1596 | * starts els_tmofunc timer if this is an ELS command. |
| 1597 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1598 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1599 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1600 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | { |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1602 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1603 | lockdep_assert_held(&pring->ring_lock); |
| 1604 | else |
| 1605 | lockdep_assert_held(&phba->hbalock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1606 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1607 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1608 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1609 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1610 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1611 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1612 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1613 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1614 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1615 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1616 | BUG_ON(!piocb->vport); |
| 1617 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1618 | mod_timer(&piocb->vport->els_tmofunc, |
| 1619 | jiffies + |
| 1620 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1621 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1622 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1623 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1624 | } |
| 1625 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1626 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1627 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1628 | * @phba: Pointer to HBA context object. |
| 1629 | * @pring: Pointer to driver SLI ring object. |
| 1630 | * |
| 1631 | * This function is called with hbalock held to get next |
| 1632 | * iocb in txq of the given ring. If there is any iocb in |
| 1633 | * the txq, the function returns first iocb in the list after |
| 1634 | * removing the iocb from the list, else it returns NULL. |
| 1635 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1636 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1637 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1638 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | struct lpfc_iocbq *cmd_iocb; |
| 1640 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1641 | lockdep_assert_held(&phba->hbalock); |
| 1642 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1643 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1644 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1645 | } |
| 1646 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1647 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1648 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1649 | * @phba: Pointer to HBA context object. |
| 1650 | * @pring: Pointer to driver SLI ring object. |
| 1651 | * |
| 1652 | * This function is called with hbalock held and the caller must post the |
| 1653 | * iocb without releasing the lock. If the caller releases the lock, |
| 1654 | * iocb slot returned by the function is not guaranteed to be available. |
| 1655 | * The function returns pointer to the next available iocb slot if there |
| 1656 | * is available slot in the ring, else it returns NULL. |
| 1657 | * If the get index of the ring is ahead of the put index, the function |
| 1658 | * will post an error attention event to the worker thread to take the |
| 1659 | * HBA to offline state. |
| 1660 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1661 | static IOCB_t * |
| 1662 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1663 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1664 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1665 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1666 | |
| 1667 | lockdep_assert_held(&phba->hbalock); |
| 1668 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1669 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1670 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1671 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1673 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1674 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1675 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1676 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1677 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1678 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1679 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1680 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1681 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1682 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1683 | pring->sli.sli3.local_getidx, |
| 1684 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1685 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1686 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | /* |
| 1688 | * All error attention handlers are posted to |
| 1689 | * worker thread |
| 1690 | */ |
| 1691 | phba->work_ha |= HA_ERATT; |
| 1692 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1693 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1694 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1695 | |
| 1696 | return NULL; |
| 1697 | } |
| 1698 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1699 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1700 | return NULL; |
| 1701 | } |
| 1702 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1703 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1704 | } |
| 1705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1707 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1708 | * @phba: Pointer to HBA context object. |
| 1709 | * @iocbq: Pointer to driver iocb object. |
| 1710 | * |
| 1711 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1712 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1713 | * array and assigns a new iotag. |
| 1714 | * The function returns the allocated iotag if successful, else returns zero. |
| 1715 | * Zero is not a valid iotag. |
| 1716 | * The caller is not required to hold any lock. |
| 1717 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1718 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1719 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1720 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1721 | struct lpfc_iocbq **new_arr; |
| 1722 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1723 | size_t new_len; |
| 1724 | struct lpfc_sli *psli = &phba->sli; |
| 1725 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1726 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1727 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1728 | iotag = psli->last_iotag; |
| 1729 | if(++iotag < psli->iocbq_lookup_len) { |
| 1730 | psli->last_iotag = iotag; |
| 1731 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1733 | iocbq->iotag = iotag; |
| 1734 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1735 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1736 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1737 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1739 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1740 | GFP_KERNEL); |
| 1741 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1742 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1743 | old_arr = psli->iocbq_lookup; |
| 1744 | if (new_len <= psli->iocbq_lookup_len) { |
| 1745 | /* highly unprobable case */ |
| 1746 | kfree(new_arr); |
| 1747 | iotag = psli->last_iotag; |
| 1748 | if(++iotag < psli->iocbq_lookup_len) { |
| 1749 | psli->last_iotag = iotag; |
| 1750 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1751 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1752 | iocbq->iotag = iotag; |
| 1753 | return iotag; |
| 1754 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1755 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1756 | return 0; |
| 1757 | } |
| 1758 | if (psli->iocbq_lookup) |
| 1759 | memcpy(new_arr, old_arr, |
| 1760 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1761 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1762 | psli->iocbq_lookup = new_arr; |
| 1763 | psli->iocbq_lookup_len = new_len; |
| 1764 | psli->last_iotag = iotag; |
| 1765 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1766 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1767 | iocbq->iotag = iotag; |
| 1768 | kfree(old_arr); |
| 1769 | return iotag; |
| 1770 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1771 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1772 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1773 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1774 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1775 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1776 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1778 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1779 | } |
| 1780 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1781 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1782 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1783 | * @phba: Pointer to HBA context object. |
| 1784 | * @pring: Pointer to driver SLI ring object. |
| 1785 | * @iocb: Pointer to iocb slot in the ring. |
| 1786 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1787 | * posted to firmware. |
| 1788 | * |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1789 | * This function is called to post a new iocb to the firmware. This |
| 1790 | * function copies the new iocb to ring iocb slot and updates the |
| 1791 | * ring pointers. It adds the new iocb to txcmplq if there is |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1792 | * a completion call back for this iocb else the function will free the |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1793 | * iocb object. The hbalock is asserted held in the code path calling |
| 1794 | * this routine. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1795 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | static void |
| 1797 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1798 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1799 | { |
| 1800 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1801 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1803 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1805 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1806 | if (pring->ringno == LPFC_ELS_RING) { |
| 1807 | lpfc_debugfs_slow_ring_trc(phba, |
| 1808 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1809 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1810 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1811 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1812 | } |
| 1813 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1814 | /* |
| 1815 | * Issue iocb command to adapter |
| 1816 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1817 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | wmb(); |
| 1819 | pring->stats.iocb_cmd++; |
| 1820 | |
| 1821 | /* |
| 1822 | * If there is no completion routine to call, we can release the |
| 1823 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1824 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1825 | */ |
| 1826 | if (nextiocb->iocb_cmpl) |
| 1827 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1828 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1829 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | |
| 1831 | /* |
| 1832 | * Let the HBA know what IOCB slot will be the next one the |
| 1833 | * driver will put a command into. |
| 1834 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1835 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1836 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1837 | } |
| 1838 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1839 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1840 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1841 | * @phba: Pointer to HBA context object. |
| 1842 | * @pring: Pointer to driver SLI ring object. |
| 1843 | * |
| 1844 | * The caller is not required to hold any lock for calling this function. |
| 1845 | * This function updates the chip attention bits for the ring to inform firmware |
| 1846 | * that there are pending work to be done for this ring and requests an |
| 1847 | * interrupt when there is space available in the ring. This function is |
| 1848 | * called when the driver is unable to post more iocbs to the ring due |
| 1849 | * to unavailability of space in the ring. |
| 1850 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1852 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1853 | { |
| 1854 | int ringno = pring->ringno; |
| 1855 | |
| 1856 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1857 | |
| 1858 | wmb(); |
| 1859 | |
| 1860 | /* |
| 1861 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1862 | * The HBA will tell us when an IOCB entry is available. |
| 1863 | */ |
| 1864 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1865 | readl(phba->CAregaddr); /* flush */ |
| 1866 | |
| 1867 | pring->stats.iocb_cmd_full++; |
| 1868 | } |
| 1869 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1870 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1871 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1872 | * @phba: Pointer to HBA context object. |
| 1873 | * @pring: Pointer to driver SLI ring object. |
| 1874 | * |
| 1875 | * This function updates the chip attention register bit for the |
| 1876 | * given ring to inform HBA that there is more work to be done |
| 1877 | * in this ring. The caller is not required to hold any lock. |
| 1878 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1880 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 | { |
| 1882 | int ringno = pring->ringno; |
| 1883 | |
| 1884 | /* |
| 1885 | * Tell the HBA that there is work to do in this ring. |
| 1886 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1887 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1888 | wmb(); |
| 1889 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1890 | readl(phba->CAregaddr); /* flush */ |
| 1891 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | } |
| 1893 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1894 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1895 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1896 | * @phba: Pointer to HBA context object. |
| 1897 | * @pring: Pointer to driver SLI ring object. |
| 1898 | * |
| 1899 | * This function is called with hbalock held to post pending iocbs |
| 1900 | * in the txq to the firmware. This function is called when driver |
| 1901 | * detects space available in the ring. |
| 1902 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1903 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1904 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | { |
| 1906 | IOCB_t *iocb; |
| 1907 | struct lpfc_iocbq *nextiocb; |
| 1908 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1909 | lockdep_assert_held(&phba->hbalock); |
| 1910 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | /* |
| 1912 | * Check to see if: |
| 1913 | * (a) there is anything on the txq to send |
| 1914 | * (b) link is up |
| 1915 | * (c) link attention events can be processed (fcp ring only) |
| 1916 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1917 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1918 | |
| 1919 | if (lpfc_is_link_up(phba) && |
| 1920 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1921 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1922 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | |
| 1924 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1925 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1926 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1927 | |
| 1928 | if (iocb) |
| 1929 | lpfc_sli_update_ring(phba, pring); |
| 1930 | else |
| 1931 | lpfc_sli_update_full_ring(phba, pring); |
| 1932 | } |
| 1933 | |
| 1934 | return; |
| 1935 | } |
| 1936 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1937 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1938 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1939 | * @phba: Pointer to HBA context object. |
| 1940 | * @hbqno: HBQ number. |
| 1941 | * |
| 1942 | * This function is called with hbalock held to get the next |
| 1943 | * available slot for the given HBQ. If there is free slot |
| 1944 | * available for the HBQ it will return pointer to the next available |
| 1945 | * HBQ entry else it will return NULL. |
| 1946 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1947 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1948 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1949 | { |
| 1950 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1951 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1952 | lockdep_assert_held(&phba->hbalock); |
| 1953 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1954 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1955 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1956 | hbqp->next_hbqPutIdx = 0; |
| 1957 | |
| 1958 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1959 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1960 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1961 | |
| 1962 | hbqp->local_hbqGetIdx = getidx; |
| 1963 | |
| 1964 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1965 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1966 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1967 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1968 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1969 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1970 | hbqp->entry_count); |
| 1971 | |
| 1972 | phba->link_state = LPFC_HBA_ERROR; |
| 1973 | return NULL; |
| 1974 | } |
| 1975 | |
| 1976 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1977 | return NULL; |
| 1978 | } |
| 1979 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1980 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1981 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1982 | } |
| 1983 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1984 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1985 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1986 | * @phba: Pointer to HBA context object. |
| 1987 | * |
| 1988 | * This function is called with no lock held to free all the |
| 1989 | * hbq buffers while uninitializing the SLI interface. It also |
| 1990 | * frees the HBQ buffers returned by the firmware but not yet |
| 1991 | * processed by the upper layers. |
| 1992 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1993 | void |
| 1994 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1995 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1996 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1997 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1998 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1999 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2000 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2001 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2002 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2003 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2004 | for (i = 0; i < hbq_count; ++i) { |
| 2005 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 2006 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 2007 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 2008 | list_del(&hbq_buf->dbuf.list); |
| 2009 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 2010 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2011 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2012 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2013 | |
| 2014 | /* Mark the HBQs not in use */ |
| 2015 | phba->hbq_in_use = 0; |
| 2016 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2017 | } |
| 2018 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2019 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2020 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2021 | * @phba: Pointer to HBA context object. |
| 2022 | * @hbqno: HBQ number. |
| 2023 | * @hbq_buf: Pointer to HBQ buffer. |
| 2024 | * |
| 2025 | * This function is called with the hbalock held to post a |
| 2026 | * hbq buffer to the firmware. If the function finds an empty |
| 2027 | * slot in the HBQ, it will post the buffer. The function will return |
| 2028 | * pointer to the hbq entry if it successfully post the buffer |
| 2029 | * else it will return NULL. |
| 2030 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2031 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2032 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2033 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2034 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2035 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2036 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2037 | } |
| 2038 | |
| 2039 | /** |
| 2040 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2041 | * @phba: Pointer to HBA context object. |
| 2042 | * @hbqno: HBQ number. |
| 2043 | * @hbq_buf: Pointer to HBQ buffer. |
| 2044 | * |
| 2045 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2046 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2047 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2048 | * it successfully post the buffer else it will return an error. |
| 2049 | **/ |
| 2050 | static int |
| 2051 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2052 | struct hbq_dmabuf *hbq_buf) |
| 2053 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2054 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2055 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2056 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2057 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2058 | /* Get next HBQ entry slot to use */ |
| 2059 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2060 | if (hbqe) { |
| 2061 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2062 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2063 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2064 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2065 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2066 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2067 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2068 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2069 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2070 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2071 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2072 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2073 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2074 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2075 | return 0; |
| 2076 | } else |
| 2077 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2078 | } |
| 2079 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2080 | /** |
| 2081 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2082 | * @phba: Pointer to HBA context object. |
| 2083 | * @hbqno: HBQ number. |
| 2084 | * @hbq_buf: Pointer to HBQ buffer. |
| 2085 | * |
| 2086 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2087 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2088 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2089 | **/ |
| 2090 | static int |
| 2091 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2092 | struct hbq_dmabuf *hbq_buf) |
| 2093 | { |
| 2094 | int rc; |
| 2095 | struct lpfc_rqe hrqe; |
| 2096 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2097 | struct lpfc_queue *hrq; |
| 2098 | struct lpfc_queue *drq; |
| 2099 | |
| 2100 | if (hbqno != LPFC_ELS_HBQ) |
| 2101 | return 1; |
| 2102 | hrq = phba->sli4_hba.hdr_rq; |
| 2103 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2104 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2105 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2106 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2107 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2108 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2109 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2110 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2111 | if (rc < 0) |
| 2112 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2113 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2114 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2115 | return 0; |
| 2116 | } |
| 2117 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2118 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2119 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2120 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2121 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2122 | .mask_count = 0, |
| 2123 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2124 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2125 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2126 | .init_count = 40, |
| 2127 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2128 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2129 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2130 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2131 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2132 | &lpfc_els_hbq, |
| 2133 | }; |
| 2134 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2135 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2136 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2137 | * @phba: Pointer to HBA context object. |
| 2138 | * @hbqno: HBQ number. |
| 2139 | * @count: Number of HBQ buffers to be posted. |
| 2140 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2141 | * This function is called with no lock held to post more hbq buffers to the |
| 2142 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2143 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2144 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2145 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2146 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2147 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2148 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2149 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2150 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2151 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2152 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2153 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2154 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2155 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2156 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2157 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2158 | phba->hbqs[hbqno].buffer_count; |
| 2159 | if (!count) |
| 2160 | return 0; |
| 2161 | /* Allocate HBQ entries */ |
| 2162 | for (i = 0; i < count; i++) { |
| 2163 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2164 | if (!hbq_buffer) |
| 2165 | break; |
| 2166 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2167 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2168 | /* Check whether HBQ is still in use */ |
| 2169 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2170 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2171 | goto err; |
| 2172 | while (!list_empty(&hbq_buf_list)) { |
| 2173 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2174 | dbuf.list); |
| 2175 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2176 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2177 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2178 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2179 | posted++; |
| 2180 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2181 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2182 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2183 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2184 | return posted; |
| 2185 | err: |
| 2186 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2187 | while (!list_empty(&hbq_buf_list)) { |
| 2188 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2189 | dbuf.list); |
| 2190 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2191 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2192 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2193 | } |
| 2194 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2195 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2196 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2197 | * @phba: Pointer to HBA context object. |
| 2198 | * @qno: HBQ number. |
| 2199 | * |
| 2200 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2201 | * is called with no lock held. The function returns the number of HBQ entries |
| 2202 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2203 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2204 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2205 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2206 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2207 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2208 | return 0; |
| 2209 | else |
| 2210 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2211 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2212 | } |
| 2213 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2214 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2215 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2216 | * @phba: Pointer to HBA context object. |
| 2217 | * @qno: HBQ queue number. |
| 2218 | * |
| 2219 | * This function is called from SLI initialization code path with |
| 2220 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2221 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2222 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2223 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2224 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2225 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2226 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2227 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2228 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2229 | else |
| 2230 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2231 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2232 | } |
| 2233 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2234 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2235 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2236 | * @phba: Pointer to HBA context object. |
| 2237 | * @hbqno: HBQ number. |
| 2238 | * |
| 2239 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2240 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2241 | **/ |
| 2242 | static struct hbq_dmabuf * |
| 2243 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2244 | { |
| 2245 | struct lpfc_dmabuf *d_buf; |
| 2246 | |
| 2247 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2248 | if (!d_buf) |
| 2249 | return NULL; |
| 2250 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2251 | } |
| 2252 | |
| 2253 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2254 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2255 | * @phba: Pointer to HBA context object. |
| 2256 | * @hbqno: HBQ number. |
| 2257 | * |
| 2258 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2259 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2260 | **/ |
| 2261 | static struct rqb_dmabuf * |
| 2262 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2263 | { |
| 2264 | struct lpfc_dmabuf *h_buf; |
| 2265 | struct lpfc_rqb *rqbp; |
| 2266 | |
| 2267 | rqbp = hrq->rqbp; |
| 2268 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2269 | struct lpfc_dmabuf, list); |
| 2270 | if (!h_buf) |
| 2271 | return NULL; |
| 2272 | rqbp->buffer_count--; |
| 2273 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2274 | } |
| 2275 | |
| 2276 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2277 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2278 | * @phba: Pointer to HBA context object. |
| 2279 | * @tag: Tag of the hbq buffer. |
| 2280 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2281 | * This function searches for the hbq buffer associated with the given tag in |
| 2282 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2283 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2284 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2285 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2286 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2287 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2288 | struct lpfc_dmabuf *d_buf; |
| 2289 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2290 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2291 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2292 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2293 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2294 | return NULL; |
| 2295 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2296 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2297 | 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] | 2298 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2299 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2300 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2301 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2302 | } |
| 2303 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2304 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2305 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2306 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2307 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2308 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2309 | } |
| 2310 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2311 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2312 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2313 | * @phba: Pointer to HBA context object. |
| 2314 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2315 | * |
| 2316 | * This function is called with hbalock. This function gives back |
| 2317 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2318 | * post the buffer, it will free the buffer. |
| 2319 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2320 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2321 | 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] | 2322 | { |
| 2323 | uint32_t hbqno; |
| 2324 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2325 | if (hbq_buffer) { |
| 2326 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2327 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2328 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2329 | } |
| 2330 | } |
| 2331 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2332 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2333 | * 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] | 2334 | * @mbxCommand: mailbox command code. |
| 2335 | * |
| 2336 | * This function is called by the mailbox event handler function to verify |
| 2337 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2338 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2339 | * and the mailbox event handler will take the HBA offline. |
| 2340 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | static int |
| 2342 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2343 | { |
| 2344 | uint8_t ret; |
| 2345 | |
| 2346 | switch (mbxCommand) { |
| 2347 | case MBX_LOAD_SM: |
| 2348 | case MBX_READ_NV: |
| 2349 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2350 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | case MBX_RUN_BIU_DIAG: |
| 2352 | case MBX_INIT_LINK: |
| 2353 | case MBX_DOWN_LINK: |
| 2354 | case MBX_CONFIG_LINK: |
| 2355 | case MBX_CONFIG_RING: |
| 2356 | case MBX_RESET_RING: |
| 2357 | case MBX_READ_CONFIG: |
| 2358 | case MBX_READ_RCONFIG: |
| 2359 | case MBX_READ_SPARM: |
| 2360 | case MBX_READ_STATUS: |
| 2361 | case MBX_READ_RPI: |
| 2362 | case MBX_READ_XRI: |
| 2363 | case MBX_READ_REV: |
| 2364 | case MBX_READ_LNK_STAT: |
| 2365 | case MBX_REG_LOGIN: |
| 2366 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | case MBX_CLEAR_LA: |
| 2368 | case MBX_DUMP_MEMORY: |
| 2369 | case MBX_DUMP_CONTEXT: |
| 2370 | case MBX_RUN_DIAGS: |
| 2371 | case MBX_RESTART: |
| 2372 | case MBX_UPDATE_CFG: |
| 2373 | case MBX_DOWN_LOAD: |
| 2374 | case MBX_DEL_LD_ENTRY: |
| 2375 | case MBX_RUN_PROGRAM: |
| 2376 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2377 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2379 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2380 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2381 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | case MBX_LOAD_AREA: |
| 2383 | case MBX_RUN_BIU_DIAG64: |
| 2384 | case MBX_CONFIG_PORT: |
| 2385 | case MBX_READ_SPARM64: |
| 2386 | case MBX_READ_RPI64: |
| 2387 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2388 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2389 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2390 | case MBX_SET_DEBUG: |
| 2391 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2392 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2393 | case MBX_REG_VPI: |
| 2394 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2395 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2396 | case MBX_PORT_CAPABILITIES: |
| 2397 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2398 | case MBX_SLI4_CONFIG: |
| 2399 | case MBX_SLI4_REQ_FTRS: |
| 2400 | case MBX_REG_FCFI: |
| 2401 | case MBX_UNREG_FCFI: |
| 2402 | case MBX_REG_VFI: |
| 2403 | case MBX_UNREG_VFI: |
| 2404 | case MBX_INIT_VPI: |
| 2405 | case MBX_INIT_VFI: |
| 2406 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2407 | case MBX_READ_EVENT_LOG_STATUS: |
| 2408 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2409 | case MBX_SECURITY_MGMT: |
| 2410 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2411 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2412 | ret = mbxCommand; |
| 2413 | break; |
| 2414 | default: |
| 2415 | ret = MBX_SHUTDOWN; |
| 2416 | break; |
| 2417 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2418 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2420 | |
| 2421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2422 | * 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] | 2423 | * @phba: Pointer to HBA context object. |
| 2424 | * @pmboxq: Pointer to mailbox command. |
| 2425 | * |
| 2426 | * This is completion handler function for mailbox commands issued from |
| 2427 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2428 | * mailbox event handler function with no lock held. This function |
| 2429 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2430 | * of the mailbox. |
| 2431 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2432 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2433 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2434 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2435 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2436 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | |
| 2438 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2439 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | * continued running. |
| 2441 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2442 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2443 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2444 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2445 | if (pmbox_done) |
| 2446 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2447 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | return; |
| 2449 | } |
| 2450 | |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2451 | static void |
| 2452 | __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 2453 | { |
| 2454 | unsigned long iflags; |
| 2455 | |
| 2456 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 2457 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
| 2458 | spin_lock_irqsave(&vport->phba->ndlp_lock, iflags); |
| 2459 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
| 2460 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
| 2461 | spin_unlock_irqrestore(&vport->phba->ndlp_lock, iflags); |
| 2462 | } |
| 2463 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 2464 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2465 | |
| 2466 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2467 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2468 | * @phba: Pointer to HBA context object. |
| 2469 | * @pmb: Pointer to mailbox object. |
| 2470 | * |
| 2471 | * This function is the default mailbox completion handler. It |
| 2472 | * frees the memory resources associated with the completed mailbox |
| 2473 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2474 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2475 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2476 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2477 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2478 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2479 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2480 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2481 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2482 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2483 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2484 | int rc; |
| 2485 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2486 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2487 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | if (mp) { |
| 2489 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2490 | kfree(mp); |
| 2491 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2492 | |
| 2493 | /* |
| 2494 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2495 | * is in re-discovery driver need to cleanup the RPI. |
| 2496 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2497 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2498 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2499 | !pmb->u.mb.mbxStatus) { |
| 2500 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2501 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 3850394 | 2020-03-22 11:12:53 -0700 | [diff] [blame] | 2502 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2503 | vpi -= phba->sli4_hba.max_cfg_param.vpi_base; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2504 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2505 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2506 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2507 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2508 | if (rc != MBX_NOT_FINISHED) |
| 2509 | return; |
| 2510 | } |
| 2511 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2512 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2513 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2514 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2515 | shost = lpfc_shost_from_vport(vport); |
| 2516 | spin_lock_irq(shost->host_lock); |
| 2517 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2518 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2519 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2520 | } |
| 2521 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2522 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2523 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2524 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2525 | pmb->ctx_buf = NULL; |
| 2526 | pmb->ctx_ndlp = NULL; |
| 2527 | } |
| 2528 | |
| 2529 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2530 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2531 | |
| 2532 | /* Check to see if there are any deferred events to process */ |
| 2533 | if (ndlp) { |
| 2534 | lpfc_printf_vlog( |
| 2535 | vport, |
| 2536 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2537 | "1438 UNREG cmpl deferred mbox x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2538 | "on NPort x%x Data: x%x x%x %px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2539 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2540 | ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp); |
| 2541 | |
| 2542 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2543 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2544 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2545 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2546 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2547 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2548 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2549 | } |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 2550 | if (vport->load_flag & FC_UNLOADING) |
| 2551 | lpfc_nlp_put(ndlp); |
James Smart | 9b16406 | 2019-03-12 16:30:06 -0700 | [diff] [blame] | 2552 | pmb->ctx_ndlp = NULL; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2553 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2554 | } |
| 2555 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2556 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2557 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2558 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2559 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2560 | "2860 SLI authentication is required " |
| 2561 | "for INIT_LINK but has not done yet\n"); |
| 2562 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2563 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2564 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2565 | else |
| 2566 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2567 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2568 | /** |
| 2569 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2570 | * @phba: Pointer to HBA context object. |
| 2571 | * @pmb: Pointer to mailbox object. |
| 2572 | * |
| 2573 | * This function is the unreg rpi mailbox completion handler. It |
| 2574 | * frees the memory resources associated with the completed mailbox |
| 2575 | * command. An additional refrenece is put on the ndlp to prevent |
| 2576 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2577 | * the unreg mailbox command completes, this routine puts the |
| 2578 | * reference back. |
| 2579 | * |
| 2580 | **/ |
| 2581 | void |
| 2582 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2583 | { |
| 2584 | struct lpfc_vport *vport = pmb->vport; |
| 2585 | struct lpfc_nodelist *ndlp; |
| 2586 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2587 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2588 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2589 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2590 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2591 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2592 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2593 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2594 | lpfc_printf_vlog( |
| 2595 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 2596 | "0010 UNREG_LOGIN vpi:%x " |
| 2597 | "rpi:%x DID:%x defer x%x flg x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2598 | "map:%x %px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2599 | vport->vpi, ndlp->nlp_rpi, |
| 2600 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2601 | ndlp->nlp_flag, |
| 2602 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2603 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2604 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2605 | |
| 2606 | /* Check to see if there are any deferred |
| 2607 | * events to process |
| 2608 | */ |
| 2609 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2610 | (ndlp->nlp_defer_did != |
| 2611 | NLP_EVT_NOTHING_PENDING)) { |
| 2612 | lpfc_printf_vlog( |
| 2613 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2614 | "4111 UNREG cmpl deferred " |
| 2615 | "clr x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2616 | "NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2617 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2618 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2619 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2620 | ndlp->nlp_defer_did = |
| 2621 | NLP_EVT_NOTHING_PENDING; |
| 2622 | lpfc_issue_els_plogi( |
| 2623 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2624 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2625 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2626 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2632 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2634 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2635 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2636 | * @phba: Pointer to HBA context object. |
| 2637 | * |
| 2638 | * This function is called with no lock held. This function processes all |
| 2639 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2640 | * service routine processes mailbox completion interrupt and adds completed |
| 2641 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2642 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2643 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2644 | * function returns the mailbox commands to the upper layer by calling the |
| 2645 | * completion handler function of each mailbox. |
| 2646 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2647 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2648 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2650 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2652 | int rc; |
| 2653 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2654 | |
| 2655 | phba->sli.slistat.mbox_event++; |
| 2656 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2657 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2658 | spin_lock_irq(&phba->hbalock); |
| 2659 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2660 | spin_unlock_irq(&phba->hbalock); |
| 2661 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2663 | do { |
| 2664 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2665 | if (pmb == NULL) |
| 2666 | break; |
| 2667 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2668 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2670 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2671 | if (pmb->vport) { |
| 2672 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2673 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2674 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2675 | (uint32_t)pmbox->mbxCommand, |
| 2676 | pmbox->un.varWords[0], |
| 2677 | pmbox->un.varWords[1]); |
| 2678 | } |
| 2679 | else { |
| 2680 | lpfc_debugfs_disc_trc(phba->pport, |
| 2681 | LPFC_DISC_TRC_MBOX, |
| 2682 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2683 | (uint32_t)pmbox->mbxCommand, |
| 2684 | pmbox->un.varWords[0], |
| 2685 | pmbox->un.varWords[1]); |
| 2686 | } |
| 2687 | } |
| 2688 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | /* |
| 2690 | * It is a fatal error if unknown mbox command completion. |
| 2691 | */ |
| 2692 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2693 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2694 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2695 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2696 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2697 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2698 | pmb->vport ? pmb->vport->vpi : |
| 2699 | LPFC_VPORT_UNKNOWN, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2700 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2701 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2702 | pmb), |
| 2703 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2704 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2705 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2706 | phba->work_hs = HS_FFER3; |
| 2707 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2708 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | } |
| 2710 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | if (pmbox->mbxStatus) { |
| 2712 | phba->sli.slistat.mbox_stat_err++; |
| 2713 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2714 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2715 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2716 | LOG_MBOX | LOG_SLI, |
| 2717 | "(%d):0305 Mbox cmd cmpl " |
| 2718 | "error - RETRYing Data: x%x " |
| 2719 | "(x%x/x%x) x%x x%x x%x\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2720 | pmb->vport ? pmb->vport->vpi : |
| 2721 | LPFC_VPORT_UNKNOWN, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2722 | pmbox->mbxCommand, |
| 2723 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2724 | pmb), |
| 2725 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2726 | pmb), |
| 2727 | pmbox->mbxStatus, |
| 2728 | pmbox->un.varWords[0], |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2729 | pmb->vport ? pmb->vport->port_state : |
| 2730 | LPFC_VPORT_UNKNOWN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2731 | pmbox->mbxStatus = 0; |
| 2732 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2734 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2735 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2740 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 2741 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2742 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2743 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2744 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2746 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2747 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | pmb->mbox_cmpl, |
| 2749 | *((uint32_t *) pmbox), |
| 2750 | pmbox->un.varWords[0], |
| 2751 | pmbox->un.varWords[1], |
| 2752 | pmbox->un.varWords[2], |
| 2753 | pmbox->un.varWords[3], |
| 2754 | pmbox->un.varWords[4], |
| 2755 | pmbox->un.varWords[5], |
| 2756 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2757 | pmbox->un.varWords[7], |
| 2758 | pmbox->un.varWords[8], |
| 2759 | pmbox->un.varWords[9], |
| 2760 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2761 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2762 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2764 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2765 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2767 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2768 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2769 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2770 | * @phba: Pointer to HBA context object. |
| 2771 | * @pring: Pointer to driver SLI ring object. |
| 2772 | * @tag: buffer tag. |
| 2773 | * |
| 2774 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2775 | * is set in the tag the buffer is posted for a particular exchange, |
| 2776 | * the function will return the buffer without replacing the buffer. |
| 2777 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2778 | * returns the buffer and also posts another buffer to the firmware. |
| 2779 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2780 | static struct lpfc_dmabuf * |
| 2781 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2782 | struct lpfc_sli_ring *pring, |
| 2783 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2784 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2785 | struct hbq_dmabuf *hbq_entry; |
| 2786 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2787 | if (tag & QUE_BUFTAG_BIT) |
| 2788 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2789 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2790 | if (!hbq_entry) |
| 2791 | return NULL; |
| 2792 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2793 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2794 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2795 | /** |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2796 | * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer |
| 2797 | * containing a NVME LS request. |
| 2798 | * @phba: pointer to lpfc hba data structure. |
| 2799 | * @piocb: pointer to the iocbq struct representing the sequence starting |
| 2800 | * frame. |
| 2801 | * |
| 2802 | * This routine initially validates the NVME LS, validates there is a login |
| 2803 | * with the port that sent the LS, and then calls the appropriate nvme host |
| 2804 | * or target LS request handler. |
| 2805 | **/ |
| 2806 | static void |
| 2807 | lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
| 2808 | { |
| 2809 | struct lpfc_nodelist *ndlp; |
| 2810 | struct lpfc_dmabuf *d_buf; |
| 2811 | struct hbq_dmabuf *nvmebuf; |
| 2812 | struct fc_frame_header *fc_hdr; |
| 2813 | struct lpfc_async_xchg_ctx *axchg = NULL; |
| 2814 | char *failwhy = NULL; |
| 2815 | uint32_t oxid, sid, did, fctl, size; |
James Smart | 4e57e0b | 2020-05-20 11:59:28 -0700 | [diff] [blame] | 2816 | int ret = 1; |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2817 | |
| 2818 | d_buf = piocb->context2; |
| 2819 | |
| 2820 | nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2821 | fc_hdr = nvmebuf->hbuf.virt; |
| 2822 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
| 2823 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 2824 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 2825 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 2826 | fc_hdr->fh_f_ctl[1] << 8 | |
| 2827 | fc_hdr->fh_f_ctl[2]); |
| 2828 | size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl); |
| 2829 | |
| 2830 | lpfc_nvmeio_data(phba, "NVME LS RCV: xri x%x sz %d from %06x\n", |
| 2831 | oxid, size, sid); |
| 2832 | |
| 2833 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 2834 | failwhy = "Driver Unloading"; |
| 2835 | } else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { |
| 2836 | failwhy = "NVME FC4 Disabled"; |
| 2837 | } else if (!phba->nvmet_support && !phba->pport->localport) { |
| 2838 | failwhy = "No Localport"; |
| 2839 | } else if (phba->nvmet_support && !phba->targetport) { |
| 2840 | failwhy = "No Targetport"; |
| 2841 | } else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) { |
| 2842 | failwhy = "Bad NVME LS R_CTL"; |
| 2843 | } else if (unlikely((fctl & 0x00FF0000) != |
| 2844 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) { |
| 2845 | failwhy = "Bad NVME LS F_CTL"; |
| 2846 | } else { |
| 2847 | axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC); |
| 2848 | if (!axchg) |
| 2849 | failwhy = "No CTX memory"; |
| 2850 | } |
| 2851 | |
| 2852 | if (unlikely(failwhy)) { |
| 2853 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC | LOG_NVME_IOERR, |
| 2854 | "6154 Drop NVME LS: SID %06X OXID x%X: %s\n", |
| 2855 | sid, oxid, failwhy); |
| 2856 | goto out_fail; |
| 2857 | } |
| 2858 | |
| 2859 | /* validate the source of the LS is logged in */ |
| 2860 | ndlp = lpfc_findnode_did(phba->pport, sid); |
| 2861 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 2862 | ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 2863 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { |
| 2864 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, |
| 2865 | "6216 NVME Unsol rcv: No ndlp: " |
| 2866 | "NPort_ID x%x oxid x%x\n", |
| 2867 | sid, oxid); |
| 2868 | goto out_fail; |
| 2869 | } |
| 2870 | |
| 2871 | axchg->phba = phba; |
| 2872 | axchg->ndlp = ndlp; |
| 2873 | axchg->size = size; |
| 2874 | axchg->oxid = oxid; |
| 2875 | axchg->sid = sid; |
| 2876 | axchg->wqeq = NULL; |
| 2877 | axchg->state = LPFC_NVME_STE_LS_RCV; |
| 2878 | axchg->entry_cnt = 1; |
| 2879 | axchg->rqb_buffer = (void *)nvmebuf; |
| 2880 | axchg->hdwq = &phba->sli4_hba.hdwq[0]; |
| 2881 | axchg->payload = nvmebuf->dbuf.virt; |
| 2882 | INIT_LIST_HEAD(&axchg->list); |
| 2883 | |
| 2884 | if (phba->nvmet_support) |
| 2885 | ret = lpfc_nvmet_handle_lsreq(phba, axchg); |
| 2886 | else |
| 2887 | ret = lpfc_nvme_handle_lsreq(phba, axchg); |
| 2888 | |
| 2889 | /* if zero, LS was successfully handled. If non-zero, LS not handled */ |
| 2890 | if (!ret) |
| 2891 | return; |
| 2892 | |
| 2893 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC | LOG_NVME_IOERR, |
| 2894 | "6155 Drop NVME LS from DID %06X: SID %06X OXID x%X " |
| 2895 | "NVMe%s handler failed %d\n", |
| 2896 | did, sid, oxid, |
| 2897 | (phba->nvmet_support) ? "T" : "I", ret); |
| 2898 | |
| 2899 | out_fail: |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2900 | |
| 2901 | /* recycle receive buffer */ |
| 2902 | lpfc_in_buf_free(phba, &nvmebuf->dbuf); |
| 2903 | |
| 2904 | /* If start of new exchange, abort it */ |
James Smart | 4e57e0b | 2020-05-20 11:59:28 -0700 | [diff] [blame] | 2905 | if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX))) |
| 2906 | ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid); |
| 2907 | |
| 2908 | if (ret) |
| 2909 | kfree(axchg); |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2913 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2914 | * @phba: Pointer to HBA context object. |
| 2915 | * @pring: Pointer to driver SLI ring object. |
| 2916 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2917 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2918 | * @fch_type: the type for the first frame of the sequence. |
| 2919 | * |
| 2920 | * This function is called with no lock held. This function uses the r_ctl and |
| 2921 | * type of the received sequence to find the correct callback function to call |
| 2922 | * to process the sequence. |
| 2923 | **/ |
| 2924 | static int |
| 2925 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2926 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2927 | uint32_t fch_type) |
| 2928 | { |
| 2929 | int i; |
| 2930 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2931 | switch (fch_type) { |
| 2932 | case FC_TYPE_NVME: |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2933 | lpfc_nvme_unsol_ls_handler(phba, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2934 | return 1; |
| 2935 | default: |
| 2936 | break; |
| 2937 | } |
| 2938 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2939 | /* unSolicited Responses */ |
| 2940 | if (pring->prt[0].profile) { |
| 2941 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2942 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2943 | saveq); |
| 2944 | return 1; |
| 2945 | } |
| 2946 | /* We must search, based on rctl / type |
| 2947 | for the right routine */ |
| 2948 | for (i = 0; i < pring->num_mask; i++) { |
| 2949 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2950 | (pring->prt[i].type == fch_type)) { |
| 2951 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2952 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2953 | (phba, pring, saveq); |
| 2954 | return 1; |
| 2955 | } |
| 2956 | } |
| 2957 | return 0; |
| 2958 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2959 | |
| 2960 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2961 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2962 | * @phba: Pointer to HBA context object. |
| 2963 | * @pring: Pointer to driver SLI ring object. |
| 2964 | * @saveq: Pointer to the unsolicited iocb. |
| 2965 | * |
| 2966 | * This function is called with no lock held by the ring event handler |
| 2967 | * when there is an unsolicited iocb posted to the response ring by the |
| 2968 | * firmware. This function gets the buffer associated with the iocbs |
| 2969 | * and calls the event handler for the ring. This function handles both |
| 2970 | * qring buffers and hbq buffers. |
| 2971 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2972 | * upper layer functions will free the iocb objects. |
| 2973 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2974 | static int |
| 2975 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2976 | struct lpfc_iocbq *saveq) |
| 2977 | { |
| 2978 | IOCB_t * irsp; |
| 2979 | WORD5 * w5p; |
| 2980 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2981 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2982 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2985 | |
| 2986 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2987 | if (pring->lpfc_sli_rcv_async_status) |
| 2988 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2989 | else |
| 2990 | lpfc_printf_log(phba, |
| 2991 | KERN_WARNING, |
| 2992 | LOG_SLI, |
| 2993 | "0316 Ring %d handler: unexpected " |
| 2994 | "ASYNC_STATUS iocb received evt_code " |
| 2995 | "0x%x\n", |
| 2996 | pring->ringno, |
| 2997 | irsp->un.asyncstat.evt_code); |
| 2998 | return 1; |
| 2999 | } |
| 3000 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3001 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 3002 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 3003 | if (irsp->ulpBdeCount > 0) { |
| 3004 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3005 | irsp->un.ulpWord[3]); |
| 3006 | lpfc_in_buf_free(phba, dmzbuf); |
| 3007 | } |
| 3008 | |
| 3009 | if (irsp->ulpBdeCount > 1) { |
| 3010 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3011 | irsp->unsli3.sli3Words[3]); |
| 3012 | lpfc_in_buf_free(phba, dmzbuf); |
| 3013 | } |
| 3014 | |
| 3015 | if (irsp->ulpBdeCount > 2) { |
| 3016 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3017 | irsp->unsli3.sli3Words[7]); |
| 3018 | lpfc_in_buf_free(phba, dmzbuf); |
| 3019 | } |
| 3020 | |
| 3021 | return 1; |
| 3022 | } |
| 3023 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3024 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3025 | if (irsp->ulpBdeCount != 0) { |
| 3026 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3027 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3028 | if (!saveq->context2) |
| 3029 | lpfc_printf_log(phba, |
| 3030 | KERN_ERR, |
| 3031 | LOG_SLI, |
| 3032 | "0341 Ring %d Cannot find buffer for " |
| 3033 | "an unsolicited iocb. tag 0x%x\n", |
| 3034 | pring->ringno, |
| 3035 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3036 | } |
| 3037 | if (irsp->ulpBdeCount == 2) { |
| 3038 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3039 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3040 | if (!saveq->context3) |
| 3041 | lpfc_printf_log(phba, |
| 3042 | KERN_ERR, |
| 3043 | LOG_SLI, |
| 3044 | "0342 Ring %d Cannot find buffer for an" |
| 3045 | " unsolicited iocb. tag 0x%x\n", |
| 3046 | pring->ringno, |
| 3047 | irsp->unsli3.sli3Words[7]); |
| 3048 | } |
| 3049 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3050 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3051 | if (irsp->ulpBdeCount != 0) { |
| 3052 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 3053 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3054 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3055 | lpfc_printf_log(phba, |
| 3056 | KERN_ERR, |
| 3057 | LOG_SLI, |
| 3058 | "0343 Ring %d Cannot find " |
| 3059 | "buffer for an unsolicited iocb" |
| 3060 | ". tag 0x%x\n", pring->ringno, |
| 3061 | irsp->un.ulpWord[3]); |
| 3062 | } |
| 3063 | if (irsp->ulpBdeCount == 2) { |
| 3064 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 3065 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3066 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3067 | lpfc_printf_log(phba, |
| 3068 | KERN_ERR, |
| 3069 | LOG_SLI, |
| 3070 | "0344 Ring %d Cannot find " |
| 3071 | "buffer for an unsolicited " |
| 3072 | "iocb. tag 0x%x\n", |
| 3073 | pring->ringno, |
| 3074 | irsp->unsli3.sli3Words[7]); |
| 3075 | } |
| 3076 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3077 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3078 | if (irsp->ulpBdeCount != 0 && |
| 3079 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 3080 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 3081 | int found = 0; |
| 3082 | |
| 3083 | /* search continue save q for same XRI */ |
| 3084 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3085 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 3086 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3087 | list_add_tail(&saveq->list, &iocbq->list); |
| 3088 | found = 1; |
| 3089 | break; |
| 3090 | } |
| 3091 | } |
| 3092 | if (!found) |
| 3093 | list_add_tail(&saveq->clist, |
| 3094 | &pring->iocb_continue_saveq); |
| 3095 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 3096 | list_del_init(&iocbq->clist); |
| 3097 | saveq = iocbq; |
| 3098 | irsp = &(saveq->iocb); |
| 3099 | } else |
| 3100 | return 0; |
| 3101 | } |
| 3102 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 3103 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 3104 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3105 | Rctl = FC_RCTL_ELS_REQ; |
| 3106 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3107 | } else { |
| 3108 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 3109 | Rctl = w5p->hcsw.Rctl; |
| 3110 | Type = w5p->hcsw.Type; |
| 3111 | |
| 3112 | /* Firmware Workaround */ |
| 3113 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 3114 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 3115 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3116 | Rctl = FC_RCTL_ELS_REQ; |
| 3117 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3118 | w5p->hcsw.Rctl = Rctl; |
| 3119 | w5p->hcsw.Type = Type; |
| 3120 | } |
| 3121 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3122 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3123 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3124 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3125 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3126 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3127 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3128 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3129 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | } |
| 3131 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3132 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3133 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3134 | * @phba: Pointer to HBA context object. |
| 3135 | * @pring: Pointer to driver SLI ring object. |
| 3136 | * @prspiocb: Pointer to response iocb object. |
| 3137 | * |
| 3138 | * This function looks up the iocb_lookup table to get the command iocb |
| 3139 | * corresponding to the given response iocb using the iotag of the |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3140 | * response iocb. The driver calls this function with the hbalock held |
| 3141 | * for SLI3 ports or the ring lock held for SLI4 ports. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3142 | * This function returns the command iocb object if it finds the command |
| 3143 | * iocb else returns NULL. |
| 3144 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3145 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3146 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 3147 | struct lpfc_sli_ring *pring, |
| 3148 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3149 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3150 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 3151 | uint16_t iotag; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3152 | spinlock_t *temp_lock = NULL; |
| 3153 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3155 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3156 | temp_lock = &pring->ring_lock; |
| 3157 | else |
| 3158 | temp_lock = &phba->hbalock; |
| 3159 | |
| 3160 | spin_lock_irqsave(temp_lock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3161 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3163 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3164 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3165 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3166 | /* remove from txcmpl queue list */ |
| 3167 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3168 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3169 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3170 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3171 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3172 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3173 | } |
| 3174 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3175 | spin_unlock_irqrestore(temp_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3176 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3177 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3178 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3179 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3180 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3181 | return NULL; |
| 3182 | } |
| 3183 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3184 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3185 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3186 | * @phba: Pointer to HBA context object. |
| 3187 | * @pring: Pointer to driver SLI ring object. |
| 3188 | * @iotag: IOCB tag. |
| 3189 | * |
| 3190 | * This function looks up the iocb_lookup table to get the command iocb |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3191 | * corresponding to the given iotag. The driver calls this function with |
| 3192 | * the ring lock held because this function is an SLI4 port only helper. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3193 | * This function returns the command iocb object if it finds the command |
| 3194 | * iocb else returns NULL. |
| 3195 | **/ |
| 3196 | static struct lpfc_iocbq * |
| 3197 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3198 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3199 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3200 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3201 | spinlock_t *temp_lock = NULL; |
| 3202 | unsigned long iflag = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3203 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3204 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3205 | temp_lock = &pring->ring_lock; |
| 3206 | else |
| 3207 | temp_lock = &phba->hbalock; |
| 3208 | |
| 3209 | spin_lock_irqsave(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3210 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3211 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3212 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3213 | /* remove from txcmpl queue list */ |
| 3214 | list_del_init(&cmd_iocb->list); |
| 3215 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3216 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3217 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3218 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3219 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3220 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3221 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3222 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3223 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3224 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3225 | "iocb_flag x%x\n", |
| 3226 | iotag, phba->sli.last_iotag, |
| 3227 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3228 | return NULL; |
| 3229 | } |
| 3230 | |
| 3231 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3232 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3233 | * @phba: Pointer to HBA context object. |
| 3234 | * @pring: Pointer to driver SLI ring object. |
| 3235 | * @saveq: Pointer to the response iocb to be processed. |
| 3236 | * |
| 3237 | * This function is called by the ring event handler for non-fcp |
| 3238 | * rings when there is a new response iocb in the response ring. |
| 3239 | * The caller is not required to hold any locks. This function |
| 3240 | * gets the command iocb associated with the response iocb and |
| 3241 | * calls the completion handler for the command iocb. If there |
| 3242 | * is no completion handler, the function will free the resources |
| 3243 | * associated with command iocb. If the response iocb is for |
| 3244 | * an already aborted command iocb, the status of the completion |
| 3245 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3246 | * This function always returns 1. |
| 3247 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3249 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3250 | struct lpfc_iocbq *saveq) |
| 3251 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3252 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3253 | int rc = 1; |
| 3254 | unsigned long iflag; |
| 3255 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3256 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | if (cmdiocbp) { |
| 3258 | if (cmdiocbp->iocb_cmpl) { |
| 3259 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3260 | * If an ELS command failed send an event to mgmt |
| 3261 | * application. |
| 3262 | */ |
| 3263 | if (saveq->iocb.ulpStatus && |
| 3264 | (pring->ringno == LPFC_ELS_RING) && |
| 3265 | (cmdiocbp->iocb.ulpCommand == |
| 3266 | CMD_ELS_REQUEST64_CR)) |
| 3267 | lpfc_send_els_failure_event(phba, |
| 3268 | cmdiocbp, saveq); |
| 3269 | |
| 3270 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3271 | * Post all ELS completions to the worker thread. |
| 3272 | * All other are passed to the completion callback. |
| 3273 | */ |
| 3274 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3275 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3276 | (cmdiocbp->iocb_flag & |
| 3277 | LPFC_DRIVER_ABORTED)) { |
| 3278 | spin_lock_irqsave(&phba->hbalock, |
| 3279 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3280 | cmdiocbp->iocb_flag &= |
| 3281 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3282 | spin_unlock_irqrestore(&phba->hbalock, |
| 3283 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3284 | saveq->iocb.ulpStatus = |
| 3285 | IOSTAT_LOCAL_REJECT; |
| 3286 | saveq->iocb.un.ulpWord[4] = |
| 3287 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3288 | |
| 3289 | /* Firmware could still be in progress |
| 3290 | * of DMAing payload, so don't free data |
| 3291 | * buffer till after a hbeat. |
| 3292 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3293 | spin_lock_irqsave(&phba->hbalock, |
| 3294 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3295 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3296 | spin_unlock_irqrestore(&phba->hbalock, |
| 3297 | iflag); |
| 3298 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3299 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3300 | if (saveq->iocb_flag & |
| 3301 | LPFC_EXCHANGE_BUSY) { |
| 3302 | /* Set cmdiocb flag for the |
| 3303 | * exchange busy so sgl (xri) |
| 3304 | * will not be released until |
| 3305 | * the abort xri is received |
| 3306 | * from hba. |
| 3307 | */ |
| 3308 | spin_lock_irqsave( |
| 3309 | &phba->hbalock, iflag); |
| 3310 | cmdiocbp->iocb_flag |= |
| 3311 | LPFC_EXCHANGE_BUSY; |
| 3312 | spin_unlock_irqrestore( |
| 3313 | &phba->hbalock, iflag); |
| 3314 | } |
| 3315 | if (cmdiocbp->iocb_flag & |
| 3316 | LPFC_DRIVER_ABORTED) { |
| 3317 | /* |
| 3318 | * Clear LPFC_DRIVER_ABORTED |
| 3319 | * bit in case it was driver |
| 3320 | * initiated abort. |
| 3321 | */ |
| 3322 | spin_lock_irqsave( |
| 3323 | &phba->hbalock, iflag); |
| 3324 | cmdiocbp->iocb_flag &= |
| 3325 | ~LPFC_DRIVER_ABORTED; |
| 3326 | spin_unlock_irqrestore( |
| 3327 | &phba->hbalock, iflag); |
| 3328 | cmdiocbp->iocb.ulpStatus = |
| 3329 | IOSTAT_LOCAL_REJECT; |
| 3330 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3331 | IOERR_ABORT_REQUESTED; |
| 3332 | /* |
| 3333 | * For SLI4, irsiocb contains |
| 3334 | * NO_XRI in sli_xritag, it |
| 3335 | * shall not affect releasing |
| 3336 | * sgl (xri) process. |
| 3337 | */ |
| 3338 | saveq->iocb.ulpStatus = |
| 3339 | IOSTAT_LOCAL_REJECT; |
| 3340 | saveq->iocb.un.ulpWord[4] = |
| 3341 | IOERR_SLI_ABORTED; |
| 3342 | spin_lock_irqsave( |
| 3343 | &phba->hbalock, iflag); |
| 3344 | saveq->iocb_flag |= |
| 3345 | LPFC_DELAY_MEM_FREE; |
| 3346 | spin_unlock_irqrestore( |
| 3347 | &phba->hbalock, iflag); |
| 3348 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3349 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3350 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3351 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3352 | } else |
| 3353 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | } else { |
| 3355 | /* |
| 3356 | * Unknown initiating command based on the response iotag. |
| 3357 | * This could be the case on the ELS ring because of |
| 3358 | * lpfc_els_abort(). |
| 3359 | */ |
| 3360 | if (pring->ringno != LPFC_ELS_RING) { |
| 3361 | /* |
| 3362 | * Ring <ringno> handler: unexpected completion IoTag |
| 3363 | * <IoTag> |
| 3364 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3365 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3366 | "0322 Ring %d handler: " |
| 3367 | "unexpected completion IoTag x%x " |
| 3368 | "Data: x%x x%x x%x x%x\n", |
| 3369 | pring->ringno, |
| 3370 | saveq->iocb.ulpIoTag, |
| 3371 | saveq->iocb.ulpStatus, |
| 3372 | saveq->iocb.un.ulpWord[4], |
| 3373 | saveq->iocb.ulpCommand, |
| 3374 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3375 | } |
| 3376 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3377 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3378 | return rc; |
| 3379 | } |
| 3380 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3381 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3382 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3383 | * @phba: Pointer to HBA context object. |
| 3384 | * @pring: Pointer to driver SLI ring object. |
| 3385 | * |
| 3386 | * This function is called from the iocb ring event handlers when |
| 3387 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3388 | * an error attention condition to the worker thread and the worker |
| 3389 | * thread will transition the HBA to offline state. |
| 3390 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3391 | static void |
| 3392 | 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] | 3393 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3394 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3395 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3396 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3397 | * rsp ring <portRspMax> |
| 3398 | */ |
| 3399 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3400 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3401 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3402 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3403 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3404 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3405 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3406 | |
| 3407 | /* |
| 3408 | * All error attention handlers are posted to |
| 3409 | * worker thread |
| 3410 | */ |
| 3411 | phba->work_ha |= HA_ERATT; |
| 3412 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3413 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3414 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3415 | |
| 3416 | return; |
| 3417 | } |
| 3418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3420 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3421 | * @ptr: Pointer to address of HBA context object. |
| 3422 | * |
| 3423 | * This function is invoked by the Error Attention polling timer when the |
| 3424 | * timer times out. It will check the SLI Error Attention register for |
| 3425 | * possible attention events. If so, it will post an Error Attention event |
| 3426 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3427 | * Error Attention polling timer for the next poll. |
| 3428 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3429 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3430 | { |
| 3431 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3432 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3433 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3434 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3435 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3436 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3437 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3438 | sli_intr = phba->sli.slistat.sli_intr; |
| 3439 | |
| 3440 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3441 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3442 | sli_intr); |
| 3443 | else |
| 3444 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3445 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3446 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3447 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3448 | phba->sli.slistat.sli_ips = cnt; |
| 3449 | |
| 3450 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3451 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3452 | /* Check chip HA register for error event */ |
| 3453 | eratt = lpfc_sli_check_eratt(phba); |
| 3454 | |
| 3455 | if (eratt) |
| 3456 | /* Tell the worker thread there is work to do */ |
| 3457 | lpfc_worker_wake_up(phba); |
| 3458 | else |
| 3459 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3460 | mod_timer(&phba->eratt_poll, |
| 3461 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3462 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3463 | return; |
| 3464 | } |
| 3465 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3466 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3467 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3468 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3469 | * @phba: Pointer to HBA context object. |
| 3470 | * @pring: Pointer to driver SLI ring object. |
| 3471 | * @mask: Host attention register mask for this ring. |
| 3472 | * |
| 3473 | * This function is called from the interrupt context when there is a ring |
| 3474 | * event for the fcp ring. The caller does not hold any lock. |
| 3475 | * 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] | 3476 | * 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] | 3477 | * LE bit set. The function will call the completion handler of the command iocb |
| 3478 | * if the response iocb indicates a completion for a command iocb or it is |
| 3479 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3480 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3482 | * to check it explicitly. |
| 3483 | */ |
| 3484 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3485 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3486 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3487 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3488 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3490 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3491 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3492 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | uint32_t status; |
| 3494 | uint32_t portRspPut, portRspMax; |
| 3495 | int rc = 1; |
| 3496 | lpfc_iocb_type type; |
| 3497 | unsigned long iflag; |
| 3498 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3500 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3501 | pring->stats.iocb_event++; |
| 3502 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | /* |
| 3504 | * The next available response entry should never exceed the maximum |
| 3505 | * entries. If it does, treat it as an adapter hardware error. |
| 3506 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3507 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3508 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3509 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3510 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | return 1; |
| 3513 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3514 | if (phba->fcp_ring_in_use) { |
| 3515 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3516 | return 1; |
| 3517 | } else |
| 3518 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3519 | |
| 3520 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3521 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3522 | /* |
| 3523 | * Fetch an entry off the ring and copy it into a local data |
| 3524 | * structure. The copy involves a byte-swap since the |
| 3525 | * network byte order and pci byte orders are different. |
| 3526 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3527 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3528 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3529 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3530 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3531 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3532 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3533 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3534 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3535 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3536 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3537 | irsp = &rspiocbq.iocb; |
| 3538 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3540 | pring->stats.iocb_rsp++; |
| 3541 | rsp_cmpl++; |
| 3542 | |
| 3543 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3544 | /* |
| 3545 | * If resource errors reported from HBA, reduce |
| 3546 | * queuedepths of the SCSI device. |
| 3547 | */ |
| 3548 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3549 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3550 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3551 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3552 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3553 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3554 | } |
| 3555 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3556 | /* Rsp ring <ringno> error: IOCB */ |
| 3557 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3558 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3559 | "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] | 3560 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3561 | irsp->un.ulpWord[0], |
| 3562 | irsp->un.ulpWord[1], |
| 3563 | irsp->un.ulpWord[2], |
| 3564 | irsp->un.ulpWord[3], |
| 3565 | irsp->un.ulpWord[4], |
| 3566 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3567 | *(uint32_t *)&irsp->un1, |
| 3568 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | switch (type) { |
| 3572 | case LPFC_ABORT_IOCB: |
| 3573 | case LPFC_SOL_IOCB: |
| 3574 | /* |
| 3575 | * Idle exchange closed via ABTS from port. No iocb |
| 3576 | * resources need to be recovered. |
| 3577 | */ |
| 3578 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3579 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3580 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3581 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3582 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3583 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | break; |
| 3585 | } |
| 3586 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3587 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3588 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3589 | &rspiocbq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3590 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3591 | if (unlikely(!cmdiocbq)) |
| 3592 | break; |
| 3593 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3594 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3595 | if (cmdiocbq->iocb_cmpl) { |
| 3596 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3597 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3598 | &rspiocbq); |
| 3599 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3600 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3602 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3603 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3604 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3605 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3606 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3607 | default: |
| 3608 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3609 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3610 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3611 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3612 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3613 | dev_warn(&((phba->pcidev)->dev), |
| 3614 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3615 | phba->brd_no, adaptermsg); |
| 3616 | } else { |
| 3617 | /* Unknown IOCB command */ |
| 3618 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3619 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3620 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3621 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3622 | irsp->ulpStatus, |
| 3623 | irsp->ulpIoTag, |
| 3624 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | } |
| 3626 | break; |
| 3627 | } |
| 3628 | |
| 3629 | /* |
| 3630 | * The response IOCB has been processed. Update the ring |
| 3631 | * pointer in SLIM. If the port response put pointer has not |
| 3632 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3633 | * response put pointer. |
| 3634 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3635 | writel(pring->sli.sli3.rspidx, |
| 3636 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3638 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3640 | } |
| 3641 | |
| 3642 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3643 | pring->stats.iocb_rsp_full++; |
| 3644 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3645 | writel(status, phba->CAregaddr); |
| 3646 | readl(phba->CAregaddr); |
| 3647 | } |
| 3648 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3649 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3650 | pring->stats.iocb_cmd_empty++; |
| 3651 | |
| 3652 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3653 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3654 | lpfc_sli_resume_iocb(phba, pring); |
| 3655 | |
| 3656 | if ((pring->lpfc_sli_cmd_available)) |
| 3657 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3658 | |
| 3659 | } |
| 3660 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3661 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3662 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3663 | return rc; |
| 3664 | } |
| 3665 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3666 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3667 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3668 | * @phba: Pointer to HBA context object. |
| 3669 | * @pring: Pointer to driver SLI ring object. |
| 3670 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3671 | * |
| 3672 | * This function is called from the worker thread when there is a slow-path |
| 3673 | * response IOCB to process. This function chains all the response iocbs until |
| 3674 | * seeing the iocb with the LE bit set. The function will call |
| 3675 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3676 | * completion of a command iocb. The function will call the |
| 3677 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3678 | * The function frees the resources or calls the completion handler if this |
| 3679 | * iocb is an abort completion. The function returns NULL when the response |
| 3680 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3681 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3682 | * response iocb passed in. |
| 3683 | **/ |
| 3684 | static struct lpfc_iocbq * |
| 3685 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3686 | struct lpfc_iocbq *rspiocbp) |
| 3687 | { |
| 3688 | struct lpfc_iocbq *saveq; |
| 3689 | struct lpfc_iocbq *cmdiocbp; |
| 3690 | struct lpfc_iocbq *next_iocb; |
| 3691 | IOCB_t *irsp = NULL; |
| 3692 | uint32_t free_saveq; |
| 3693 | uint8_t iocb_cmd_type; |
| 3694 | lpfc_iocb_type type; |
| 3695 | unsigned long iflag; |
| 3696 | int rc; |
| 3697 | |
| 3698 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3699 | /* First add the response iocb to the countinueq list */ |
| 3700 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3701 | pring->iocb_continueq_cnt++; |
| 3702 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3703 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3704 | irsp = &rspiocbp->iocb; |
| 3705 | if (irsp->ulpLe) { |
| 3706 | /* |
| 3707 | * By default, the driver expects to free all resources |
| 3708 | * associated with this iocb completion. |
| 3709 | */ |
| 3710 | free_saveq = 1; |
| 3711 | saveq = list_get_first(&pring->iocb_continueq, |
| 3712 | struct lpfc_iocbq, list); |
| 3713 | irsp = &(saveq->iocb); |
| 3714 | list_del_init(&pring->iocb_continueq); |
| 3715 | pring->iocb_continueq_cnt = 0; |
| 3716 | |
| 3717 | pring->stats.iocb_rsp++; |
| 3718 | |
| 3719 | /* |
| 3720 | * If resource errors reported from HBA, reduce |
| 3721 | * queuedepths of the SCSI device. |
| 3722 | */ |
| 3723 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3724 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3725 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3726 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3727 | phba->lpfc_rampdown_queue_depth(phba); |
| 3728 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3729 | } |
| 3730 | |
| 3731 | if (irsp->ulpStatus) { |
| 3732 | /* Rsp ring <ringno> error: IOCB */ |
| 3733 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3734 | "0328 Rsp Ring %d error: " |
| 3735 | "IOCB Data: " |
| 3736 | "x%x x%x x%x x%x " |
| 3737 | "x%x x%x x%x x%x " |
| 3738 | "x%x x%x x%x x%x " |
| 3739 | "x%x x%x x%x x%x\n", |
| 3740 | pring->ringno, |
| 3741 | irsp->un.ulpWord[0], |
| 3742 | irsp->un.ulpWord[1], |
| 3743 | irsp->un.ulpWord[2], |
| 3744 | irsp->un.ulpWord[3], |
| 3745 | irsp->un.ulpWord[4], |
| 3746 | irsp->un.ulpWord[5], |
| 3747 | *(((uint32_t *) irsp) + 6), |
| 3748 | *(((uint32_t *) irsp) + 7), |
| 3749 | *(((uint32_t *) irsp) + 8), |
| 3750 | *(((uint32_t *) irsp) + 9), |
| 3751 | *(((uint32_t *) irsp) + 10), |
| 3752 | *(((uint32_t *) irsp) + 11), |
| 3753 | *(((uint32_t *) irsp) + 12), |
| 3754 | *(((uint32_t *) irsp) + 13), |
| 3755 | *(((uint32_t *) irsp) + 14), |
| 3756 | *(((uint32_t *) irsp) + 15)); |
| 3757 | } |
| 3758 | |
| 3759 | /* |
| 3760 | * Fetch the IOCB command type and call the correct completion |
| 3761 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3762 | * get freed back to the lpfc_iocb_list by the discovery |
| 3763 | * kernel thread. |
| 3764 | */ |
| 3765 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3766 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3767 | switch (type) { |
| 3768 | case LPFC_SOL_IOCB: |
| 3769 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3770 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3771 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3772 | break; |
| 3773 | |
| 3774 | case LPFC_UNSOL_IOCB: |
| 3775 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3776 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3777 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3778 | if (!rc) |
| 3779 | free_saveq = 0; |
| 3780 | break; |
| 3781 | |
| 3782 | case LPFC_ABORT_IOCB: |
| 3783 | cmdiocbp = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3784 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) { |
| 3785 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3786 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3787 | saveq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3788 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3789 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3790 | if (cmdiocbp) { |
| 3791 | /* Call the specified completion routine */ |
| 3792 | if (cmdiocbp->iocb_cmpl) { |
| 3793 | spin_unlock_irqrestore(&phba->hbalock, |
| 3794 | iflag); |
| 3795 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3796 | saveq); |
| 3797 | spin_lock_irqsave(&phba->hbalock, |
| 3798 | iflag); |
| 3799 | } else |
| 3800 | __lpfc_sli_release_iocbq(phba, |
| 3801 | cmdiocbp); |
| 3802 | } |
| 3803 | break; |
| 3804 | |
| 3805 | case LPFC_UNKNOWN_IOCB: |
| 3806 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3807 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3808 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3809 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3810 | MAX_MSG_DATA); |
| 3811 | dev_warn(&((phba->pcidev)->dev), |
| 3812 | "lpfc%d: %s\n", |
| 3813 | phba->brd_no, adaptermsg); |
| 3814 | } else { |
| 3815 | /* Unknown IOCB command */ |
| 3816 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3817 | "0335 Unknown IOCB " |
| 3818 | "command Data: x%x " |
| 3819 | "x%x x%x x%x\n", |
| 3820 | irsp->ulpCommand, |
| 3821 | irsp->ulpStatus, |
| 3822 | irsp->ulpIoTag, |
| 3823 | irsp->ulpContext); |
| 3824 | } |
| 3825 | break; |
| 3826 | } |
| 3827 | |
| 3828 | if (free_saveq) { |
| 3829 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3830 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3831 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3832 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3833 | } |
| 3834 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3835 | } |
| 3836 | rspiocbp = NULL; |
| 3837 | } |
| 3838 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3839 | return rspiocbp; |
| 3840 | } |
| 3841 | |
| 3842 | /** |
| 3843 | * 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] | 3844 | * @phba: Pointer to HBA context object. |
| 3845 | * @pring: Pointer to driver SLI ring object. |
| 3846 | * @mask: Host attention register mask for this ring. |
| 3847 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3848 | * This routine wraps the actual slow_ring event process routine from the |
| 3849 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3850 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3851 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3852 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3853 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3855 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3856 | } |
| 3857 | |
| 3858 | /** |
| 3859 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3860 | * @phba: Pointer to HBA context object. |
| 3861 | * @pring: Pointer to driver SLI ring object. |
| 3862 | * @mask: Host attention register mask for this ring. |
| 3863 | * |
| 3864 | * This function is called from the worker thread when there is a ring event |
| 3865 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3866 | * remove each response iocb in the response ring and calls the handle |
| 3867 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3868 | **/ |
| 3869 | static void |
| 3870 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3871 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3872 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3873 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3874 | IOCB_t *entry; |
| 3875 | IOCB_t *irsp = NULL; |
| 3876 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3878 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3879 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3881 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3882 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3883 | pring->stats.iocb_event++; |
| 3884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | /* |
| 3886 | * The next available response entry should never exceed the maximum |
| 3887 | * entries. If it does, treat it as an adapter hardware error. |
| 3888 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3889 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3890 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3891 | if (portRspPut >= portRspMax) { |
| 3892 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3893 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3894 | * rsp ring <portRspMax> |
| 3895 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3896 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3897 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3898 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3899 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3900 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | phba->link_state = LPFC_HBA_ERROR; |
| 3902 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | |
| 3904 | phba->work_hs = HS_FFER3; |
| 3905 | lpfc_handle_eratt(phba); |
| 3906 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3907 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3911 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3912 | /* |
| 3913 | * Build a completion list and call the appropriate handler. |
| 3914 | * The process is to get the next available response iocb, get |
| 3915 | * a free iocb from the list, copy the response data into the |
| 3916 | * free iocb, insert to the continuation list, and update the |
| 3917 | * next response index to slim. This process makes response |
| 3918 | * iocb's in the ring available to DMA as fast as possible but |
| 3919 | * pays a penalty for a copy operation. Since the iocb is |
| 3920 | * only 32 bytes, this penalty is considered small relative to |
| 3921 | * the PCI reads for register values and a slim write. When |
| 3922 | * the ulpLe field is set, the entire Command has been |
| 3923 | * received. |
| 3924 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3925 | entry = lpfc_resp_iocb(phba, pring); |
| 3926 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3927 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3928 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3929 | if (rspiocbp == NULL) { |
| 3930 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3931 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3932 | break; |
| 3933 | } |
| 3934 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3935 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3936 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3937 | irsp = &rspiocbp->iocb; |
| 3938 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3939 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3940 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3941 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3942 | if (pring->ringno == LPFC_ELS_RING) { |
| 3943 | lpfc_debugfs_slow_ring_trc(phba, |
| 3944 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3945 | *(((uint32_t *) irsp) + 4), |
| 3946 | *(((uint32_t *) irsp) + 6), |
| 3947 | *(((uint32_t *) irsp) + 7)); |
| 3948 | } |
| 3949 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3950 | writel(pring->sli.sli3.rspidx, |
| 3951 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3952 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3953 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3954 | /* Handle the response IOCB */ |
| 3955 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3956 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | |
| 3958 | /* |
| 3959 | * If the port response put pointer has not been updated, sync |
| 3960 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3961 | * response put pointer. |
| 3962 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3963 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3964 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3965 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3966 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3967 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3968 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3969 | /* At least one response entry has been freed */ |
| 3970 | pring->stats.iocb_rsp_full++; |
| 3971 | /* SET RxRE_RSP in Chip Att register */ |
| 3972 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3973 | writel(status, phba->CAregaddr); |
| 3974 | readl(phba->CAregaddr); /* flush */ |
| 3975 | } |
| 3976 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3977 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3978 | pring->stats.iocb_cmd_empty++; |
| 3979 | |
| 3980 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3981 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | lpfc_sli_resume_iocb(phba, pring); |
| 3983 | |
| 3984 | if ((pring->lpfc_sli_cmd_available)) |
| 3985 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3986 | |
| 3987 | } |
| 3988 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3989 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3990 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3991 | } |
| 3992 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3993 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3994 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3995 | * @phba: Pointer to HBA context object. |
| 3996 | * @pring: Pointer to driver SLI ring object. |
| 3997 | * @mask: Host attention register mask for this ring. |
| 3998 | * |
| 3999 | * This function is called from the worker thread when there is a pending |
| 4000 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 4001 | * queue. The caller does not hold any lock. The function will remove each |
| 4002 | * response iocb from the response worker queue and calls the handle |
| 4003 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 4004 | **/ |
| 4005 | static void |
| 4006 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 4007 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 4008 | { |
| 4009 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4010 | struct hbq_dmabuf *dmabuf; |
| 4011 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4012 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4013 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4014 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4015 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4016 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 4017 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4018 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4019 | /* Get the response iocb from the head of work queue */ |
| 4020 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4021 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4022 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4023 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4024 | |
| 4025 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 4026 | case CQE_CODE_COMPL_WQE: |
| 4027 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 4028 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4029 | /* Translate ELS WCQE to response IOCBQ */ |
| 4030 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 4031 | irspiocbq); |
| 4032 | if (irspiocbq) |
| 4033 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 4034 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4035 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4036 | break; |
| 4037 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4038 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4039 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 4040 | cq_event); |
| 4041 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4042 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4043 | break; |
| 4044 | default: |
| 4045 | break; |
| 4046 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4047 | |
| 4048 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 4049 | if (count == 64) |
| 4050 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4051 | } |
| 4052 | } |
| 4053 | |
| 4054 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4055 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4056 | * @phba: Pointer to HBA context object. |
| 4057 | * @pring: Pointer to driver SLI ring object. |
| 4058 | * |
| 4059 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 4060 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 4061 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 4062 | * the return of this function. The caller is not required to hold any locks. |
| 4063 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4064 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4065 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 4066 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4067 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4069 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4070 | if (pring->ringno == LPFC_ELS_RING) { |
| 4071 | lpfc_fabric_abort_hba(phba); |
| 4072 | } |
| 4073 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | /* Error everything on txq and txcmplq |
| 4075 | * First do the txq. |
| 4076 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4077 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 4078 | spin_lock_irq(&pring->ring_lock); |
| 4079 | list_splice_init(&pring->txq, &completions); |
| 4080 | pring->txq_cnt = 0; |
| 4081 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4083 | spin_lock_irq(&phba->hbalock); |
| 4084 | /* Next issue ABTS for everything on the txcmplq */ |
| 4085 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 4086 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 4087 | spin_unlock_irq(&phba->hbalock); |
| 4088 | } else { |
| 4089 | spin_lock_irq(&phba->hbalock); |
| 4090 | list_splice_init(&pring->txq, &completions); |
| 4091 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4092 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4093 | /* Next issue ABTS for everything on the txcmplq */ |
| 4094 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 4095 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 4096 | spin_unlock_irq(&phba->hbalock); |
| 4097 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4098 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4099 | /* Cancel all the IOCBs from the completions list */ |
| 4100 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4101 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4102 | } |
| 4103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4104 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4105 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 4106 | * @phba: Pointer to HBA context object. |
| 4107 | * @pring: Pointer to driver SLI ring object. |
| 4108 | * |
| 4109 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 4110 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 4111 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 4112 | * the return of this function. The caller is not required to hold any locks. |
| 4113 | **/ |
| 4114 | void |
| 4115 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 4116 | { |
| 4117 | struct lpfc_sli *psli = &phba->sli; |
| 4118 | struct lpfc_sli_ring *pring; |
| 4119 | uint32_t i; |
| 4120 | |
| 4121 | /* Look on all the FCP Rings for the iotag */ |
| 4122 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4123 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4124 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4125 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4126 | } |
| 4127 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4128 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4129 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4130 | } |
| 4131 | } |
| 4132 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4133 | /** |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4134 | * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4135 | * @phba: Pointer to HBA context object. |
| 4136 | * |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4137 | * This function flushes all iocbs in the IO ring and frees all the iocb |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4138 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 4139 | * for all the iocb commands in txcmplq, they will just be returned with |
| 4140 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4141 | * slot has been permanently disabled. |
| 4142 | **/ |
| 4143 | void |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4144 | lpfc_sli_flush_io_rings(struct lpfc_hba *phba) |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4145 | { |
| 4146 | LIST_HEAD(txq); |
| 4147 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4148 | struct lpfc_sli *psli = &phba->sli; |
| 4149 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4150 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4151 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4152 | |
| 4153 | spin_lock_irq(&phba->hbalock); |
James Smart | 4cd7089 | 2020-03-22 11:12:57 -0700 | [diff] [blame] | 4154 | if (phba->hba_flag & HBA_IOQ_FLUSH || |
| 4155 | !phba->sli4_hba.hdwq) { |
| 4156 | spin_unlock_irq(&phba->hbalock); |
| 4157 | return; |
| 4158 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4159 | /* Indicate the I/O queues are flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4160 | phba->hba_flag |= HBA_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4161 | spin_unlock_irq(&phba->hbalock); |
| 4162 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4163 | /* Look on all the FCP Rings for the iotag */ |
| 4164 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4165 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4166 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4167 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4168 | spin_lock_irq(&pring->ring_lock); |
| 4169 | /* Retrieve everything on txq */ |
| 4170 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4171 | list_for_each_entry_safe(piocb, next_iocb, |
| 4172 | &pring->txcmplq, list) |
| 4173 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4174 | /* Retrieve everything on the txcmplq */ |
| 4175 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4176 | pring->txq_cnt = 0; |
| 4177 | pring->txcmplq_cnt = 0; |
| 4178 | spin_unlock_irq(&pring->ring_lock); |
| 4179 | |
| 4180 | /* Flush the txq */ |
| 4181 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4182 | IOSTAT_LOCAL_REJECT, |
| 4183 | IOERR_SLI_DOWN); |
| 4184 | /* Flush the txcmpq */ |
| 4185 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4186 | IOSTAT_LOCAL_REJECT, |
| 4187 | IOERR_SLI_DOWN); |
| 4188 | } |
| 4189 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4190 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4191 | |
| 4192 | spin_lock_irq(&phba->hbalock); |
| 4193 | /* Retrieve everything on txq */ |
| 4194 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4195 | list_for_each_entry_safe(piocb, next_iocb, |
| 4196 | &pring->txcmplq, list) |
| 4197 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4198 | /* Retrieve everything on the txcmplq */ |
| 4199 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4200 | pring->txq_cnt = 0; |
| 4201 | pring->txcmplq_cnt = 0; |
| 4202 | spin_unlock_irq(&phba->hbalock); |
| 4203 | |
| 4204 | /* Flush the txq */ |
| 4205 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4206 | IOERR_SLI_DOWN); |
| 4207 | /* Flush the txcmpq */ |
| 4208 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4209 | IOERR_SLI_DOWN); |
| 4210 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4214 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4215 | * @phba: Pointer to HBA context object. |
| 4216 | * @mask: Bit mask to be checked. |
| 4217 | * |
| 4218 | * This function reads the host status register and compares |
| 4219 | * with the provided bit mask to check if HBA completed |
| 4220 | * the restart. This function will wait in a loop for the |
| 4221 | * HBA to complete restart. If the HBA does not restart within |
| 4222 | * 15 iterations, the function will reset the HBA again. The |
| 4223 | * function returns 1 when HBA fail to restart otherwise returns |
| 4224 | * zero. |
| 4225 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4226 | static int |
| 4227 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4229 | uint32_t status; |
| 4230 | int i = 0; |
| 4231 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4232 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4233 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4234 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4235 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4237 | /* |
| 4238 | * Check status register every 100ms for 5 retries, then every |
| 4239 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4240 | * every 2.5 sec for 4. |
| 4241 | * Break our of the loop if errors occurred during init. |
| 4242 | */ |
| 4243 | while (((status & mask) != mask) && |
| 4244 | !(status & HS_FFERM) && |
| 4245 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4246 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4247 | if (i <= 5) |
| 4248 | msleep(10); |
| 4249 | else if (i <= 10) |
| 4250 | msleep(500); |
| 4251 | else |
| 4252 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4254 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4255 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4256 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4257 | lpfc_sli_brdrestart(phba); |
| 4258 | } |
| 4259 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4260 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4261 | retval = 1; |
| 4262 | break; |
| 4263 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4264 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4265 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4266 | /* Check to see if any errors occurred during init */ |
| 4267 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4268 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4269 | "2751 Adapter failed to restart, " |
| 4270 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4271 | status, |
| 4272 | readl(phba->MBslimaddr + 0xa8), |
| 4273 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4274 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4275 | retval = 1; |
| 4276 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4277 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4278 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | } |
| 4280 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4281 | /** |
| 4282 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4283 | * @phba: Pointer to HBA context object. |
| 4284 | * @mask: Bit mask to be checked. |
| 4285 | * |
| 4286 | * This function checks the host status register to check if HBA is |
| 4287 | * ready. This function will wait in a loop for the HBA to be ready |
| 4288 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4289 | * function again. The function returns 1 when HBA fail to be ready |
| 4290 | * otherwise returns zero. |
| 4291 | **/ |
| 4292 | static int |
| 4293 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4294 | { |
| 4295 | uint32_t status; |
| 4296 | int retval = 0; |
| 4297 | |
| 4298 | /* Read the HBA Host Status Register */ |
| 4299 | status = lpfc_sli4_post_status_check(phba); |
| 4300 | |
| 4301 | if (status) { |
| 4302 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4303 | lpfc_sli_brdrestart(phba); |
| 4304 | status = lpfc_sli4_post_status_check(phba); |
| 4305 | } |
| 4306 | |
| 4307 | /* Check to see if any errors occurred during init */ |
| 4308 | if (status) { |
| 4309 | phba->link_state = LPFC_HBA_ERROR; |
| 4310 | retval = 1; |
| 4311 | } else |
| 4312 | phba->sli4_hba.intr_enable = 0; |
| 4313 | |
| 4314 | return retval; |
| 4315 | } |
| 4316 | |
| 4317 | /** |
| 4318 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4319 | * @phba: Pointer to HBA context object. |
| 4320 | * @mask: Bit mask to be checked. |
| 4321 | * |
| 4322 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4323 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4324 | **/ |
| 4325 | int |
| 4326 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4327 | { |
| 4328 | return phba->lpfc_sli_brdready(phba, mask); |
| 4329 | } |
| 4330 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4331 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4332 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4333 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4334 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4335 | * @phba: Pointer to HBA context object. |
| 4336 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4337 | * This function is called before resetting an HBA. This function is called |
| 4338 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4339 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4340 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4341 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4342 | uint32_t __iomem *resp_buf; |
| 4343 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4344 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4345 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4346 | int i; |
| 4347 | uint8_t hdrtype; |
| 4348 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4349 | lockdep_assert_held(&phba->hbalock); |
| 4350 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4351 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4352 | if (hdrtype != 0x80 || |
| 4353 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4354 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4355 | return; |
| 4356 | |
| 4357 | /* |
| 4358 | * Tell the other part of the chip to suspend temporarily all |
| 4359 | * its DMA activity. |
| 4360 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4361 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4362 | |
| 4363 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4364 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4365 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4366 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4367 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4368 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4369 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4370 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4371 | return; |
| 4372 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4373 | /* Clear Chip error bit */ |
| 4374 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4375 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | mbox = 0; |
| 4379 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4380 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4381 | |
| 4382 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4383 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4384 | writel(mbox, mbox_buf); |
| 4385 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4386 | for (i = 0; i < 50; i++) { |
| 4387 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4388 | return; |
| 4389 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4390 | mdelay(1); |
| 4391 | else |
| 4392 | break; |
| 4393 | } |
| 4394 | resp_data = 0; |
| 4395 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4396 | return; |
| 4397 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4398 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4399 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4400 | goto restore_hc; |
| 4401 | else |
| 4402 | goto clear_errat; |
| 4403 | } |
| 4404 | |
| 4405 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4406 | resp_data = 0; |
| 4407 | for (i = 0; i < 500; i++) { |
| 4408 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4409 | return; |
| 4410 | if (resp_data != mbox) |
| 4411 | mdelay(1); |
| 4412 | else |
| 4413 | break; |
| 4414 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4415 | |
| 4416 | clear_errat: |
| 4417 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4418 | while (++i < 500) { |
| 4419 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4420 | return; |
| 4421 | if (!(ha_copy & HA_ERATT)) |
| 4422 | mdelay(1); |
| 4423 | else |
| 4424 | break; |
| 4425 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4426 | |
| 4427 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4428 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4429 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4433 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4434 | writel(hc_copy, phba->HCregaddr); |
| 4435 | readl(phba->HCregaddr); /* flush */ |
| 4436 | } |
| 4437 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4438 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4439 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4440 | * @phba: Pointer to HBA context object. |
| 4441 | * |
| 4442 | * This function issues a kill_board mailbox command and waits for |
| 4443 | * the error attention interrupt. This function is called for stopping |
| 4444 | * the firmware processing. The caller is not required to hold any |
| 4445 | * locks. This function calls lpfc_hba_down_post function to free |
| 4446 | * any pending commands after the kill. The function will return 1 when it |
| 4447 | * fails to kill the board else will return 0. |
| 4448 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4449 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4450 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4451 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4452 | struct lpfc_sli *psli; |
| 4453 | LPFC_MBOXQ_t *pmb; |
| 4454 | uint32_t status; |
| 4455 | uint32_t ha_copy; |
| 4456 | int retval; |
| 4457 | int i = 0; |
| 4458 | |
| 4459 | psli = &phba->sli; |
| 4460 | |
| 4461 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4462 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4463 | "0329 Kill HBA Data: x%x x%x\n", |
| 4464 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4465 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4466 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4467 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4468 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4469 | |
| 4470 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4471 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4472 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4473 | spin_unlock_irq(&phba->hbalock); |
| 4474 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4475 | return 1; |
| 4476 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4477 | status &= ~HC_ERINT_ENA; |
| 4478 | writel(status, phba->HCregaddr); |
| 4479 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4480 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4481 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4482 | |
| 4483 | lpfc_kill_board(phba, pmb); |
| 4484 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4485 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4486 | |
| 4487 | if (retval != MBX_SUCCESS) { |
| 4488 | if (retval != MBX_BUSY) |
| 4489 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4490 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4491 | "2752 KILL_BOARD command failed retval %d\n", |
| 4492 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4493 | spin_lock_irq(&phba->hbalock); |
| 4494 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4495 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4496 | return 1; |
| 4497 | } |
| 4498 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4499 | spin_lock_irq(&phba->hbalock); |
| 4500 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4501 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4502 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4503 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4504 | |
| 4505 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4506 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4507 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4508 | * board is now undefined. |
| 4509 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4510 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4511 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4512 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4513 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4514 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4515 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4519 | if (ha_copy & HA_ERATT) { |
| 4520 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4521 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4522 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4523 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4524 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4525 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4526 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4527 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4528 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4529 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4531 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4533 | } |
| 4534 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4535 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4536 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4537 | * @phba: Pointer to HBA context object. |
| 4538 | * |
| 4539 | * This function resets the HBA by writing HC_INITFF to the control |
| 4540 | * register. After the HBA resets, this function resets all the iocb ring |
| 4541 | * indices. This function disables PCI layer parity checking during |
| 4542 | * the reset. |
| 4543 | * This function returns 0 always. |
| 4544 | * The caller is not required to hold any locks. |
| 4545 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4546 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4547 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4548 | { |
| 4549 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4550 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4551 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4552 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4553 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4554 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4555 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4556 | /* Reset HBA */ |
| 4557 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4558 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4559 | (phba->pport) ? phba->pport->port_state : 0, |
| 4560 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [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 | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4565 | if (phba->pport) { |
| 4566 | phba->pport->fc_myDID = 0; |
| 4567 | phba->pport->fc_prevDID = 0; |
| 4568 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4570 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4571 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) |
| 4572 | return -EIO; |
| 4573 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4574 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4575 | (cfg_value & |
| 4576 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4577 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4578 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4579 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4580 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4581 | writel(HC_INITFF, phba->HCregaddr); |
| 4582 | mdelay(1); |
| 4583 | readl(phba->HCregaddr); /* flush */ |
| 4584 | writel(0, phba->HCregaddr); |
| 4585 | readl(phba->HCregaddr); /* flush */ |
| 4586 | |
| 4587 | /* Restore PCI cmd register */ |
| 4588 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4589 | |
| 4590 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4591 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4592 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4593 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4594 | pring->sli.sli3.rspidx = 0; |
| 4595 | pring->sli.sli3.next_cmdidx = 0; |
| 4596 | pring->sli.sli3.local_getidx = 0; |
| 4597 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4598 | pring->missbufcnt = 0; |
| 4599 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4600 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4601 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4602 | return 0; |
| 4603 | } |
| 4604 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4605 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4606 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4607 | * @phba: Pointer to HBA context object. |
| 4608 | * |
| 4609 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4610 | * checking during resets the device. The caller is not required to hold |
| 4611 | * any locks. |
| 4612 | * |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 4613 | * This function returns 0 on success else returns negative error code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4614 | **/ |
| 4615 | int |
| 4616 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4617 | { |
| 4618 | struct lpfc_sli *psli = &phba->sli; |
| 4619 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4620 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4621 | |
| 4622 | /* Reset HBA */ |
| 4623 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4624 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4625 | phba->pport->port_state, psli->sli_flag, |
| 4626 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4627 | |
| 4628 | /* perform board reset */ |
| 4629 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4630 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4631 | phba->pport->fc_myDID = 0; |
| 4632 | phba->pport->fc_prevDID = 0; |
| 4633 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4634 | spin_lock_irq(&phba->hbalock); |
| 4635 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4636 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4637 | spin_unlock_irq(&phba->hbalock); |
| 4638 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4639 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4640 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4641 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4642 | return rc; |
| 4643 | } |
| 4644 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4645 | /* Now physically reset the device */ |
| 4646 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4647 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4648 | |
| 4649 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4650 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) { |
| 4651 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4652 | "3205 PCI read Config failed\n"); |
| 4653 | return -EIO; |
| 4654 | } |
| 4655 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4656 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4657 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4658 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4659 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4660 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4661 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4662 | /* Restore PCI cmd register */ |
| 4663 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4664 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4665 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | /** |
| 4669 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4670 | * @phba: Pointer to HBA context object. |
| 4671 | * |
| 4672 | * This function is called in the SLI initialization code path to |
| 4673 | * restart the HBA. The caller is not required to hold any lock. |
| 4674 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4675 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4676 | * function to free any pending commands. The function enables |
| 4677 | * POST only during the first initialization. The function returns zero. |
| 4678 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4679 | * command before the return of this function. |
| 4680 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4681 | static int |
| 4682 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4683 | { |
| 4684 | MAILBOX_t *mb; |
| 4685 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4686 | volatile uint32_t word0; |
| 4687 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4688 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4689 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4690 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4691 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4692 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4693 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4694 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4695 | psli = &phba->sli; |
| 4696 | |
| 4697 | /* Restart HBA */ |
| 4698 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4699 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4700 | (phba->pport) ? phba->pport->port_state : 0, |
| 4701 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4702 | |
| 4703 | word0 = 0; |
| 4704 | mb = (MAILBOX_t *) &word0; |
| 4705 | mb->mbxCommand = MBX_RESTART; |
| 4706 | mb->mbxHc = 1; |
| 4707 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4708 | lpfc_reset_barrier(phba); |
| 4709 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4710 | to_slim = phba->MBslimaddr; |
| 4711 | writel(*(uint32_t *) mb, to_slim); |
| 4712 | readl(to_slim); /* flush */ |
| 4713 | |
| 4714 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4715 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4716 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4717 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4718 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4719 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4720 | writel(*(uint32_t *) mb, to_slim); |
| 4721 | readl(to_slim); /* flush */ |
| 4722 | |
| 4723 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4724 | if (phba->pport) |
| 4725 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4726 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4727 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4728 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4729 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4730 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4731 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4732 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4733 | /* Give the INITFF and Post time to settle. */ |
| 4734 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4736 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4737 | if (hba_aer_enabled) |
| 4738 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4739 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4740 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 | |
| 4742 | return 0; |
| 4743 | } |
| 4744 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4745 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4746 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4747 | * @phba: Pointer to HBA context object. |
| 4748 | * |
| 4749 | * This function is called in the SLI initialization code path to restart |
| 4750 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4751 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4752 | * free any pending commands. |
| 4753 | **/ |
| 4754 | static int |
| 4755 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4756 | { |
| 4757 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4758 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4759 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4760 | |
| 4761 | /* Restart HBA */ |
| 4762 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4763 | "0296 Restart HBA Data: x%x x%x\n", |
| 4764 | phba->pport->port_state, psli->sli_flag); |
| 4765 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4766 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4767 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4768 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4769 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4770 | if (rc) { |
| 4771 | phba->link_state = LPFC_HBA_ERROR; |
| 4772 | goto hba_down_queue; |
| 4773 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4774 | |
| 4775 | spin_lock_irq(&phba->hbalock); |
| 4776 | phba->pport->stopped = 0; |
| 4777 | phba->link_state = LPFC_INIT_START; |
| 4778 | phba->hba_flag = 0; |
| 4779 | spin_unlock_irq(&phba->hbalock); |
| 4780 | |
| 4781 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4782 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4783 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4784 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4785 | if (hba_aer_enabled) |
| 4786 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4787 | |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4788 | hba_down_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4789 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4790 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4791 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4792 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | /** |
| 4796 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4797 | * @phba: Pointer to HBA context object. |
| 4798 | * |
| 4799 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4800 | * API jump table function pointer from the lpfc_hba struct. |
| 4801 | **/ |
| 4802 | int |
| 4803 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4804 | { |
| 4805 | return phba->lpfc_sli_brdrestart(phba); |
| 4806 | } |
| 4807 | |
| 4808 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4809 | * 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] | 4810 | * @phba: Pointer to HBA context object. |
| 4811 | * |
| 4812 | * This function is called after a HBA restart to wait for successful |
| 4813 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4814 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4815 | * iteration, the function will restart the HBA again. The function returns |
| 4816 | * zero if HBA successfully restarted else returns negative error code. |
| 4817 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4818 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4819 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4820 | { |
| 4821 | uint32_t status, i = 0; |
| 4822 | |
| 4823 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4824 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4825 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4826 | |
| 4827 | /* Check status register to see what current state is */ |
| 4828 | i = 0; |
| 4829 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4830 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4831 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4832 | * retries, then every 1 sec for 50 retires for a total of |
| 4833 | * ~60 seconds before reset the board again and check every |
| 4834 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4835 | * board ready is required by the Falcon FIPS zeroization |
| 4836 | * complete, and any reset the board in between shall cause |
| 4837 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4838 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4839 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4840 | /* Adapter failed to init, timeout, status reg |
| 4841 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4842 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4843 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4844 | "timeout, status reg x%x, " |
| 4845 | "FW Data: A8 x%x AC x%x\n", status, |
| 4846 | readl(phba->MBslimaddr + 0xa8), |
| 4847 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4848 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4849 | return -ETIMEDOUT; |
| 4850 | } |
| 4851 | |
| 4852 | /* Check to see if any errors occurred during init */ |
| 4853 | if (status & HS_FFERM) { |
| 4854 | /* ERROR: During chipset initialization */ |
| 4855 | /* Adapter failed to init, chipset, status reg |
| 4856 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4857 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4858 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4859 | "chipset, status reg x%x, " |
| 4860 | "FW Data: A8 x%x AC x%x\n", status, |
| 4861 | readl(phba->MBslimaddr + 0xa8), |
| 4862 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4863 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4864 | return -EIO; |
| 4865 | } |
| 4866 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4867 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4868 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4869 | else if (i <= 100) |
| 4870 | msleep(100); |
| 4871 | else |
| 4872 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4873 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4874 | if (i == 150) { |
| 4875 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4876 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4877 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4878 | } |
| 4879 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4880 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4881 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | /* Check to see if any errors occurred during init */ |
| 4885 | if (status & HS_FFERM) { |
| 4886 | /* ERROR: During chipset initialization */ |
| 4887 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4888 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4889 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4890 | "status reg x%x, " |
| 4891 | "FW Data: A8 x%x AC x%x\n", status, |
| 4892 | readl(phba->MBslimaddr + 0xa8), |
| 4893 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4894 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4895 | return -EIO; |
| 4896 | } |
| 4897 | |
| 4898 | /* Clear all interrupt enable conditions */ |
| 4899 | writel(0, phba->HCregaddr); |
| 4900 | readl(phba->HCregaddr); /* flush */ |
| 4901 | |
| 4902 | /* setup host attn register */ |
| 4903 | writel(0xffffffff, phba->HAregaddr); |
| 4904 | readl(phba->HAregaddr); /* flush */ |
| 4905 | return 0; |
| 4906 | } |
| 4907 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4908 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4909 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4910 | * |
| 4911 | * This function calculates and returns the number of HBQs required to be |
| 4912 | * configured. |
| 4913 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4914 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4915 | lpfc_sli_hbq_count(void) |
| 4916 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4917 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4918 | } |
| 4919 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4920 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4921 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4922 | * |
| 4923 | * This function adds the number of hbq entries in every HBQ to get |
| 4924 | * the total number of hbq entries required for the HBA and returns |
| 4925 | * the total count. |
| 4926 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4927 | static int |
| 4928 | lpfc_sli_hbq_entry_count(void) |
| 4929 | { |
| 4930 | int hbq_count = lpfc_sli_hbq_count(); |
| 4931 | int count = 0; |
| 4932 | int i; |
| 4933 | |
| 4934 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4935 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4936 | return count; |
| 4937 | } |
| 4938 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4939 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4940 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4941 | * |
| 4942 | * This function calculates amount of memory required for all hbq entries |
| 4943 | * to be configured and returns the total memory required. |
| 4944 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4945 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4946 | lpfc_sli_hbq_size(void) |
| 4947 | { |
| 4948 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4949 | } |
| 4950 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4952 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4953 | * @phba: Pointer to HBA context object. |
| 4954 | * |
| 4955 | * This function is called during the SLI initialization to configure |
| 4956 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4957 | * required to hold any locks. This function will return zero if successful |
| 4958 | * else it will return negative error code. |
| 4959 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4960 | static int |
| 4961 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4962 | { |
| 4963 | int hbq_count = lpfc_sli_hbq_count(); |
| 4964 | LPFC_MBOXQ_t *pmb; |
| 4965 | MAILBOX_t *pmbox; |
| 4966 | uint32_t hbqno; |
| 4967 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4968 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4969 | /* Get a Mailbox buffer to setup mailbox |
| 4970 | * commands for HBA initialization |
| 4971 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4972 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4973 | |
| 4974 | if (!pmb) |
| 4975 | return -ENOMEM; |
| 4976 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4977 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4978 | |
| 4979 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4980 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4981 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4982 | |
| 4983 | hbq_entry_index = 0; |
| 4984 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4985 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4986 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4987 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4988 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4989 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4990 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4991 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4992 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4993 | |
| 4994 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4995 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4996 | mbxStatus <status>, ring <num> */ |
| 4997 | |
| 4998 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4999 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5000 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5001 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5002 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5003 | pmbox->mbxStatus, hbqno); |
| 5004 | |
| 5005 | phba->link_state = LPFC_HBA_ERROR; |
| 5006 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5007 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5008 | } |
| 5009 | } |
| 5010 | phba->hbq_count = hbq_count; |
| 5011 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5012 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5013 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5014 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5015 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 5016 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5017 | return 0; |
| 5018 | } |
| 5019 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5020 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5021 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 5022 | * @phba: Pointer to HBA context object. |
| 5023 | * |
| 5024 | * This function is called during the SLI initialization to configure |
| 5025 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 5026 | * required to hold any locks. This function will return zero if successful |
| 5027 | * else it will return negative error code. |
| 5028 | **/ |
| 5029 | static int |
| 5030 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 5031 | { |
| 5032 | phba->hbq_in_use = 1; |
James Smart | 999fbbc | 2019-12-18 15:58:06 -0800 | [diff] [blame] | 5033 | /** |
| 5034 | * Specific case when the MDS diagnostics is enabled and supported. |
| 5035 | * The receive buffer count is truncated to manage the incoming |
| 5036 | * traffic. |
| 5037 | **/ |
| 5038 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) |
| 5039 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 5040 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1; |
| 5041 | else |
| 5042 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 5043 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5044 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5045 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5046 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5047 | return 0; |
| 5048 | } |
| 5049 | |
| 5050 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5051 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5052 | * @phba: Pointer to HBA context object. |
| 5053 | * @sli_mode: sli mode - 2/3 |
| 5054 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5055 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5056 | * to issue config_port mailbox command. This function restarts the |
| 5057 | * HBA firmware and issues a config_port mailbox command to configure |
| 5058 | * the SLI interface in the sli mode specified by sli_mode |
| 5059 | * variable. The caller is not required to hold any locks. |
| 5060 | * The function returns 0 if successful, else returns negative error |
| 5061 | * code. |
| 5062 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5063 | int |
| 5064 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5065 | { |
| 5066 | LPFC_MBOXQ_t *pmb; |
| 5067 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 5068 | |
| 5069 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5070 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5071 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5072 | return -ENOMEM; |
| 5073 | } |
| 5074 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5075 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5076 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5077 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 5078 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5079 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5080 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5081 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5082 | rc = lpfc_sli_chipset_init(phba); |
| 5083 | if (rc) |
| 5084 | break; |
| 5085 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5086 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 5087 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5088 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5089 | resetcount++; |
| 5090 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5091 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 5092 | * value of 0 means the call was successful. Any other |
| 5093 | * nonzero value is a failure, but if ERESTART is returned, |
| 5094 | * the driver may reset the HBA and try again. |
| 5095 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5096 | rc = lpfc_config_port_prep(phba); |
| 5097 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5098 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5100 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5101 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5102 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5103 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5104 | lpfc_config_port(phba, pmb); |
| 5105 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5106 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 5107 | LPFC_SLI3_HBQ_ENABLED | |
| 5108 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5109 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5110 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5111 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5112 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5113 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5114 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5115 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5116 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5117 | spin_unlock_irq(&phba->hbalock); |
| 5118 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5119 | } else { |
| 5120 | /* Allow asynchronous mailbox command to go through */ |
| 5121 | spin_lock_irq(&phba->hbalock); |
| 5122 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 5123 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5124 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5125 | |
| 5126 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 5127 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 5128 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5129 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5130 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5131 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5132 | if (!done) { |
| 5133 | rc = -EINVAL; |
| 5134 | goto do_prep_failed; |
| 5135 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5136 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 5137 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5138 | rc = -ENXIO; |
| 5139 | goto do_prep_failed; |
| 5140 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5141 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5142 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5143 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5144 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5145 | phba->max_vpi : phba->max_vports; |
| 5146 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5147 | } else |
| 5148 | phba->max_vpi = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5149 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5150 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5151 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5152 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5153 | |
| 5154 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5155 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5156 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5157 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5158 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5159 | phba->cfg_enable_bg = 0; |
| 5160 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5162 | "0443 Adapter did not grant " |
| 5163 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5164 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5165 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5166 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5167 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5168 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5169 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5170 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5171 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5172 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5173 | return rc; |
| 5174 | } |
| 5175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5176 | |
| 5177 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5178 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5179 | * @phba: Pointer to HBA context object. |
| 5180 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5181 | * This function is the main SLI initialization function. This function |
| 5182 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5183 | * error attention handler code. Caller is not required to hold any |
| 5184 | * locks. This function issues config_port mailbox command to configure |
| 5185 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5186 | * calls the config_port_post function to issue init_link mailbox |
| 5187 | * command and to start the discovery. The function will return zero |
| 5188 | * if successful, else it will return negative error code. |
| 5189 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5190 | int |
| 5191 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5192 | { |
| 5193 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5194 | int mode = 3, i; |
| 5195 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5196 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5197 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5198 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5199 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5201 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5202 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5203 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5204 | break; |
| 5205 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5206 | mode = 2; |
| 5207 | break; |
| 5208 | case 0: |
| 5209 | case 3: |
| 5210 | break; |
| 5211 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5212 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5213 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 5214 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5215 | |
| 5216 | break; |
| 5217 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5218 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5219 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5220 | rc = lpfc_sli_config_port(phba, mode); |
| 5221 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5222 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5223 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5224 | "1820 Unable to select SLI-3. " |
| 5225 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5226 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5227 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 5228 | else if (rc && mode == 2) |
| 5229 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5230 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5231 | goto lpfc_sli_hba_setup_error; |
| 5232 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5233 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5234 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5235 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5236 | if (!rc) { |
| 5237 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5238 | "2709 This device supports " |
| 5239 | "Advanced Error Reporting (AER)\n"); |
| 5240 | spin_lock_irq(&phba->hbalock); |
| 5241 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5242 | spin_unlock_irq(&phba->hbalock); |
| 5243 | } else { |
| 5244 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5245 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5246 | "Advanced Error Reporting (AER): %d\n", |
| 5247 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5248 | phba->cfg_aer_support = 0; |
| 5249 | } |
| 5250 | } |
| 5251 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5252 | if (phba->sli_rev == 3) { |
| 5253 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5254 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5255 | } else { |
| 5256 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5257 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5258 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5262 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5263 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5264 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5265 | |
| 5266 | if (rc) |
| 5267 | goto lpfc_sli_hba_setup_error; |
| 5268 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5269 | /* Initialize VPIs. */ |
| 5270 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5271 | /* |
| 5272 | * The VPI bitmask and physical ID array are allocated |
| 5273 | * and initialized once only - at driver load. A port |
| 5274 | * reset doesn't need to reinitialize this memory. |
| 5275 | */ |
| 5276 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5277 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5278 | phba->vpi_bmask = kcalloc(longs, |
| 5279 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5280 | GFP_KERNEL); |
| 5281 | if (!phba->vpi_bmask) { |
| 5282 | rc = -ENOMEM; |
| 5283 | goto lpfc_sli_hba_setup_error; |
| 5284 | } |
| 5285 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5286 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5287 | sizeof(uint16_t), |
| 5288 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5289 | if (!phba->vpi_ids) { |
| 5290 | kfree(phba->vpi_bmask); |
| 5291 | rc = -ENOMEM; |
| 5292 | goto lpfc_sli_hba_setup_error; |
| 5293 | } |
| 5294 | for (i = 0; i < phba->max_vpi; i++) |
| 5295 | phba->vpi_ids[i] = i; |
| 5296 | } |
| 5297 | } |
| 5298 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5299 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5300 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5301 | rc = lpfc_sli_hbq_setup(phba); |
| 5302 | if (rc) |
| 5303 | goto lpfc_sli_hba_setup_error; |
| 5304 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5305 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5306 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5307 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5308 | |
| 5309 | rc = lpfc_config_port_post(phba); |
| 5310 | if (rc) |
| 5311 | goto lpfc_sli_hba_setup_error; |
| 5312 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5313 | return rc; |
| 5314 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5315 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5316 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 5317 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5318 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5319 | return rc; |
| 5320 | } |
| 5321 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5322 | /** |
| 5323 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5324 | * @phba: Pointer to HBA context object. |
| 5325 | * @mboxq: mailbox pointer. |
| 5326 | * This function issue a dump mailbox command to read config region |
| 5327 | * 23 and parse the records in the region and populate driver |
| 5328 | * data structure. |
| 5329 | **/ |
| 5330 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5331 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5332 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5333 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5334 | struct lpfc_dmabuf *mp; |
| 5335 | struct lpfc_mqe *mqe; |
| 5336 | uint32_t data_length; |
| 5337 | int rc; |
| 5338 | |
| 5339 | /* Program the default value of vlan_id and fc_map */ |
| 5340 | phba->valid_vlan = 0; |
| 5341 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5342 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5343 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5344 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5345 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5346 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5347 | return -ENOMEM; |
| 5348 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5349 | mqe = &mboxq->u.mqe; |
| 5350 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5351 | rc = -ENOMEM; |
| 5352 | goto out_free_mboxq; |
| 5353 | } |
| 5354 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5355 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5356 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5357 | |
| 5358 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5359 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5360 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5361 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5362 | "CQ: x%x x%x x%x x%x\n", |
| 5363 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5364 | bf_get(lpfc_mqe_command, mqe), |
| 5365 | bf_get(lpfc_mqe_status, mqe), |
| 5366 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5367 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5368 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5369 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5370 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5371 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5372 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5373 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5374 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5375 | mboxq->mcqe.word0, |
| 5376 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5377 | mboxq->mcqe.trailer); |
| 5378 | |
| 5379 | if (rc) { |
| 5380 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5381 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5382 | rc = -EIO; |
| 5383 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5384 | } |
| 5385 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5386 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5387 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5388 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5389 | rc = -EIO; |
| 5390 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5391 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5392 | |
| 5393 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5394 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5395 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5396 | rc = 0; |
| 5397 | |
| 5398 | out_free_mboxq: |
| 5399 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5400 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | /** |
| 5404 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5405 | * @phba: pointer to lpfc hba data structure. |
| 5406 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5407 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5408 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5409 | * On output, the number of data bytes in @vpd. |
| 5410 | * |
| 5411 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5412 | * addition, this routine gets the port vpd data. |
| 5413 | * |
| 5414 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5415 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5416 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5417 | **/ |
| 5418 | static int |
| 5419 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5420 | uint8_t *vpd, uint32_t *vpd_size) |
| 5421 | { |
| 5422 | int rc = 0; |
| 5423 | uint32_t dma_size; |
| 5424 | struct lpfc_dmabuf *dmabuf; |
| 5425 | struct lpfc_mqe *mqe; |
| 5426 | |
| 5427 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5428 | if (!dmabuf) |
| 5429 | return -ENOMEM; |
| 5430 | |
| 5431 | /* |
| 5432 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5433 | * mailbox command. |
| 5434 | */ |
| 5435 | dma_size = *vpd_size; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 5436 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size, |
| 5437 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5438 | if (!dmabuf->virt) { |
| 5439 | kfree(dmabuf); |
| 5440 | return -ENOMEM; |
| 5441 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5442 | |
| 5443 | /* |
| 5444 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5445 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5446 | * in SLI3. This code corrects the conflicts. |
| 5447 | */ |
| 5448 | lpfc_read_rev(phba, mboxq); |
| 5449 | mqe = &mboxq->u.mqe; |
| 5450 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5451 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5452 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5453 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5454 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5455 | |
| 5456 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5457 | if (rc) { |
| 5458 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5459 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5460 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5461 | return -EIO; |
| 5462 | } |
| 5463 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5464 | /* |
| 5465 | * The available vpd length cannot be bigger than the |
| 5466 | * DMA buffer passed to the port. Catch the less than |
| 5467 | * case and update the caller's size. |
| 5468 | */ |
| 5469 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5470 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5471 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5472 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5473 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5474 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5475 | dmabuf->virt, dmabuf->phys); |
| 5476 | kfree(dmabuf); |
| 5477 | return 0; |
| 5478 | } |
| 5479 | |
| 5480 | /** |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5481 | * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5482 | * @phba: pointer to lpfc hba data structure. |
| 5483 | * |
| 5484 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5485 | * is attached to. |
| 5486 | * |
| 5487 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5488 | * 0 - successful |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5489 | * otherwise - failed to retrieve controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5490 | **/ |
| 5491 | static int |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5492 | lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba) |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5493 | { |
| 5494 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5495 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5496 | struct lpfc_controller_attribute *cntl_attr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5497 | void *virtaddr = NULL; |
| 5498 | uint32_t alloclen, reqlen; |
| 5499 | uint32_t shdr_status, shdr_add_status; |
| 5500 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5501 | int rc; |
| 5502 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5503 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5504 | if (!mboxq) |
| 5505 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5506 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5507 | /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */ |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5508 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5509 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5510 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5511 | LPFC_SLI4_MBX_NEMBED); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5512 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5513 | if (alloclen < reqlen) { |
| 5514 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5515 | "3084 Allocated DMA memory size (%d) is " |
| 5516 | "less than the requested DMA memory size " |
| 5517 | "(%d)\n", alloclen, reqlen); |
| 5518 | rc = -ENOMEM; |
| 5519 | goto out_free_mboxq; |
| 5520 | } |
| 5521 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5522 | virtaddr = mboxq->sge_array->addr[0]; |
| 5523 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5524 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5525 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5526 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5527 | if (shdr_status || shdr_add_status || rc) { |
| 5528 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5529 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5530 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5531 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5532 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5533 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5534 | rc, shdr_status, shdr_add_status); |
| 5535 | rc = -ENXIO; |
| 5536 | goto out_free_mboxq; |
| 5537 | } |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5538 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5539 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5540 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5541 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5542 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5543 | phba->sli4_hba.lnk_info.lnk_no = |
| 5544 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5545 | |
| 5546 | memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion)); |
| 5547 | strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str, |
| 5548 | sizeof(phba->BIOSVersion)); |
| 5549 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5550 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5551 | "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n", |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5552 | phba->sli4_hba.lnk_info.lnk_tp, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5553 | phba->sli4_hba.lnk_info.lnk_no, |
| 5554 | phba->BIOSVersion); |
| 5555 | out_free_mboxq: |
| 5556 | if (rc != MBX_TIMEOUT) { |
| 5557 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5558 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5559 | else |
| 5560 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5561 | } |
| 5562 | return rc; |
| 5563 | } |
| 5564 | |
| 5565 | /** |
| 5566 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5567 | * @phba: pointer to lpfc hba data structure. |
| 5568 | * |
| 5569 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5570 | * is attached to. |
| 5571 | * |
| 5572 | * Return codes |
| 5573 | * 0 - successful |
| 5574 | * otherwise - failed to retrieve physical port name |
| 5575 | **/ |
| 5576 | static int |
| 5577 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5578 | { |
| 5579 | LPFC_MBOXQ_t *mboxq; |
| 5580 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5581 | uint32_t shdr_status, shdr_add_status; |
| 5582 | union lpfc_sli4_cfg_shdr *shdr; |
| 5583 | char cport_name = 0; |
| 5584 | int rc; |
| 5585 | |
| 5586 | /* We assume nothing at this point */ |
| 5587 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5588 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5589 | |
| 5590 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5591 | if (!mboxq) |
| 5592 | return -ENOMEM; |
| 5593 | /* obtain link type and link number via READ_CONFIG */ |
| 5594 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5595 | lpfc_sli4_read_config(phba); |
| 5596 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5597 | goto retrieve_ppname; |
| 5598 | |
| 5599 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5600 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 5601 | if (rc) |
| 5602 | goto out_free_mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5603 | |
| 5604 | retrieve_ppname: |
| 5605 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5606 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5607 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5608 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5609 | LPFC_SLI4_MBX_EMBED); |
| 5610 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5611 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5612 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5613 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5614 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5615 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5616 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5617 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5618 | if (shdr_status || shdr_add_status || rc) { |
| 5619 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5620 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5621 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5622 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5623 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5624 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5625 | rc, shdr_status, shdr_add_status); |
| 5626 | rc = -ENXIO; |
| 5627 | goto out_free_mboxq; |
| 5628 | } |
| 5629 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5630 | case LPFC_LINK_NUMBER_0: |
| 5631 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5632 | &get_port_name->u.response); |
| 5633 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5634 | break; |
| 5635 | case LPFC_LINK_NUMBER_1: |
| 5636 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5637 | &get_port_name->u.response); |
| 5638 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5639 | break; |
| 5640 | case LPFC_LINK_NUMBER_2: |
| 5641 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5642 | &get_port_name->u.response); |
| 5643 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5644 | break; |
| 5645 | case LPFC_LINK_NUMBER_3: |
| 5646 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5647 | &get_port_name->u.response); |
| 5648 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5649 | break; |
| 5650 | default: |
| 5651 | break; |
| 5652 | } |
| 5653 | |
| 5654 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5655 | phba->Port[0] = cport_name; |
| 5656 | phba->Port[1] = '\0'; |
| 5657 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5658 | "3091 SLI get port name: %s\n", phba->Port); |
| 5659 | } |
| 5660 | |
| 5661 | out_free_mboxq: |
| 5662 | if (rc != MBX_TIMEOUT) { |
| 5663 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5664 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5665 | else |
| 5666 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5667 | } |
| 5668 | return rc; |
| 5669 | } |
| 5670 | |
| 5671 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5672 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5673 | * @phba: pointer to lpfc hba data structure. |
| 5674 | * |
| 5675 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5676 | * event queues |
| 5677 | **/ |
| 5678 | static void |
| 5679 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5680 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5681 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5682 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5683 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5684 | struct lpfc_queue *eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5685 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5686 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM); |
| 5687 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM); |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5688 | if (sli4_hba->nvmels_cq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5689 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0, |
| 5690 | LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5691 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5692 | if (sli4_hba->hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5693 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5694 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5695 | qp = &sli4_hba->hdwq[qidx]; |
| 5696 | /* ARM the corresponding CQ */ |
James Smart | 01f2ef6 | 2019-08-28 16:19:11 -0700 | [diff] [blame] | 5697 | sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 5698 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5699 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5700 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5701 | /* Loop thru all IRQ vectors */ |
| 5702 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 5703 | eq = sli4_hba->hba_eq_hdl[qidx].eq; |
| 5704 | /* ARM the corresponding EQ */ |
| 5705 | sli4_hba->sli4_write_eq_db(phba, eq, |
| 5706 | 0, LPFC_QUEUE_REARM); |
| 5707 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5708 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5709 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5710 | if (phba->nvmet_support) { |
| 5711 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5712 | sli4_hba->sli4_write_cq_db(phba, |
| 5713 | sli4_hba->nvmet_cqset[qidx], 0, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5714 | LPFC_QUEUE_REARM); |
| 5715 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5716 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5720 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5721 | * @phba: Pointer to HBA context object. |
| 5722 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5723 | * @extnt_count: buffer to hold port available extent count. |
| 5724 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5725 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5726 | * This function calls the port and retrievs the number of available |
| 5727 | * extents and their size for a particular extent type. |
| 5728 | * |
| 5729 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5730 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5731 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5732 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5733 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5734 | { |
| 5735 | int rc = 0; |
| 5736 | uint32_t length; |
| 5737 | uint32_t mbox_tmo; |
| 5738 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5739 | LPFC_MBOXQ_t *mbox; |
| 5740 | |
| 5741 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5742 | if (!mbox) |
| 5743 | return -ENOMEM; |
| 5744 | |
| 5745 | /* Find out how many extents are available for this resource type */ |
| 5746 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5747 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5748 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5749 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5750 | length, LPFC_SLI4_MBX_EMBED); |
| 5751 | |
| 5752 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5753 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5754 | LPFC_SLI4_MBX_EMBED); |
| 5755 | if (unlikely(rc)) { |
| 5756 | rc = -EIO; |
| 5757 | goto err_exit; |
| 5758 | } |
| 5759 | |
| 5760 | if (!phba->sli4_hba.intr_enable) |
| 5761 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5762 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5763 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5764 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5765 | } |
| 5766 | if (unlikely(rc)) { |
| 5767 | rc = -EIO; |
| 5768 | goto err_exit; |
| 5769 | } |
| 5770 | |
| 5771 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5772 | if (bf_get(lpfc_mbox_hdr_status, |
| 5773 | &rsrc_info->header.cfg_shdr.response)) { |
| 5774 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5775 | "2930 Failed to get resource extents " |
| 5776 | "Status 0x%x Add'l Status 0x%x\n", |
| 5777 | bf_get(lpfc_mbox_hdr_status, |
| 5778 | &rsrc_info->header.cfg_shdr.response), |
| 5779 | bf_get(lpfc_mbox_hdr_add_status, |
| 5780 | &rsrc_info->header.cfg_shdr.response)); |
| 5781 | rc = -EIO; |
| 5782 | goto err_exit; |
| 5783 | } |
| 5784 | |
| 5785 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5786 | &rsrc_info->u.rsp); |
| 5787 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5788 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5789 | |
| 5790 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5791 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5792 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5793 | |
| 5794 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5795 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5796 | return rc; |
| 5797 | } |
| 5798 | |
| 5799 | /** |
| 5800 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5801 | * @phba: Pointer to HBA context object. |
| 5802 | * @type: The extent type to check. |
| 5803 | * |
| 5804 | * This function reads the current available extents from the port and checks |
| 5805 | * if the extent count or extent size has changed since the last access. |
| 5806 | * Callers use this routine post port reset to understand if there is a |
| 5807 | * extent reprovisioning requirement. |
| 5808 | * |
| 5809 | * Returns: |
| 5810 | * -Error: error indicates problem. |
| 5811 | * 1: Extent count or size has changed. |
| 5812 | * 0: No changes. |
| 5813 | **/ |
| 5814 | static int |
| 5815 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5816 | { |
| 5817 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5818 | uint16_t size_diff, rsrc_ext_size; |
| 5819 | int rc = 0; |
| 5820 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5821 | struct list_head *rsrc_blk_list = NULL; |
| 5822 | |
| 5823 | size_diff = 0; |
| 5824 | curr_ext_cnt = 0; |
| 5825 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5826 | &rsrc_ext_cnt, |
| 5827 | &rsrc_ext_size); |
| 5828 | if (unlikely(rc)) |
| 5829 | return -EIO; |
| 5830 | |
| 5831 | switch (type) { |
| 5832 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5833 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5834 | break; |
| 5835 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5836 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5837 | break; |
| 5838 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5839 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5840 | break; |
| 5841 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5842 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5843 | break; |
| 5844 | default: |
| 5845 | break; |
| 5846 | } |
| 5847 | |
| 5848 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5849 | curr_ext_cnt++; |
| 5850 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5851 | size_diff++; |
| 5852 | } |
| 5853 | |
| 5854 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5855 | rc = 1; |
| 5856 | |
| 5857 | return rc; |
| 5858 | } |
| 5859 | |
| 5860 | /** |
| 5861 | * lpfc_sli4_cfg_post_extnts - |
| 5862 | * @phba: Pointer to HBA context object. |
| 5863 | * @extnt_cnt - number of available extents. |
| 5864 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5865 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5866 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5867 | * |
| 5868 | * This function executes the extents allocation request. It also |
| 5869 | * takes care of the amount of memory needed to allocate or get the |
| 5870 | * allocated extents. It is the caller's responsibility to evaluate |
| 5871 | * the response. |
| 5872 | * |
| 5873 | * Returns: |
| 5874 | * -Error: Error value describes the condition found. |
| 5875 | * 0: if successful |
| 5876 | **/ |
| 5877 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5878 | 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] | 5879 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5880 | { |
| 5881 | int rc = 0; |
| 5882 | uint32_t req_len; |
| 5883 | uint32_t emb_len; |
| 5884 | uint32_t alloc_len, mbox_tmo; |
| 5885 | |
| 5886 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5887 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5888 | |
| 5889 | /* |
| 5890 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5891 | * accounts for extents-specific word. |
| 5892 | */ |
| 5893 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5894 | sizeof(uint32_t); |
| 5895 | |
| 5896 | /* |
| 5897 | * Presume the allocation and response will fit into an embedded |
| 5898 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5899 | */ |
| 5900 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5901 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5902 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5903 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5904 | sizeof(uint32_t); |
| 5905 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5906 | } |
| 5907 | |
| 5908 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5909 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5910 | req_len, *emb); |
| 5911 | if (alloc_len < req_len) { |
| 5912 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5913 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5914 | "less than the requested DMA memory " |
| 5915 | "size (x%x)\n", alloc_len, req_len); |
| 5916 | return -ENOMEM; |
| 5917 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5918 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5919 | if (unlikely(rc)) |
| 5920 | return -EIO; |
| 5921 | |
| 5922 | if (!phba->sli4_hba.intr_enable) |
| 5923 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5924 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5925 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5926 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5927 | } |
| 5928 | |
| 5929 | if (unlikely(rc)) |
| 5930 | rc = -EIO; |
| 5931 | return rc; |
| 5932 | } |
| 5933 | |
| 5934 | /** |
| 5935 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5936 | * @phba: Pointer to HBA context object. |
| 5937 | * @type: The resource extent type to allocate. |
| 5938 | * |
| 5939 | * This function allocates the number of elements for the specified |
| 5940 | * resource type. |
| 5941 | **/ |
| 5942 | static int |
| 5943 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5944 | { |
| 5945 | bool emb = false; |
| 5946 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5947 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5948 | uint16_t *ids; |
| 5949 | int i, rc; |
| 5950 | unsigned long longs; |
| 5951 | unsigned long *bmask; |
| 5952 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5953 | LPFC_MBOXQ_t *mbox; |
| 5954 | uint32_t length; |
| 5955 | struct lpfc_id_range *id_array = NULL; |
| 5956 | void *virtaddr = NULL; |
| 5957 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5958 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5959 | struct list_head *ext_blk_list; |
| 5960 | |
| 5961 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5962 | &rsrc_cnt, |
| 5963 | &rsrc_size); |
| 5964 | if (unlikely(rc)) |
| 5965 | return -EIO; |
| 5966 | |
| 5967 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5968 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5969 | "3009 No available Resource Extents " |
| 5970 | "for resource type 0x%x: Count: 0x%x, " |
| 5971 | "Size 0x%x\n", type, rsrc_cnt, |
| 5972 | rsrc_size); |
| 5973 | return -ENOMEM; |
| 5974 | } |
| 5975 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5976 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5977 | "2903 Post resource extents type-0x%x: " |
| 5978 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5979 | |
| 5980 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5981 | if (!mbox) |
| 5982 | return -ENOMEM; |
| 5983 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5984 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5985 | if (unlikely(rc)) { |
| 5986 | rc = -EIO; |
| 5987 | goto err_exit; |
| 5988 | } |
| 5989 | |
| 5990 | /* |
| 5991 | * Figure out where the response is located. Then get local pointers |
| 5992 | * to the response data. The port does not guarantee to respond to |
| 5993 | * all extents counts request so update the local variable with the |
| 5994 | * allocated count from the port. |
| 5995 | */ |
| 5996 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5997 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5998 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5999 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6000 | } else { |
| 6001 | virtaddr = mbox->sge_array->addr[0]; |
| 6002 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6003 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6004 | id_array = &n_rsrc->id; |
| 6005 | } |
| 6006 | |
| 6007 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6008 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 6009 | |
| 6010 | /* |
| 6011 | * Based on the resource size and count, correct the base and max |
| 6012 | * resource values. |
| 6013 | */ |
| 6014 | length = sizeof(struct lpfc_rsrc_blks); |
| 6015 | switch (type) { |
| 6016 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6017 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6018 | sizeof(unsigned long), |
| 6019 | GFP_KERNEL); |
| 6020 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6021 | rc = -ENOMEM; |
| 6022 | goto err_exit; |
| 6023 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6024 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6025 | sizeof(uint16_t), |
| 6026 | GFP_KERNEL); |
| 6027 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6028 | kfree(phba->sli4_hba.rpi_bmask); |
| 6029 | rc = -ENOMEM; |
| 6030 | goto err_exit; |
| 6031 | } |
| 6032 | |
| 6033 | /* |
| 6034 | * The next_rpi was initialized with the maximum available |
| 6035 | * count but the port may allocate a smaller number. Catch |
| 6036 | * that case and update the next_rpi. |
| 6037 | */ |
| 6038 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 6039 | |
| 6040 | /* Initialize local ptrs for common extent processing later. */ |
| 6041 | bmask = phba->sli4_hba.rpi_bmask; |
| 6042 | ids = phba->sli4_hba.rpi_ids; |
| 6043 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6044 | break; |
| 6045 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6046 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6047 | GFP_KERNEL); |
| 6048 | if (unlikely(!phba->vpi_bmask)) { |
| 6049 | rc = -ENOMEM; |
| 6050 | goto err_exit; |
| 6051 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6052 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6053 | GFP_KERNEL); |
| 6054 | if (unlikely(!phba->vpi_ids)) { |
| 6055 | kfree(phba->vpi_bmask); |
| 6056 | rc = -ENOMEM; |
| 6057 | goto err_exit; |
| 6058 | } |
| 6059 | |
| 6060 | /* Initialize local ptrs for common extent processing later. */ |
| 6061 | bmask = phba->vpi_bmask; |
| 6062 | ids = phba->vpi_ids; |
| 6063 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 6064 | break; |
| 6065 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6066 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6067 | sizeof(unsigned long), |
| 6068 | GFP_KERNEL); |
| 6069 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6070 | rc = -ENOMEM; |
| 6071 | goto err_exit; |
| 6072 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6073 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6074 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6075 | sizeof(uint16_t), |
| 6076 | GFP_KERNEL); |
| 6077 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6078 | kfree(phba->sli4_hba.xri_bmask); |
| 6079 | rc = -ENOMEM; |
| 6080 | goto err_exit; |
| 6081 | } |
| 6082 | |
| 6083 | /* Initialize local ptrs for common extent processing later. */ |
| 6084 | bmask = phba->sli4_hba.xri_bmask; |
| 6085 | ids = phba->sli4_hba.xri_ids; |
| 6086 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6087 | break; |
| 6088 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6089 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6090 | sizeof(unsigned long), |
| 6091 | GFP_KERNEL); |
| 6092 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6093 | rc = -ENOMEM; |
| 6094 | goto err_exit; |
| 6095 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6096 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6097 | sizeof(uint16_t), |
| 6098 | GFP_KERNEL); |
| 6099 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6100 | kfree(phba->sli4_hba.vfi_bmask); |
| 6101 | rc = -ENOMEM; |
| 6102 | goto err_exit; |
| 6103 | } |
| 6104 | |
| 6105 | /* Initialize local ptrs for common extent processing later. */ |
| 6106 | bmask = phba->sli4_hba.vfi_bmask; |
| 6107 | ids = phba->sli4_hba.vfi_ids; |
| 6108 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6109 | break; |
| 6110 | default: |
| 6111 | /* Unsupported Opcode. Fail call. */ |
| 6112 | id_array = NULL; |
| 6113 | bmask = NULL; |
| 6114 | ids = NULL; |
| 6115 | ext_blk_list = NULL; |
| 6116 | goto err_exit; |
| 6117 | } |
| 6118 | |
| 6119 | /* |
| 6120 | * Complete initializing the extent configuration with the |
| 6121 | * allocated ids assigned to this function. The bitmask serves |
| 6122 | * as an index into the array and manages the available ids. The |
| 6123 | * array just stores the ids communicated to the port via the wqes. |
| 6124 | */ |
| 6125 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 6126 | if ((i % 2) == 0) |
| 6127 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 6128 | &id_array[k]); |
| 6129 | else |
| 6130 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 6131 | &id_array[k]); |
| 6132 | |
| 6133 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 6134 | if (unlikely(!rsrc_blks)) { |
| 6135 | rc = -ENOMEM; |
| 6136 | kfree(bmask); |
| 6137 | kfree(ids); |
| 6138 | goto err_exit; |
| 6139 | } |
| 6140 | rsrc_blks->rsrc_start = rsrc_id; |
| 6141 | rsrc_blks->rsrc_size = rsrc_size; |
| 6142 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6143 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6144 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6145 | phba->sli4_hba.io_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6146 | lpfc_sli4_get_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6147 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6148 | |
| 6149 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6150 | ids[j] = rsrc_id; |
| 6151 | rsrc_id++; |
| 6152 | j++; |
| 6153 | } |
| 6154 | /* Entire word processed. Get next word.*/ |
| 6155 | if ((i % 2) == 1) |
| 6156 | k++; |
| 6157 | } |
| 6158 | err_exit: |
| 6159 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6160 | return rc; |
| 6161 | } |
| 6162 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6163 | |
| 6164 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6165 | /** |
| 6166 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6167 | * @phba: Pointer to HBA context object. |
| 6168 | * @type: the extent's type. |
| 6169 | * |
| 6170 | * This function deallocates all extents of a particular resource type. |
| 6171 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6172 | * is the caller's responsibility to release all kernel memory resources. |
| 6173 | **/ |
| 6174 | static int |
| 6175 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6176 | { |
| 6177 | int rc; |
| 6178 | uint32_t length, mbox_tmo = 0; |
| 6179 | LPFC_MBOXQ_t *mbox; |
| 6180 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6181 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6182 | |
| 6183 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6184 | if (!mbox) |
| 6185 | return -ENOMEM; |
| 6186 | |
| 6187 | /* |
| 6188 | * This function sends an embedded mailbox because it only sends the |
| 6189 | * the resource type. All extents of this type are released by the |
| 6190 | * port. |
| 6191 | */ |
| 6192 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6193 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6194 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6195 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6196 | length, LPFC_SLI4_MBX_EMBED); |
| 6197 | |
| 6198 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6199 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6200 | LPFC_SLI4_MBX_EMBED); |
| 6201 | if (unlikely(rc)) { |
| 6202 | rc = -EIO; |
| 6203 | goto out_free_mbox; |
| 6204 | } |
| 6205 | if (!phba->sli4_hba.intr_enable) |
| 6206 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6207 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6208 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6209 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6210 | } |
| 6211 | if (unlikely(rc)) { |
| 6212 | rc = -EIO; |
| 6213 | goto out_free_mbox; |
| 6214 | } |
| 6215 | |
| 6216 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6217 | if (bf_get(lpfc_mbox_hdr_status, |
| 6218 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 6219 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6220 | "2919 Failed to release resource extents " |
| 6221 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6222 | "Resource memory not released.\n", |
| 6223 | type, |
| 6224 | bf_get(lpfc_mbox_hdr_status, |
| 6225 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6226 | bf_get(lpfc_mbox_hdr_add_status, |
| 6227 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6228 | rc = -EIO; |
| 6229 | goto out_free_mbox; |
| 6230 | } |
| 6231 | |
| 6232 | /* Release kernel memory resources for the specific type. */ |
| 6233 | switch (type) { |
| 6234 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6235 | kfree(phba->vpi_bmask); |
| 6236 | kfree(phba->vpi_ids); |
| 6237 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6238 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6239 | &phba->lpfc_vpi_blk_list, list) { |
| 6240 | list_del_init(&rsrc_blk->list); |
| 6241 | kfree(rsrc_blk); |
| 6242 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6243 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6244 | break; |
| 6245 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6246 | kfree(phba->sli4_hba.xri_bmask); |
| 6247 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6248 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6249 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6250 | list_del_init(&rsrc_blk->list); |
| 6251 | kfree(rsrc_blk); |
| 6252 | } |
| 6253 | break; |
| 6254 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6255 | kfree(phba->sli4_hba.vfi_bmask); |
| 6256 | kfree(phba->sli4_hba.vfi_ids); |
| 6257 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6258 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6259 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6260 | list_del_init(&rsrc_blk->list); |
| 6261 | kfree(rsrc_blk); |
| 6262 | } |
| 6263 | break; |
| 6264 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6265 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6266 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6267 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6268 | list_del_init(&rsrc_blk->list); |
| 6269 | kfree(rsrc_blk); |
| 6270 | } |
| 6271 | break; |
| 6272 | default: |
| 6273 | break; |
| 6274 | } |
| 6275 | |
| 6276 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6277 | |
| 6278 | out_free_mbox: |
| 6279 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6280 | return rc; |
| 6281 | } |
| 6282 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6283 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6284 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6285 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6286 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6287 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6288 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6289 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6290 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6291 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6292 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6293 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6294 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6295 | switch (feature) { |
| 6296 | case LPFC_SET_UE_RECOVERY: |
| 6297 | bf_set(lpfc_mbx_set_feature_UER, |
| 6298 | &mbox->u.mqe.un.set_feature, 1); |
| 6299 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6300 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6301 | break; |
| 6302 | case LPFC_SET_MDS_DIAGS: |
| 6303 | bf_set(lpfc_mbx_set_feature_mds, |
| 6304 | &mbox->u.mqe.un.set_feature, 1); |
| 6305 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6306 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6307 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6308 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6309 | break; |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 6310 | case LPFC_SET_DUAL_DUMP: |
| 6311 | bf_set(lpfc_mbx_set_feature_dd, |
| 6312 | &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP); |
| 6313 | bf_set(lpfc_mbx_set_feature_ddquery, |
| 6314 | &mbox->u.mqe.un.set_feature, 0); |
| 6315 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP; |
| 6316 | mbox->u.mqe.un.set_feature.param_len = 4; |
| 6317 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6318 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6319 | |
| 6320 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6321 | } |
| 6322 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6323 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6324 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6325 | * @phba: Pointer to HBA context object. |
| 6326 | * |
| 6327 | * Disable FW logging into host memory on the adapter. To |
| 6328 | * be done before reading logs from the host memory. |
| 6329 | **/ |
| 6330 | void |
| 6331 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6332 | { |
| 6333 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6334 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6335 | spin_lock_irq(&phba->hbalock); |
| 6336 | ras_fwlog->state = INACTIVE; |
| 6337 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6338 | |
| 6339 | /* Disable FW logging to host memory */ |
| 6340 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6341 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6342 | |
| 6343 | /* Wait 10ms for firmware to stop using DMA buffer */ |
| 6344 | usleep_range(10 * 1000, 20 * 1000); |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6348 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6349 | * @phba: Pointer to HBA context object. |
| 6350 | * |
| 6351 | * This function is called to free memory allocated for RAS FW logging |
| 6352 | * support in the driver. |
| 6353 | **/ |
| 6354 | void |
| 6355 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6356 | { |
| 6357 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6358 | struct lpfc_dmabuf *dmabuf, *next; |
| 6359 | |
| 6360 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6361 | list_for_each_entry_safe(dmabuf, next, |
| 6362 | &ras_fwlog->fwlog_buff_list, |
| 6363 | list) { |
| 6364 | list_del(&dmabuf->list); |
| 6365 | dma_free_coherent(&phba->pcidev->dev, |
| 6366 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6367 | dmabuf->virt, dmabuf->phys); |
| 6368 | kfree(dmabuf); |
| 6369 | } |
| 6370 | } |
| 6371 | |
| 6372 | if (ras_fwlog->lwpd.virt) { |
| 6373 | dma_free_coherent(&phba->pcidev->dev, |
| 6374 | sizeof(uint32_t) * 2, |
| 6375 | ras_fwlog->lwpd.virt, |
| 6376 | ras_fwlog->lwpd.phys); |
| 6377 | ras_fwlog->lwpd.virt = NULL; |
| 6378 | } |
| 6379 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6380 | spin_lock_irq(&phba->hbalock); |
| 6381 | ras_fwlog->state = INACTIVE; |
| 6382 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | /** |
| 6386 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6387 | * @phba: Pointer to HBA context object. |
| 6388 | * @fwlog_buff_count: Count of buffers to be created. |
| 6389 | * |
| 6390 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6391 | * to update FW log is posted to the adapter. |
| 6392 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6393 | * Size of each buffer posted to FW is 64K. |
| 6394 | **/ |
| 6395 | |
| 6396 | static int |
| 6397 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6398 | uint32_t fwlog_buff_count) |
| 6399 | { |
| 6400 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6401 | struct lpfc_dmabuf *dmabuf; |
| 6402 | int rc = 0, i = 0; |
| 6403 | |
| 6404 | /* Initialize List */ |
| 6405 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6406 | |
| 6407 | /* Allocate memory for the LWPD */ |
| 6408 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6409 | sizeof(uint32_t) * 2, |
| 6410 | &ras_fwlog->lwpd.phys, |
| 6411 | GFP_KERNEL); |
| 6412 | if (!ras_fwlog->lwpd.virt) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6414 | "6185 LWPD Memory Alloc Failed\n"); |
| 6415 | |
| 6416 | return -ENOMEM; |
| 6417 | } |
| 6418 | |
| 6419 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6420 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6421 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6422 | GFP_KERNEL); |
| 6423 | if (!dmabuf) { |
| 6424 | rc = -ENOMEM; |
| 6425 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6426 | "6186 Memory Alloc failed FW logging"); |
| 6427 | goto free_mem; |
| 6428 | } |
| 6429 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6430 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6431 | LPFC_RAS_MAX_ENTRY_SIZE, |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6432 | &dmabuf->phys, GFP_KERNEL); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6433 | if (!dmabuf->virt) { |
| 6434 | kfree(dmabuf); |
| 6435 | rc = -ENOMEM; |
| 6436 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6437 | "6187 DMA Alloc Failed FW logging"); |
| 6438 | goto free_mem; |
| 6439 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6440 | dmabuf->buffer_tag = i; |
| 6441 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6442 | } |
| 6443 | |
| 6444 | free_mem: |
| 6445 | if (rc) |
| 6446 | lpfc_sli4_ras_dma_free(phba); |
| 6447 | |
| 6448 | return rc; |
| 6449 | } |
| 6450 | |
| 6451 | /** |
| 6452 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6453 | * @phba: pointer to lpfc hba data structure. |
| 6454 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 6455 | * |
| 6456 | * Completion handler for driver's RAS MBX command to the device. |
| 6457 | **/ |
| 6458 | static void |
| 6459 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6460 | { |
| 6461 | MAILBOX_t *mb; |
| 6462 | union lpfc_sli4_cfg_shdr *shdr; |
| 6463 | uint32_t shdr_status, shdr_add_status; |
| 6464 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6465 | |
| 6466 | mb = &pmb->u.mb; |
| 6467 | |
| 6468 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6469 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6470 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6471 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6472 | |
| 6473 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6474 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6475 | "6188 FW LOG mailbox " |
| 6476 | "completed with status x%x add_status x%x," |
| 6477 | " mbx status x%x\n", |
| 6478 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6479 | |
| 6480 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6481 | goto disable_ras; |
| 6482 | } |
| 6483 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6484 | spin_lock_irq(&phba->hbalock); |
| 6485 | ras_fwlog->state = ACTIVE; |
| 6486 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6487 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6488 | |
| 6489 | return; |
| 6490 | |
| 6491 | disable_ras: |
| 6492 | /* Free RAS DMA memory */ |
| 6493 | lpfc_sli4_ras_dma_free(phba); |
| 6494 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6495 | } |
| 6496 | |
| 6497 | /** |
| 6498 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6499 | * @phba: pointer to lpfc hba data structure. |
| 6500 | * @fwlog_level: Logging verbosity level. |
| 6501 | * @fwlog_enable: Enable/Disable logging. |
| 6502 | * |
| 6503 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6504 | * memory. |
| 6505 | **/ |
| 6506 | int |
| 6507 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6508 | uint32_t fwlog_level, |
| 6509 | uint32_t fwlog_enable) |
| 6510 | { |
| 6511 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6512 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6513 | struct lpfc_dmabuf *dmabuf; |
| 6514 | LPFC_MBOXQ_t *mbox; |
| 6515 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6516 | int rc = 0; |
| 6517 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6518 | spin_lock_irq(&phba->hbalock); |
| 6519 | ras_fwlog->state = INACTIVE; |
| 6520 | spin_unlock_irq(&phba->hbalock); |
| 6521 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6522 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6523 | phba->cfg_ras_fwlog_buffsize); |
| 6524 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6525 | |
| 6526 | /* |
| 6527 | * If re-enabling FW logging support use earlier allocated |
| 6528 | * DMA buffers while posting MBX command. |
| 6529 | **/ |
| 6530 | if (!ras_fwlog->lwpd.virt) { |
| 6531 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6532 | if (rc) { |
| 6533 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6534 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6535 | return rc; |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | /* Setup Mailbox command */ |
| 6540 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6541 | if (!mbox) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6542 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6543 | "6190 RAS MBX Alloc Failed"); |
| 6544 | rc = -ENOMEM; |
| 6545 | goto mem_free; |
| 6546 | } |
| 6547 | |
| 6548 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6549 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6550 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6551 | |
| 6552 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6553 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6554 | len, LPFC_SLI4_MBX_EMBED); |
| 6555 | |
| 6556 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6557 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6558 | fwlog_enable); |
| 6559 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6560 | ras_fwlog->fw_loglevel); |
| 6561 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6562 | ras_fwlog->fw_buffcount); |
| 6563 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6564 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6565 | |
| 6566 | /* Update DMA buffer address */ |
| 6567 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6568 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6569 | |
| 6570 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6571 | putPaddrLow(dmabuf->phys); |
| 6572 | |
| 6573 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 6574 | putPaddrHigh(dmabuf->phys); |
| 6575 | } |
| 6576 | |
| 6577 | /* Update LPWD address */ |
| 6578 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 6579 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 6580 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6581 | spin_lock_irq(&phba->hbalock); |
| 6582 | ras_fwlog->state = REG_INPROGRESS; |
| 6583 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6584 | mbox->vport = phba->pport; |
| 6585 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 6586 | |
| 6587 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6588 | |
| 6589 | if (rc == MBX_NOT_FINISHED) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6590 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6591 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6592 | "status %d mbxStatus : x%x", rc, |
| 6593 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 6594 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6595 | rc = -EIO; |
| 6596 | goto mem_free; |
| 6597 | } else |
| 6598 | rc = 0; |
| 6599 | mem_free: |
| 6600 | if (rc) |
| 6601 | lpfc_sli4_ras_dma_free(phba); |
| 6602 | |
| 6603 | return rc; |
| 6604 | } |
| 6605 | |
| 6606 | /** |
| 6607 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 6608 | * @phba: Pointer to HBA context object. |
| 6609 | * |
| 6610 | * Check if RAS is supported on the adapter and initialize it. |
| 6611 | **/ |
| 6612 | void |
| 6613 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 6614 | { |
| 6615 | /* Check RAS FW Log needs to be enabled or not */ |
| 6616 | if (lpfc_check_fwlog_support(phba)) |
| 6617 | return; |
| 6618 | |
| 6619 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 6620 | LPFC_RAS_ENABLE_LOGGING); |
| 6621 | } |
| 6622 | |
| 6623 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6624 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6625 | * @phba: Pointer to HBA context object. |
| 6626 | * |
| 6627 | * This function allocates all SLI4 resource identifiers. |
| 6628 | **/ |
| 6629 | int |
| 6630 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6631 | { |
| 6632 | int i, rc, error = 0; |
| 6633 | uint16_t count, base; |
| 6634 | unsigned long longs; |
| 6635 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6636 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6637 | 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] | 6638 | if (phba->sli4_hba.extents_in_use) { |
| 6639 | /* |
| 6640 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6641 | * resource extent count must be read and allocated before |
| 6642 | * provisioning the resource id arrays. |
| 6643 | */ |
| 6644 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6645 | LPFC_IDX_RSRC_RDY) { |
| 6646 | /* |
| 6647 | * Extent-based resources are set - the driver could |
| 6648 | * be in a port reset. Figure out if any corrective |
| 6649 | * actions need to be taken. |
| 6650 | */ |
| 6651 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6652 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6653 | if (rc != 0) |
| 6654 | error++; |
| 6655 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6656 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6657 | if (rc != 0) |
| 6658 | error++; |
| 6659 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6660 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6661 | if (rc != 0) |
| 6662 | error++; |
| 6663 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6664 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6665 | if (rc != 0) |
| 6666 | error++; |
| 6667 | |
| 6668 | /* |
| 6669 | * It's possible that the number of resources |
| 6670 | * provided to this port instance changed between |
| 6671 | * resets. Detect this condition and reallocate |
| 6672 | * resources. Otherwise, there is no action. |
| 6673 | */ |
| 6674 | if (error) { |
| 6675 | lpfc_printf_log(phba, KERN_INFO, |
| 6676 | LOG_MBOX | LOG_INIT, |
| 6677 | "2931 Detected extent resource " |
| 6678 | "change. Reallocating all " |
| 6679 | "extents.\n"); |
| 6680 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6681 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6682 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6683 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6684 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6685 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6686 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6687 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6688 | } else |
| 6689 | return 0; |
| 6690 | } |
| 6691 | |
| 6692 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6693 | if (unlikely(rc)) |
| 6694 | goto err_exit; |
| 6695 | |
| 6696 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6697 | if (unlikely(rc)) |
| 6698 | goto err_exit; |
| 6699 | |
| 6700 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6701 | if (unlikely(rc)) |
| 6702 | goto err_exit; |
| 6703 | |
| 6704 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6705 | if (unlikely(rc)) |
| 6706 | goto err_exit; |
| 6707 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6708 | LPFC_IDX_RSRC_RDY); |
| 6709 | return rc; |
| 6710 | } else { |
| 6711 | /* |
| 6712 | * The port does not support resource extents. The XRI, VPI, |
| 6713 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6714 | * Just allocate the bitmasks and provision the resource id |
| 6715 | * arrays. If a port reset is active, the resources don't |
| 6716 | * need any action - just exit. |
| 6717 | */ |
| 6718 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6719 | LPFC_IDX_RSRC_RDY) { |
| 6720 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6721 | lpfc_sli4_remove_rpis(phba); |
| 6722 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6723 | /* RPIs. */ |
| 6724 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6725 | if (count <= 0) { |
| 6726 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6727 | "3279 Invalid provisioning of " |
| 6728 | "rpi:%d\n", count); |
| 6729 | rc = -EINVAL; |
| 6730 | goto err_exit; |
| 6731 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6732 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6733 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6734 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6735 | sizeof(unsigned long), |
| 6736 | GFP_KERNEL); |
| 6737 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6738 | rc = -ENOMEM; |
| 6739 | goto err_exit; |
| 6740 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6741 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6742 | GFP_KERNEL); |
| 6743 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6744 | rc = -ENOMEM; |
| 6745 | goto free_rpi_bmask; |
| 6746 | } |
| 6747 | |
| 6748 | for (i = 0; i < count; i++) |
| 6749 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6750 | |
| 6751 | /* VPIs. */ |
| 6752 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6753 | if (count <= 0) { |
| 6754 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6755 | "3280 Invalid provisioning of " |
| 6756 | "vpi:%d\n", count); |
| 6757 | rc = -EINVAL; |
| 6758 | goto free_rpi_ids; |
| 6759 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6760 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6761 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6762 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6763 | GFP_KERNEL); |
| 6764 | if (unlikely(!phba->vpi_bmask)) { |
| 6765 | rc = -ENOMEM; |
| 6766 | goto free_rpi_ids; |
| 6767 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6768 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6769 | GFP_KERNEL); |
| 6770 | if (unlikely(!phba->vpi_ids)) { |
| 6771 | rc = -ENOMEM; |
| 6772 | goto free_vpi_bmask; |
| 6773 | } |
| 6774 | |
| 6775 | for (i = 0; i < count; i++) |
| 6776 | phba->vpi_ids[i] = base + i; |
| 6777 | |
| 6778 | /* XRIs. */ |
| 6779 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6780 | if (count <= 0) { |
| 6781 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6782 | "3281 Invalid provisioning of " |
| 6783 | "xri:%d\n", count); |
| 6784 | rc = -EINVAL; |
| 6785 | goto free_vpi_ids; |
| 6786 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6787 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6788 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6789 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6790 | sizeof(unsigned long), |
| 6791 | GFP_KERNEL); |
| 6792 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6793 | rc = -ENOMEM; |
| 6794 | goto free_vpi_ids; |
| 6795 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6796 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6797 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6798 | GFP_KERNEL); |
| 6799 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6800 | rc = -ENOMEM; |
| 6801 | goto free_xri_bmask; |
| 6802 | } |
| 6803 | |
| 6804 | for (i = 0; i < count; i++) |
| 6805 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6806 | |
| 6807 | /* VFIs. */ |
| 6808 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6809 | if (count <= 0) { |
| 6810 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6811 | "3282 Invalid provisioning of " |
| 6812 | "vfi:%d\n", count); |
| 6813 | rc = -EINVAL; |
| 6814 | goto free_xri_ids; |
| 6815 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6816 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6817 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6818 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6819 | sizeof(unsigned long), |
| 6820 | GFP_KERNEL); |
| 6821 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6822 | rc = -ENOMEM; |
| 6823 | goto free_xri_ids; |
| 6824 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6825 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6826 | GFP_KERNEL); |
| 6827 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6828 | rc = -ENOMEM; |
| 6829 | goto free_vfi_bmask; |
| 6830 | } |
| 6831 | |
| 6832 | for (i = 0; i < count; i++) |
| 6833 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6834 | |
| 6835 | /* |
| 6836 | * Mark all resources ready. An HBA reset doesn't need |
| 6837 | * to reset the initialization. |
| 6838 | */ |
| 6839 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6840 | LPFC_IDX_RSRC_RDY); |
| 6841 | return 0; |
| 6842 | } |
| 6843 | |
| 6844 | free_vfi_bmask: |
| 6845 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6846 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6847 | free_xri_ids: |
| 6848 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6849 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6850 | free_xri_bmask: |
| 6851 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6852 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6853 | free_vpi_ids: |
| 6854 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6855 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6856 | free_vpi_bmask: |
| 6857 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6858 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6859 | free_rpi_ids: |
| 6860 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6861 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6862 | free_rpi_bmask: |
| 6863 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6864 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6865 | err_exit: |
| 6866 | return rc; |
| 6867 | } |
| 6868 | |
| 6869 | /** |
| 6870 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6871 | * @phba: Pointer to HBA context object. |
| 6872 | * |
| 6873 | * This function allocates the number of elements for the specified |
| 6874 | * resource type. |
| 6875 | **/ |
| 6876 | int |
| 6877 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6878 | { |
| 6879 | if (phba->sli4_hba.extents_in_use) { |
| 6880 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6881 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6882 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6883 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6884 | } else { |
| 6885 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6886 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6887 | kfree(phba->vpi_ids); |
| 6888 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6889 | kfree(phba->sli4_hba.xri_bmask); |
| 6890 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6891 | kfree(phba->sli4_hba.vfi_bmask); |
| 6892 | kfree(phba->sli4_hba.vfi_ids); |
| 6893 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6894 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6895 | } |
| 6896 | |
| 6897 | return 0; |
| 6898 | } |
| 6899 | |
| 6900 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6901 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6902 | * @phba: Pointer to HBA context object. |
| 6903 | * @type: The resource extent type. |
| 6904 | * @extnt_count: buffer to hold port extent count response |
| 6905 | * @extnt_size: buffer to hold port extent size response. |
| 6906 | * |
| 6907 | * This function calls the port to read the host allocated extents |
| 6908 | * for a particular type. |
| 6909 | **/ |
| 6910 | int |
| 6911 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6912 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6913 | { |
| 6914 | bool emb; |
| 6915 | int rc = 0; |
| 6916 | uint16_t curr_blks = 0; |
| 6917 | uint32_t req_len, emb_len; |
| 6918 | uint32_t alloc_len, mbox_tmo; |
| 6919 | struct list_head *blk_list_head; |
| 6920 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6921 | LPFC_MBOXQ_t *mbox; |
| 6922 | void *virtaddr = NULL; |
| 6923 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6924 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6925 | union lpfc_sli4_cfg_shdr *shdr; |
| 6926 | |
| 6927 | switch (type) { |
| 6928 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6929 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6930 | break; |
| 6931 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6932 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6933 | break; |
| 6934 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6935 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6936 | break; |
| 6937 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6938 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6939 | break; |
| 6940 | default: |
| 6941 | return -EIO; |
| 6942 | } |
| 6943 | |
| 6944 | /* Count the number of extents currently allocatd for this type. */ |
| 6945 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6946 | if (curr_blks == 0) { |
| 6947 | /* |
| 6948 | * The GET_ALLOCATED mailbox does not return the size, |
| 6949 | * just the count. The size should be just the size |
| 6950 | * stored in the current allocated block and all sizes |
| 6951 | * for an extent type are the same so set the return |
| 6952 | * value now. |
| 6953 | */ |
| 6954 | *extnt_size = rsrc_blk->rsrc_size; |
| 6955 | } |
| 6956 | curr_blks++; |
| 6957 | } |
| 6958 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6959 | /* |
| 6960 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6961 | * accounts for extents-specific word. |
| 6962 | */ |
| 6963 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6964 | sizeof(uint32_t); |
| 6965 | |
| 6966 | /* |
| 6967 | * Presume the allocation and response will fit into an embedded |
| 6968 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6969 | */ |
| 6970 | emb = LPFC_SLI4_MBX_EMBED; |
| 6971 | req_len = emb_len; |
| 6972 | if (req_len > emb_len) { |
| 6973 | req_len = curr_blks * sizeof(uint16_t) + |
| 6974 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6975 | sizeof(uint32_t); |
| 6976 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6977 | } |
| 6978 | |
| 6979 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6980 | if (!mbox) |
| 6981 | return -ENOMEM; |
| 6982 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6983 | |
| 6984 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6985 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6986 | req_len, emb); |
| 6987 | if (alloc_len < req_len) { |
| 6988 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6989 | "2983 Allocated DMA memory size (x%x) is " |
| 6990 | "less than the requested DMA memory " |
| 6991 | "size (x%x)\n", alloc_len, req_len); |
| 6992 | rc = -ENOMEM; |
| 6993 | goto err_exit; |
| 6994 | } |
| 6995 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6996 | if (unlikely(rc)) { |
| 6997 | rc = -EIO; |
| 6998 | goto err_exit; |
| 6999 | } |
| 7000 | |
| 7001 | if (!phba->sli4_hba.intr_enable) |
| 7002 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 7003 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7004 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7005 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 7006 | } |
| 7007 | |
| 7008 | if (unlikely(rc)) { |
| 7009 | rc = -EIO; |
| 7010 | goto err_exit; |
| 7011 | } |
| 7012 | |
| 7013 | /* |
| 7014 | * Figure out where the response is located. Then get local pointers |
| 7015 | * to the response data. The port does not guarantee to respond to |
| 7016 | * all extents counts request so update the local variable with the |
| 7017 | * allocated count from the port. |
| 7018 | */ |
| 7019 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 7020 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 7021 | shdr = &rsrc_ext->header.cfg_shdr; |
| 7022 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 7023 | } else { |
| 7024 | virtaddr = mbox->sge_array->addr[0]; |
| 7025 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 7026 | shdr = &n_rsrc->cfg_shdr; |
| 7027 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 7028 | } |
| 7029 | |
| 7030 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 7031 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 7032 | "2984 Failed to read allocated resources " |
| 7033 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 7034 | type, |
| 7035 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 7036 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 7037 | rc = -EIO; |
| 7038 | goto err_exit; |
| 7039 | } |
| 7040 | err_exit: |
| 7041 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 7042 | return rc; |
| 7043 | } |
| 7044 | |
| 7045 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 7046 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7047 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7048 | * @pring: Pointer to driver SLI ring object. |
| 7049 | * @sgl_list: linked link of sgl buffers to post |
| 7050 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7051 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7052 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7053 | * repost them to the port by using SGL block post. This is needed after a |
| 7054 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7055 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 7056 | * 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] | 7057 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 7058 | * mailbox command for posting. |
| 7059 | * |
| 7060 | * Returns: 0 = success, non-zero failure. |
| 7061 | **/ |
| 7062 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7063 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 7064 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7065 | { |
| 7066 | struct lpfc_sglq *sglq_entry = NULL; |
| 7067 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 7068 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7069 | int status, total_cnt; |
| 7070 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7071 | int last_xritag = NO_XRI; |
| 7072 | LIST_HEAD(prep_sgl_list); |
| 7073 | LIST_HEAD(blck_sgl_list); |
| 7074 | LIST_HEAD(allc_sgl_list); |
| 7075 | LIST_HEAD(post_sgl_list); |
| 7076 | LIST_HEAD(free_sgl_list); |
| 7077 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7078 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7079 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7080 | list_splice_init(sgl_list, &allc_sgl_list); |
| 7081 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7082 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7083 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7084 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7085 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 7086 | &allc_sgl_list, list) { |
| 7087 | list_del_init(&sglq_entry->list); |
| 7088 | block_cnt++; |
| 7089 | if ((last_xritag != NO_XRI) && |
| 7090 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 7091 | /* a hole in xri block, form a sgl posting block */ |
| 7092 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 7093 | post_cnt = block_cnt - 1; |
| 7094 | /* prepare list for next posting block */ |
| 7095 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 7096 | block_cnt = 1; |
| 7097 | } else { |
| 7098 | /* prepare list for next posting block */ |
| 7099 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 7100 | /* enough sgls for non-embed sgl mbox command */ |
| 7101 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 7102 | list_splice_init(&prep_sgl_list, |
| 7103 | &blck_sgl_list); |
| 7104 | post_cnt = block_cnt; |
| 7105 | block_cnt = 0; |
| 7106 | } |
| 7107 | } |
| 7108 | num_posted++; |
| 7109 | |
| 7110 | /* keep track of last sgl's xritag */ |
| 7111 | last_xritag = sglq_entry->sli4_xritag; |
| 7112 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7113 | /* end of repost sgl list condition for buffers */ |
| 7114 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7115 | if (post_cnt == 0) { |
| 7116 | list_splice_init(&prep_sgl_list, |
| 7117 | &blck_sgl_list); |
| 7118 | post_cnt = block_cnt; |
| 7119 | } else if (block_cnt == 1) { |
| 7120 | status = lpfc_sli4_post_sgl(phba, |
| 7121 | sglq_entry->phys, 0, |
| 7122 | sglq_entry->sli4_xritag); |
| 7123 | if (!status) { |
| 7124 | /* successful, put sgl to posted list */ |
| 7125 | list_add_tail(&sglq_entry->list, |
| 7126 | &post_sgl_list); |
| 7127 | } else { |
| 7128 | /* Failure, put sgl to free list */ |
| 7129 | lpfc_printf_log(phba, KERN_WARNING, |
| 7130 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7131 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7132 | "sgl, xritag:x%x\n", |
| 7133 | sglq_entry->sli4_xritag); |
| 7134 | list_add_tail(&sglq_entry->list, |
| 7135 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7136 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7137 | } |
| 7138 | } |
| 7139 | } |
| 7140 | |
| 7141 | /* continue until a nembed page worth of sgls */ |
| 7142 | if (post_cnt == 0) |
| 7143 | continue; |
| 7144 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7145 | /* post the buffer list sgls as a block */ |
| 7146 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 7147 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7148 | |
| 7149 | if (!status) { |
| 7150 | /* success, put sgl list to posted sgl list */ |
| 7151 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 7152 | } else { |
| 7153 | /* Failure, put sgl list to free sgl list */ |
| 7154 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 7155 | struct lpfc_sglq, |
| 7156 | list); |
| 7157 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7158 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7159 | "xritag:x%x-x%x\n", |
| 7160 | sglq_entry_first->sli4_xritag, |
| 7161 | (sglq_entry_first->sli4_xritag + |
| 7162 | post_cnt - 1)); |
| 7163 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7164 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7165 | } |
| 7166 | |
| 7167 | /* don't reset xirtag due to hole in xri block */ |
| 7168 | if (block_cnt == 0) |
| 7169 | last_xritag = NO_XRI; |
| 7170 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7171 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7172 | post_cnt = 0; |
| 7173 | } |
| 7174 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7175 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7176 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7177 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7178 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7179 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7180 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7181 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7182 | list_splice_init(&post_sgl_list, sgl_list); |
| 7183 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7184 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7185 | } else { |
| 7186 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7187 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7188 | return -EIO; |
| 7189 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7190 | |
| 7191 | /* return the number of XRIs actually posted */ |
| 7192 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7193 | } |
| 7194 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7195 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7196 | * 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] | 7197 | * @phba: pointer to lpfc hba data structure. |
| 7198 | * |
| 7199 | * This routine walks the list of nvme buffers that have been allocated and |
| 7200 | * repost them to the port by using SGL block post. This is needed after a |
| 7201 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 7202 | * 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] | 7203 | * 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] | 7204 | * |
| 7205 | * Returns: 0 = success, non-zero failure. |
| 7206 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7207 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7208 | lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7209 | { |
| 7210 | LIST_HEAD(post_nblist); |
| 7211 | int num_posted, rc = 0; |
| 7212 | |
| 7213 | /* get all NVME buffers need to repost to a local list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7214 | lpfc_io_buf_flush(phba, &post_nblist); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7215 | |
| 7216 | /* post the list of nvme buffer sgls to port if available */ |
| 7217 | if (!list_empty(&post_nblist)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7218 | num_posted = lpfc_sli4_post_io_sgl_list( |
| 7219 | phba, &post_nblist, phba->sli4_hba.io_xri_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7220 | /* failed to post any nvme buffer, return error */ |
| 7221 | if (num_posted == 0) |
| 7222 | rc = -EIO; |
| 7223 | } |
| 7224 | return rc; |
| 7225 | } |
| 7226 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7227 | static void |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7228 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7229 | { |
| 7230 | uint32_t len; |
| 7231 | |
| 7232 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7233 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7234 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7235 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7236 | LPFC_SLI4_MBX_EMBED); |
| 7237 | |
| 7238 | 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] | 7239 | mbox->u.mqe.un.set_host_data.param_len = |
| 7240 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7241 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 7242 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7243 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7244 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7245 | } |
| 7246 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7247 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7248 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7249 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7250 | { |
| 7251 | int rc, i; |
| 7252 | struct lpfc_rqe hrqe; |
| 7253 | struct lpfc_rqe drqe; |
| 7254 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7255 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7256 | struct rqb_dmabuf *rqb_buffer; |
| 7257 | LIST_HEAD(rqb_buf_list); |
| 7258 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7259 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7260 | rqbp = hrq->rqbp; |
| 7261 | for (i = 0; i < count; i++) { |
| 7262 | /* IF RQ is already full, don't bother */ |
| 7263 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 7264 | break; |
| 7265 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7266 | if (!rqb_buffer) |
| 7267 | break; |
| 7268 | rqb_buffer->hrq = hrq; |
| 7269 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7270 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7271 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7272 | } |
| 7273 | while (!list_empty(&rqb_buf_list)) { |
| 7274 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7275 | hbuf.list); |
| 7276 | |
| 7277 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7278 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7279 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7280 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7281 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7282 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7283 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7284 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7285 | "DRQ %x %x\n", |
| 7286 | hrq->queue_id, |
| 7287 | hrq->host_index, |
| 7288 | hrq->hba_index, |
| 7289 | hrq->entry_count, |
| 7290 | drq->host_index, |
| 7291 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7292 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7293 | } else { |
| 7294 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7295 | &rqbp->rqb_buffer_list); |
| 7296 | rqbp->buffer_count++; |
| 7297 | } |
| 7298 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7299 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7300 | return 1; |
| 7301 | } |
| 7302 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 7303 | /** |
| 7304 | * lpfc_init_idle_stat_hb - Initialize idle_stat tracking |
| 7305 | * |
| 7306 | * This routine initializes the per-cq idle_stat to dynamically dictate |
| 7307 | * polling decisions. |
| 7308 | * |
| 7309 | * Return codes: |
| 7310 | * None |
| 7311 | **/ |
| 7312 | static void lpfc_init_idle_stat_hb(struct lpfc_hba *phba) |
| 7313 | { |
| 7314 | int i; |
| 7315 | struct lpfc_sli4_hdw_queue *hdwq; |
| 7316 | struct lpfc_queue *cq; |
| 7317 | struct lpfc_idle_stat *idle_stat; |
| 7318 | u64 wall; |
| 7319 | |
| 7320 | for_each_present_cpu(i) { |
| 7321 | hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq]; |
| 7322 | cq = hdwq->io_cq; |
| 7323 | |
| 7324 | /* Skip if we've already handled this cq's primary CPU */ |
| 7325 | if (cq->chann != i) |
| 7326 | continue; |
| 7327 | |
| 7328 | idle_stat = &phba->sli4_hba.idle_stat[i]; |
| 7329 | |
| 7330 | idle_stat->prev_idle = get_cpu_idle_time(i, &wall, 1); |
| 7331 | idle_stat->prev_wall = wall; |
| 7332 | |
| 7333 | if (phba->nvmet_support) |
| 7334 | cq->poll_mode = LPFC_QUEUE_WORK; |
| 7335 | else |
| 7336 | cq->poll_mode = LPFC_IRQ_POLL; |
| 7337 | } |
| 7338 | |
| 7339 | if (!phba->nvmet_support) |
| 7340 | schedule_delayed_work(&phba->idle_stat_delay_work, |
| 7341 | msecs_to_jiffies(LPFC_IDLE_STAT_DELAY)); |
| 7342 | } |
| 7343 | |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame] | 7344 | static void lpfc_sli4_dip(struct lpfc_hba *phba) |
| 7345 | { |
| 7346 | uint32_t if_type; |
| 7347 | |
| 7348 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7349 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2 || |
| 7350 | if_type == LPFC_SLI_INTF_IF_TYPE_6) { |
| 7351 | struct lpfc_register reg_data; |
| 7352 | |
| 7353 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7354 | ®_data.word0)) |
| 7355 | return; |
| 7356 | |
| 7357 | if (bf_get(lpfc_sliport_status_dip, ®_data)) |
| 7358 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7359 | "2904 Firmware Dump Image Present" |
| 7360 | " on Adapter"); |
| 7361 | } |
| 7362 | } |
| 7363 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7364 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7365 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7366 | * @phba: Pointer to HBA context object. |
| 7367 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7368 | * This function is the main SLI4 device initialization PCI function. This |
| 7369 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7370 | * HBA error attention handler code. Caller is not required to hold any |
| 7371 | * locks. |
| 7372 | **/ |
| 7373 | int |
| 7374 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7375 | { |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7376 | int rc, i, cnt, len, dd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7377 | LPFC_MBOXQ_t *mboxq; |
| 7378 | struct lpfc_mqe *mqe; |
| 7379 | uint8_t *vpd; |
| 7380 | uint32_t vpd_size; |
| 7381 | uint32_t ftr_rsp = 0; |
| 7382 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7383 | struct lpfc_vport *vport = phba->pport; |
| 7384 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7385 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7386 | |
| 7387 | /* Perform a PCI function reset to start from clean */ |
| 7388 | rc = lpfc_pci_function_reset(phba); |
| 7389 | if (unlikely(rc)) |
| 7390 | return -ENODEV; |
| 7391 | |
| 7392 | /* Check the HBA Host Status Register for readyness */ |
| 7393 | rc = lpfc_sli4_post_status_check(phba); |
| 7394 | if (unlikely(rc)) |
| 7395 | return -ENODEV; |
| 7396 | else { |
| 7397 | spin_lock_irq(&phba->hbalock); |
| 7398 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7399 | spin_unlock_irq(&phba->hbalock); |
| 7400 | } |
| 7401 | |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame] | 7402 | lpfc_sli4_dip(phba); |
| 7403 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7404 | /* |
| 7405 | * Allocate a single mailbox container for initializing the |
| 7406 | * port. |
| 7407 | */ |
| 7408 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7409 | if (!mboxq) |
| 7410 | return -ENOMEM; |
| 7411 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7412 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7413 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7414 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7415 | if (!vpd) { |
| 7416 | rc = -ENOMEM; |
| 7417 | goto out_free_mbox; |
| 7418 | } |
| 7419 | |
| 7420 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7421 | if (unlikely(rc)) { |
| 7422 | kfree(vpd); |
| 7423 | goto out_free_mbox; |
| 7424 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7425 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7426 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7427 | 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] | 7428 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7429 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7430 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7431 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7432 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7433 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7434 | |
| 7435 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7436 | LPFC_DCBX_CEE_MODE) |
| 7437 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7438 | else |
| 7439 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7440 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 7441 | phba->hba_flag &= ~HBA_IOQ_FLUSH; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7442 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7443 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7444 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7445 | "0376 READ_REV Error. SLI Level %d " |
| 7446 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7447 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7448 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7449 | kfree(vpd); |
| 7450 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7451 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7452 | |
| 7453 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7454 | * Continue initialization with default values even if driver failed |
| 7455 | * to read FCoE param config regions, only read parameters if the |
| 7456 | * board is FCoE |
| 7457 | */ |
| 7458 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7459 | lpfc_sli4_read_fcoe_params(phba)) |
| 7460 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7461 | "2570 Failed to read FCoE parameters\n"); |
| 7462 | |
| 7463 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7464 | * Retrieve sli4 device physical port name, failure of doing it |
| 7465 | * is considered as non-fatal. |
| 7466 | */ |
| 7467 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7468 | if (!rc) |
| 7469 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7470 | "3080 Successful retrieving SLI4 device " |
| 7471 | "physical port name: %s.\n", phba->Port); |
| 7472 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 7473 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 7474 | if (!rc) |
| 7475 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7476 | "8351 Successful retrieving SLI4 device " |
| 7477 | "CTL ATTR\n"); |
| 7478 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7479 | /* |
| 7480 | * Evaluate the read rev and vpd data. Populate the driver |
| 7481 | * state with the results. If this routine fails, the failure |
| 7482 | * is not fatal as the driver will use generic values. |
| 7483 | */ |
| 7484 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7485 | if (unlikely(!rc)) { |
| 7486 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7487 | "0377 Error %d parsing vpd. " |
| 7488 | "Using defaults.\n", rc); |
| 7489 | rc = 0; |
| 7490 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7491 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7492 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7493 | /* Save information as VPD data */ |
| 7494 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7495 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7496 | |
| 7497 | /* |
| 7498 | * This is because first G7 ASIC doesn't support the standard |
| 7499 | * 0x5a NVME cmd descriptor type/subtype |
| 7500 | */ |
| 7501 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7502 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7503 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7504 | (phba->vpd.rev.smRev == 0) && |
| 7505 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7506 | phba->cfg_nvme_embed_cmd = 0; |
| 7507 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7508 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7509 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7510 | &mqe->un.read_rev); |
| 7511 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7512 | &mqe->un.read_rev); |
| 7513 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7514 | &mqe->un.read_rev); |
| 7515 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7516 | &mqe->un.read_rev); |
| 7517 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7518 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7519 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7520 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7521 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7522 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7523 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7524 | "(%d):0380 READ_REV Status x%x " |
| 7525 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7526 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7527 | bf_get(lpfc_mqe_status, mqe), |
| 7528 | phba->vpd.rev.opFwName, |
| 7529 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7530 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7531 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7532 | 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] | 7533 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7534 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7535 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7536 | if (rc == MBX_SUCCESS) { |
| 7537 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7538 | /* Set 1Sec interval to detect UE */ |
| 7539 | phba->eratt_poll_interval = 1; |
| 7540 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7541 | lpfc_mbx_set_feature_UESR, |
| 7542 | &mboxq->u.mqe.un.set_feature); |
| 7543 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7544 | lpfc_mbx_set_feature_UERP, |
| 7545 | &mboxq->u.mqe.un.set_feature); |
| 7546 | } |
| 7547 | } |
| 7548 | |
| 7549 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7550 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7551 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7552 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7553 | if (rc != MBX_SUCCESS) |
| 7554 | phba->mds_diags_support = 0; |
| 7555 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7556 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7557 | /* |
| 7558 | * Discover the port's supported feature set and match it against the |
| 7559 | * hosts requests. |
| 7560 | */ |
| 7561 | lpfc_request_features(phba, mboxq); |
| 7562 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7563 | if (unlikely(rc)) { |
| 7564 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7565 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7566 | } |
| 7567 | |
| 7568 | /* |
| 7569 | * The port must support FCP initiator mode as this is the |
| 7570 | * only mode running in the host. |
| 7571 | */ |
| 7572 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7573 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7574 | "0378 No support for fcpi mode.\n"); |
| 7575 | ftr_rsp++; |
| 7576 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7577 | |
| 7578 | /* Performance Hints are ONLY for FCoE */ |
| 7579 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7580 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7581 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7582 | else |
| 7583 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7584 | } |
| 7585 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7586 | /* |
| 7587 | * If the port cannot support the host's requested features |
| 7588 | * then turn off the global config parameters to disable the |
| 7589 | * feature in the driver. This is not a fatal error. |
| 7590 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7591 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7592 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7593 | phba->cfg_enable_bg = 0; |
| 7594 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7595 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7596 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7597 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7598 | |
| 7599 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7600 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7601 | ftr_rsp++; |
| 7602 | |
| 7603 | if (ftr_rsp) { |
| 7604 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7605 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7606 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7607 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7608 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7609 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7610 | phba->cfg_enable_bg = 0; |
| 7611 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7612 | phba->cfg_enable_npiv = 0; |
| 7613 | } |
| 7614 | |
| 7615 | /* These SLI3 features are assumed in SLI4 */ |
| 7616 | spin_lock_irq(&phba->hbalock); |
| 7617 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7618 | spin_unlock_irq(&phba->hbalock); |
| 7619 | |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7620 | /* Always try to enable dual dump feature if we can */ |
| 7621 | lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP); |
| 7622 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7623 | dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature); |
| 7624 | if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP)) |
| 7625 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_INIT, |
| 7626 | "6448 Dual Dump is enabled\n"); |
| 7627 | else |
| 7628 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT, |
| 7629 | "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, " |
| 7630 | "rc:x%x dd:x%x\n", |
| 7631 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 7632 | lpfc_sli_config_mbox_subsys_get( |
| 7633 | phba, mboxq), |
| 7634 | lpfc_sli_config_mbox_opcode_get( |
| 7635 | phba, mboxq), |
| 7636 | rc, dd); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7637 | /* |
| 7638 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7639 | * calls depends on these resources to complete port setup. |
| 7640 | */ |
| 7641 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7642 | if (rc) { |
| 7643 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7644 | "2920 Failed to alloc Resource IDs " |
| 7645 | "rc = x%x\n", rc); |
| 7646 | goto out_free_mbox; |
| 7647 | } |
| 7648 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7649 | lpfc_set_host_data(phba, mboxq); |
| 7650 | |
| 7651 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7652 | if (rc) { |
| 7653 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7654 | "2134 Failed to set host os driver version %x", |
| 7655 | rc); |
| 7656 | } |
| 7657 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7658 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7659 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7660 | if (rc) { |
| 7661 | phba->link_state = LPFC_HBA_ERROR; |
| 7662 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7663 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7664 | } |
| 7665 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7666 | mboxq->vport = vport; |
| 7667 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7668 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7669 | if (rc == MBX_SUCCESS) { |
| 7670 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7671 | rc = 0; |
| 7672 | } |
| 7673 | |
| 7674 | /* |
| 7675 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7676 | * it to the mbuf pool. |
| 7677 | */ |
| 7678 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7679 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7680 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7681 | if (unlikely(rc)) { |
| 7682 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7683 | "0382 READ_SPARAM command failed " |
| 7684 | "status %d, mbxStatus x%x\n", |
| 7685 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7686 | phba->link_state = LPFC_HBA_ERROR; |
| 7687 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7688 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7689 | } |
| 7690 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7691 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7692 | |
| 7693 | /* Update the fc_host data structures with new wwn. */ |
| 7694 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7695 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7696 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7697 | /* Create all the SLI4 queues */ |
| 7698 | rc = lpfc_sli4_queue_create(phba); |
| 7699 | if (rc) { |
| 7700 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7701 | "3089 Failed to allocate queues\n"); |
| 7702 | rc = -ENODEV; |
| 7703 | goto out_free_mbox; |
| 7704 | } |
| 7705 | /* Set up all the queues to the device */ |
| 7706 | rc = lpfc_sli4_queue_setup(phba); |
| 7707 | if (unlikely(rc)) { |
| 7708 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7709 | "0381 Error %d during queue setup.\n ", rc); |
| 7710 | goto out_stop_timers; |
| 7711 | } |
| 7712 | /* Initialize the driver internal SLI layer lists. */ |
| 7713 | lpfc_sli4_setup(phba); |
| 7714 | lpfc_sli4_queue_init(phba); |
| 7715 | |
| 7716 | /* update host els xri-sgl sizes and mappings */ |
| 7717 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7718 | if (unlikely(rc)) { |
| 7719 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7720 | "1400 Failed to update xri-sgl size and " |
| 7721 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7722 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7723 | } |
| 7724 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7725 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7726 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7727 | phba->sli4_hba.els_xri_cnt); |
| 7728 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7729 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7730 | "0582 Error %d during els sgl post " |
| 7731 | "operation\n", rc); |
| 7732 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7733 | goto out_destroy_queue; |
| 7734 | } |
| 7735 | phba->sli4_hba.els_xri_cnt = rc; |
| 7736 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7737 | if (phba->nvmet_support) { |
| 7738 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7739 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7740 | if (unlikely(rc)) { |
| 7741 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7742 | "6308 Failed to update nvmet-sgl size " |
| 7743 | "and mapping: %d\n", rc); |
| 7744 | goto out_destroy_queue; |
| 7745 | } |
| 7746 | |
| 7747 | /* register the nvmet sgl pool to the port */ |
| 7748 | rc = lpfc_sli4_repost_sgl_list( |
| 7749 | phba, |
| 7750 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7751 | phba->sli4_hba.nvmet_xri_cnt); |
| 7752 | if (unlikely(rc < 0)) { |
| 7753 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7754 | "3117 Error %d during nvmet " |
| 7755 | "sgl post\n", rc); |
| 7756 | rc = -ENODEV; |
| 7757 | goto out_destroy_queue; |
| 7758 | } |
| 7759 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7760 | |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7761 | /* We allocate an iocbq for every receive context SGL. |
| 7762 | * The additional allocation is for abort and ls handling. |
| 7763 | */ |
| 7764 | cnt = phba->sli4_hba.nvmet_xri_cnt + |
| 7765 | phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7766 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7767 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7768 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7769 | if (unlikely(rc)) { |
| 7770 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7771 | "6082 Failed to update nvme-sgl size " |
| 7772 | "and mapping: %d\n", rc); |
| 7773 | goto out_destroy_queue; |
| 7774 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7775 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7776 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7777 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7778 | if (unlikely(rc)) { |
| 7779 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7780 | "6116 Error %d during nvme sgl post " |
| 7781 | "operation\n", rc); |
| 7782 | /* Some NVME buffers were moved to abort nvme list */ |
| 7783 | /* A pci function reset will repost them */ |
| 7784 | rc = -ENODEV; |
| 7785 | goto out_destroy_queue; |
| 7786 | } |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7787 | /* Each lpfc_io_buf job structure has an iocbq element. |
| 7788 | * This cnt provides for abort, els, ct and ls requests. |
| 7789 | */ |
| 7790 | cnt = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7791 | } |
| 7792 | |
| 7793 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7794 | /* Initialize and populate the iocb list per host */ |
| 7795 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7796 | "2821 initialize iocb list with %d entries\n", |
| 7797 | cnt); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7798 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7799 | if (rc) { |
| 7800 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7801 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7802 | goto out_destroy_queue; |
| 7803 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7804 | } |
| 7805 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7806 | if (phba->nvmet_support) |
| 7807 | lpfc_nvmet_create_targetport(phba); |
| 7808 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7809 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7810 | /* Post initial buffers to all RQs created */ |
| 7811 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7812 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7813 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7814 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7815 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7816 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7817 | rqbp->buffer_count = 0; |
| 7818 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7819 | lpfc_post_rq_buffer( |
| 7820 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7821 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7822 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7823 | } |
| 7824 | } |
| 7825 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7826 | /* Post the rpi header region to the device. */ |
| 7827 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7828 | if (unlikely(rc)) { |
| 7829 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7830 | "0393 Error %d during rpi post operation\n", |
| 7831 | rc); |
| 7832 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7833 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7834 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7835 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7836 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7837 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7838 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7839 | /* |
| 7840 | * The FC Port needs to register FCFI (index 0) |
| 7841 | */ |
| 7842 | lpfc_reg_fcfi(phba, mboxq); |
| 7843 | mboxq->vport = phba->pport; |
| 7844 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7845 | if (rc != MBX_SUCCESS) |
| 7846 | goto out_unset_queue; |
| 7847 | rc = 0; |
| 7848 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7849 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7850 | } else { |
| 7851 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7852 | |
| 7853 | /* First register the FCFI */ |
| 7854 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7855 | mboxq->vport = phba->pport; |
| 7856 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7857 | if (rc != MBX_SUCCESS) |
| 7858 | goto out_unset_queue; |
| 7859 | rc = 0; |
| 7860 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7861 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7862 | |
| 7863 | /* Next register the MRQs */ |
| 7864 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7865 | mboxq->vport = phba->pport; |
| 7866 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7867 | if (rc != MBX_SUCCESS) |
| 7868 | goto out_unset_queue; |
| 7869 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7870 | } |
| 7871 | /* Check if the port is configured to be disabled */ |
| 7872 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7873 | } |
| 7874 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7875 | /* Don't post more new bufs if repost already recovered |
| 7876 | * the nvme sgls. |
| 7877 | */ |
| 7878 | if (phba->nvmet_support == 0) { |
| 7879 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 7880 | len = lpfc_new_io_buf( |
| 7881 | phba, phba->sli4_hba.io_xri_max); |
| 7882 | if (len == 0) { |
| 7883 | rc = -ENOMEM; |
| 7884 | goto out_unset_queue; |
| 7885 | } |
| 7886 | |
| 7887 | if (phba->cfg_xri_rebalancing) |
| 7888 | lpfc_create_multixri_pools(phba); |
| 7889 | } |
| 7890 | } else { |
| 7891 | phba->cfg_xri_rebalancing = 0; |
| 7892 | } |
| 7893 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7894 | /* Allow asynchronous mailbox command to go through */ |
| 7895 | spin_lock_irq(&phba->hbalock); |
| 7896 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7897 | spin_unlock_irq(&phba->hbalock); |
| 7898 | |
| 7899 | /* Post receive buffers to the device */ |
| 7900 | lpfc_sli4_rb_setup(phba); |
| 7901 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7902 | /* Reset HBA FCF states after HBA reset */ |
| 7903 | phba->fcf.fcf_flag = 0; |
| 7904 | phba->fcf.current_rec.flag = 0; |
| 7905 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7906 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7907 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7908 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7909 | |
| 7910 | /* Start heart beat timer */ |
| 7911 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7912 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7913 | phba->hb_outstanding = 0; |
| 7914 | phba->last_completion_time = jiffies; |
| 7915 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7916 | /* start eq_delay heartbeat */ |
| 7917 | if (phba->cfg_auto_imax) |
| 7918 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 7919 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 7920 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 7921 | /* start per phba idle_stat_delay heartbeat */ |
| 7922 | lpfc_init_idle_stat_hb(phba); |
| 7923 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7924 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7925 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7926 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7927 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7928 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7929 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7930 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7931 | if (!rc) { |
| 7932 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7933 | "2829 This device supports " |
| 7934 | "Advanced Error Reporting (AER)\n"); |
| 7935 | spin_lock_irq(&phba->hbalock); |
| 7936 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7937 | spin_unlock_irq(&phba->hbalock); |
| 7938 | } else { |
| 7939 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7940 | "2830 This device does not support " |
| 7941 | "Advanced Error Reporting (AER)\n"); |
| 7942 | phba->cfg_aer_support = 0; |
| 7943 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7944 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7945 | } |
| 7946 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7947 | /* |
| 7948 | * The port is ready, set the host's link state to LINK_DOWN |
| 7949 | * in preparation for link interrupts. |
| 7950 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7951 | spin_lock_irq(&phba->hbalock); |
| 7952 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7953 | |
| 7954 | /* Check if physical ports are trunked */ |
| 7955 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 7956 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 7957 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 7958 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 7959 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 7960 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 7961 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 7962 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7963 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7964 | |
James Smart | e8869f5 | 2019-03-12 16:30:18 -0700 | [diff] [blame] | 7965 | /* Arm the CQs and then EQs on device */ |
| 7966 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7967 | |
| 7968 | /* Indicate device interrupt mode */ |
| 7969 | phba->sli4_hba.intr_enable = 1; |
| 7970 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7971 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7972 | (phba->hba_flag & LINK_DISABLED)) { |
| 7973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7974 | "3103 Adapter Link is disabled.\n"); |
| 7975 | lpfc_down_link(phba, mboxq); |
| 7976 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7977 | if (rc != MBX_SUCCESS) { |
| 7978 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7979 | "3104 Adapter failed to issue " |
| 7980 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7981 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7982 | } |
| 7983 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7984 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7985 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7986 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7987 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7988 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7989 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7990 | } |
| 7991 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7992 | return rc; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7993 | out_io_buff_free: |
| 7994 | /* Free allocated IO Buffers */ |
| 7995 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7996 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7997 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7998 | lpfc_sli4_queue_unset(phba); |
| 7999 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8000 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8001 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8002 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8003 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8004 | out_free_mbox: |
| 8005 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8006 | return rc; |
| 8007 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8008 | |
| 8009 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8010 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8011 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8012 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8013 | * This is the callback function for mailbox timer. The mailbox |
| 8014 | * timer is armed when a new mailbox command is issued and the timer |
| 8015 | * is deleted when the mailbox complete. The function is called by |
| 8016 | * the kernel timer code when a mailbox does not complete within |
| 8017 | * expected time. This function wakes up the worker thread to |
| 8018 | * process the mailbox timeout and returns. All the processing is |
| 8019 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 8020 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8021 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8022 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8023 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8024 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8025 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8026 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8027 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8028 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8029 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8030 | if (!tmo_posted) |
| 8031 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 8032 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 8033 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8034 | if (!tmo_posted) |
| 8035 | lpfc_worker_wake_up(phba); |
| 8036 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8037 | } |
| 8038 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8039 | /** |
| 8040 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 8041 | * are pending |
| 8042 | * @phba: Pointer to HBA context object. |
| 8043 | * |
| 8044 | * This function checks if any mailbox completions are present on the mailbox |
| 8045 | * completion queue. |
| 8046 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 8047 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8048 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 8049 | { |
| 8050 | |
| 8051 | uint32_t idx; |
| 8052 | struct lpfc_queue *mcq; |
| 8053 | struct lpfc_mcqe *mcqe; |
| 8054 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8055 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8056 | |
| 8057 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 8058 | return false; |
| 8059 | |
| 8060 | /* Check for completions on mailbox completion queue */ |
| 8061 | |
| 8062 | mcq = phba->sli4_hba.mbx_cq; |
| 8063 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8064 | qe_valid = mcq->qe_valid; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 8065 | while (bf_get_le32(lpfc_cqe_valid, |
| 8066 | (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) { |
| 8067 | mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx)); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8068 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 8069 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 8070 | pending_completions = true; |
| 8071 | break; |
| 8072 | } |
| 8073 | idx = (idx + 1) % mcq->entry_count; |
| 8074 | if (mcq->hba_index == idx) |
| 8075 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8076 | |
| 8077 | /* if the index wrapped around, toggle the valid bit */ |
| 8078 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 8079 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8080 | } |
| 8081 | return pending_completions; |
| 8082 | |
| 8083 | } |
| 8084 | |
| 8085 | /** |
| 8086 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 8087 | * that were missed. |
| 8088 | * @phba: Pointer to HBA context object. |
| 8089 | * |
| 8090 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 8091 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 8092 | * checks to see if mbox completions are on the mailbox completion queue |
| 8093 | * and will process all the completions associated with the eq for the |
| 8094 | * mailbox completion queue. |
| 8095 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 8096 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8097 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 8098 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 8099 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8100 | uint32_t eqidx; |
| 8101 | struct lpfc_queue *fpeq = NULL; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8102 | struct lpfc_queue *eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8103 | bool mbox_pending; |
| 8104 | |
| 8105 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 8106 | return false; |
| 8107 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8108 | /* Find the EQ associated with the mbox CQ */ |
| 8109 | if (sli4_hba->hdwq) { |
| 8110 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) { |
| 8111 | eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq; |
Daniel Wagner | 535fb49 | 2019-10-18 18:21:11 +0200 | [diff] [blame] | 8112 | if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8113 | fpeq = eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8114 | break; |
| 8115 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8116 | } |
| 8117 | } |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8118 | if (!fpeq) |
| 8119 | return false; |
| 8120 | |
| 8121 | /* Turn off interrupts from this EQ */ |
| 8122 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 8123 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8124 | |
| 8125 | /* Check to see if a mbox completion is pending */ |
| 8126 | |
| 8127 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 8128 | |
| 8129 | /* |
| 8130 | * If a mbox completion is pending, process all the events on EQ |
| 8131 | * associated with the mbox completion queue (this could include |
| 8132 | * mailbox commands, async events, els commands, receive queue data |
| 8133 | * and fcp commands) |
| 8134 | */ |
| 8135 | |
| 8136 | if (mbox_pending) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8137 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 8138 | lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8139 | else |
| 8140 | /* Always clear and re-arm the EQ */ |
| 8141 | sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8142 | |
| 8143 | return mbox_pending; |
| 8144 | |
| 8145 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8146 | |
| 8147 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8148 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8149 | * @phba: Pointer to HBA context object. |
| 8150 | * |
| 8151 | * This function is called from worker thread when a mailbox command times out. |
| 8152 | * The caller is not required to hold any locks. This function will reset the |
| 8153 | * HBA and recover all the pending commands. |
| 8154 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8155 | void |
| 8156 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 8157 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8158 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8159 | MAILBOX_t *mb = NULL; |
| 8160 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8161 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8162 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8163 | /* If the mailbox completed, process the completion and return */ |
| 8164 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 8165 | return; |
| 8166 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8167 | if (pmbox != NULL) |
| 8168 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8169 | /* Check the pmbox pointer first. There is a race condition |
| 8170 | * between the mbox timeout handler getting executed in the |
| 8171 | * worklist and the mailbox actually completing. When this |
| 8172 | * race condition occurs, the mbox_active will be NULL. |
| 8173 | */ |
| 8174 | spin_lock_irq(&phba->hbalock); |
| 8175 | if (pmbox == NULL) { |
| 8176 | lpfc_printf_log(phba, KERN_WARNING, |
| 8177 | LOG_MBOX | LOG_SLI, |
| 8178 | "0353 Active Mailbox cleared - mailbox timeout " |
| 8179 | "exiting\n"); |
| 8180 | spin_unlock_irq(&phba->hbalock); |
| 8181 | return; |
| 8182 | } |
| 8183 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8184 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8185 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 8186 | "0310 Mailbox command x%x timeout Data: x%x x%x x%px\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8187 | mb->mbxCommand, |
| 8188 | phba->pport->port_state, |
| 8189 | phba->sli.sli_flag, |
| 8190 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8191 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8192 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8193 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 8194 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8195 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8196 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8197 | spin_lock_irq(&phba->pport->work_port_lock); |
| 8198 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 8199 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 8200 | spin_lock_irq(&phba->hbalock); |
| 8201 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 8202 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8203 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8204 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 8205 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8206 | |
| 8207 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8208 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8209 | |
| 8210 | /* Reset the HBA device */ |
| 8211 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8212 | } |
| 8213 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8214 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8215 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8216 | * @phba: Pointer to HBA context object. |
| 8217 | * @pmbox: Pointer to mailbox object. |
| 8218 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8219 | * |
| 8220 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8221 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 8222 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8223 | * The mailbox command can be submitted in polling mode, in which case |
| 8224 | * this function will wait in a polling loop for the completion of the |
| 8225 | * mailbox. |
| 8226 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 8227 | * function will submit the command and returns immediately without waiting |
| 8228 | * for the mailbox completion. The no_wait is supported only when HBA |
| 8229 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 8230 | * The SLI interface allows only one mailbox pending at a time. If the |
| 8231 | * mailbox is issued in polling mode and there is already a mailbox |
| 8232 | * pending, then the function will return an error. If the mailbox is issued |
| 8233 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 8234 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 8235 | * The sli layer owns the mailbox object until the completion of mailbox |
| 8236 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 8237 | * return codes the caller owns the mailbox command after the return of |
| 8238 | * the function. |
| 8239 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8240 | static int |
| 8241 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 8242 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8243 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8244 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8245 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8246 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8247 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8248 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8249 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8250 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8251 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8252 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8253 | int processing_queue = 0; |
| 8254 | |
| 8255 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8256 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8257 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8258 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8259 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8260 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8261 | return MBX_SUCCESS; |
| 8262 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8263 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8264 | pmbox = lpfc_mbox_get(phba); |
| 8265 | if (!pmbox) { |
| 8266 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8267 | return MBX_SUCCESS; |
| 8268 | } |
| 8269 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8270 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8271 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8272 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8273 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8274 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8275 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8276 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8277 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8278 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8279 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8280 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8281 | } |
| 8282 | } |
| 8283 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8284 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8285 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8286 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8287 | goto out_not_finished; |
| 8288 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8289 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8290 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8291 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8292 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8293 | goto out_not_finished; |
| 8294 | } |
| 8295 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8296 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8297 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8298 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8299 | status = MBX_SUCCESS; |
| 8300 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8301 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8302 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8303 | |
| 8304 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8305 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8306 | "(%d):0311 Mailbox command x%x cannot " |
| 8307 | "issue Data: x%x x%x\n", |
| 8308 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8309 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8310 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8311 | } |
| 8312 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8313 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8314 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8315 | !(hc_copy & HC_MBINT_ENA)) { |
| 8316 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8317 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8318 | "(%d):2528 Mailbox command x%x cannot " |
| 8319 | "issue Data: x%x x%x\n", |
| 8320 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8321 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8322 | goto out_not_finished; |
| 8323 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8324 | } |
| 8325 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8326 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8327 | /* Polling for a mbox command when another one is already active |
| 8328 | * is not allowed in SLI. Also, the driver must have established |
| 8329 | * SLI2 mode to queue and process multiple mbox commands. |
| 8330 | */ |
| 8331 | |
| 8332 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8333 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8334 | |
| 8335 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8336 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8337 | "(%d):2529 Mailbox command x%x " |
| 8338 | "cannot issue Data: x%x x%x\n", |
| 8339 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8340 | pmbox->u.mb.mbxCommand, |
| 8341 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8342 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8343 | } |
| 8344 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8345 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8346 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8347 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8348 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8349 | "(%d):2530 Mailbox command x%x " |
| 8350 | "cannot issue Data: x%x x%x\n", |
| 8351 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8352 | pmbox->u.mb.mbxCommand, |
| 8353 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8354 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8355 | } |
| 8356 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8357 | /* Another mailbox command is still being processed, queue this |
| 8358 | * command to be processed later. |
| 8359 | */ |
| 8360 | lpfc_mbox_put(phba, pmbox); |
| 8361 | |
| 8362 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8363 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8364 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8365 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8366 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8367 | mbx->mbxCommand, |
| 8368 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8369 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8370 | |
| 8371 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8372 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8373 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8374 | if (pmbox->vport) { |
| 8375 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8376 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8377 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8378 | (uint32_t)mbx->mbxCommand, |
| 8379 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8380 | } |
| 8381 | else { |
| 8382 | lpfc_debugfs_disc_trc(phba->pport, |
| 8383 | LPFC_DISC_TRC_MBOX, |
| 8384 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8385 | (uint32_t)mbx->mbxCommand, |
| 8386 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8387 | } |
| 8388 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8389 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8390 | } |
| 8391 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8392 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8393 | |
| 8394 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8395 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8396 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8397 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8398 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8399 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8400 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8401 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8402 | "(%d):2531 Mailbox command x%x " |
| 8403 | "cannot issue Data: x%x x%x\n", |
| 8404 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8405 | pmbox->u.mb.mbxCommand, |
| 8406 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8407 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8408 | } |
| 8409 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8410 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8411 | 1000); |
| 8412 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8413 | } |
| 8414 | |
| 8415 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8416 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8417 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8418 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8419 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8420 | mbx->mbxCommand, |
| 8421 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8422 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8423 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8424 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8425 | if (pmbox->vport) { |
| 8426 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8427 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8428 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8429 | (uint32_t)mbx->mbxCommand, |
| 8430 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8431 | } |
| 8432 | else { |
| 8433 | lpfc_debugfs_disc_trc(phba->pport, |
| 8434 | LPFC_DISC_TRC_MBOX, |
| 8435 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8436 | (uint32_t)mbx->mbxCommand, |
| 8437 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8438 | } |
| 8439 | } |
| 8440 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8441 | psli->slistat.mbox_cmd++; |
| 8442 | evtctr = psli->slistat.mbox_event; |
| 8443 | |
| 8444 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8445 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8446 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8447 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8448 | /* Populate mbox extension offset word. */ |
| 8449 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8450 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8451 | = (uint8_t *)phba->mbox_ext |
| 8452 | - (uint8_t *)phba->mbox; |
| 8453 | } |
| 8454 | |
| 8455 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8456 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8457 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8458 | (uint8_t *)phba->mbox_ext, |
| 8459 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8460 | } |
| 8461 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8462 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8463 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8464 | /* Populate mbox extension offset word. */ |
| 8465 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8466 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8467 | = MAILBOX_HBA_EXT_OFFSET; |
| 8468 | |
| 8469 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8470 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8471 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8472 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8473 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8474 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8475 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8476 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8477 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8478 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8479 | |
| 8480 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8481 | word */ |
| 8482 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8483 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8484 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8485 | |
| 8486 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8487 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8488 | to_slim = phba->MBslimaddr; |
| 8489 | writel(ldata, to_slim); |
| 8490 | readl(to_slim); /* flush */ |
| 8491 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8492 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8493 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8494 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8495 | } |
| 8496 | |
| 8497 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8498 | |
| 8499 | switch (flag) { |
| 8500 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8501 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8502 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8503 | /* Interrupt board to do it */ |
| 8504 | writel(CA_MBATT, phba->CAregaddr); |
| 8505 | readl(phba->CAregaddr); /* flush */ |
| 8506 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8507 | break; |
| 8508 | |
| 8509 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8510 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8511 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8512 | /* Interrupt board to do it */ |
| 8513 | writel(CA_MBATT, phba->CAregaddr); |
| 8514 | readl(phba->CAregaddr); /* flush */ |
| 8515 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8516 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8517 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8518 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8519 | word0 = le32_to_cpu(word0); |
| 8520 | } else { |
| 8521 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8522 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8523 | spin_unlock_irqrestore(&phba->hbalock, |
| 8524 | drvr_flag); |
| 8525 | goto out_not_finished; |
| 8526 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8527 | } |
| 8528 | |
| 8529 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8530 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8531 | spin_unlock_irqrestore(&phba->hbalock, |
| 8532 | drvr_flag); |
| 8533 | goto out_not_finished; |
| 8534 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8535 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8536 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8537 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8538 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8539 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8540 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8541 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8542 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8543 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8544 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8545 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8546 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8547 | } |
| 8548 | |
| 8549 | /* Check if we took a mbox interrupt while we were |
| 8550 | polling */ |
| 8551 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8552 | && (evtctr != psli->slistat.mbox_event)) |
| 8553 | break; |
| 8554 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8555 | if (i++ > 10) { |
| 8556 | spin_unlock_irqrestore(&phba->hbalock, |
| 8557 | drvr_flag); |
| 8558 | msleep(1); |
| 8559 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8560 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8561 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8562 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8563 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8564 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8565 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8566 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8567 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8568 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8569 | /* Check real SLIM for any errors */ |
| 8570 | slimword0 = readl(phba->MBslimaddr); |
| 8571 | slimmb = (MAILBOX_t *) & slimword0; |
| 8572 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8573 | && slimmb->mbxStatus) { |
| 8574 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8575 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8576 | word0 = slimword0; |
| 8577 | } |
| 8578 | } |
| 8579 | } else { |
| 8580 | /* First copy command data */ |
| 8581 | word0 = readl(phba->MBslimaddr); |
| 8582 | } |
| 8583 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8584 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8585 | spin_unlock_irqrestore(&phba->hbalock, |
| 8586 | drvr_flag); |
| 8587 | goto out_not_finished; |
| 8588 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8589 | } |
| 8590 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8591 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8592 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8593 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8594 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8595 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8596 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8597 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8598 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8599 | pmbox->out_ext_byte_len); |
| 8600 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8601 | } else { |
| 8602 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8603 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8604 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8605 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8606 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8607 | lpfc_memcpy_from_slim( |
| 8608 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8609 | phba->MBslimaddr + |
| 8610 | MAILBOX_HBA_EXT_OFFSET, |
| 8611 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8612 | } |
| 8613 | } |
| 8614 | |
| 8615 | writel(HA_MBATT, phba->HAregaddr); |
| 8616 | readl(phba->HAregaddr); /* flush */ |
| 8617 | |
| 8618 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8619 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8620 | } |
| 8621 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8622 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8623 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8624 | |
| 8625 | out_not_finished: |
| 8626 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8627 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8628 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8629 | } |
| 8630 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8631 | } |
| 8632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8633 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8634 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8635 | * @phba: Pointer to HBA context object. |
| 8636 | * |
| 8637 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8638 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8639 | * possible outstanding mailbox command before return. |
| 8640 | * |
| 8641 | * Returns: |
| 8642 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8643 | * the outstanding mailbox command timed out. |
| 8644 | **/ |
| 8645 | static int |
| 8646 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8647 | { |
| 8648 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8649 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8650 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8651 | |
| 8652 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8653 | spin_lock_irq(&phba->hbalock); |
| 8654 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8655 | /* Determine how long we might wait for the active mailbox |
| 8656 | * command to be gracefully completed by firmware. |
| 8657 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8658 | if (phba->sli.mbox_active) |
| 8659 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8660 | phba->sli.mbox_active) * |
| 8661 | 1000) + jiffies; |
| 8662 | spin_unlock_irq(&phba->hbalock); |
| 8663 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8664 | /* Make sure the mailbox is really active */ |
| 8665 | if (timeout) |
| 8666 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8667 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8668 | /* Wait for the outstnading mailbox command to complete */ |
| 8669 | while (phba->sli.mbox_active) { |
| 8670 | /* Check active mailbox complete status every 2ms */ |
| 8671 | msleep(2); |
| 8672 | if (time_after(jiffies, timeout)) { |
| 8673 | /* Timeout, marked the outstanding cmd not complete */ |
| 8674 | rc = 1; |
| 8675 | break; |
| 8676 | } |
| 8677 | } |
| 8678 | |
| 8679 | /* Can not cleanly block async mailbox command, fails it */ |
| 8680 | if (rc) { |
| 8681 | spin_lock_irq(&phba->hbalock); |
| 8682 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8683 | spin_unlock_irq(&phba->hbalock); |
| 8684 | } |
| 8685 | return rc; |
| 8686 | } |
| 8687 | |
| 8688 | /** |
| 8689 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8690 | * @phba: Pointer to HBA context object. |
| 8691 | * |
| 8692 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8693 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8694 | * that there is no outstanding mailbox command before resuming posting |
| 8695 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8696 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8697 | * mailbox command posting. |
| 8698 | **/ |
| 8699 | static void |
| 8700 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8701 | { |
| 8702 | struct lpfc_sli *psli = &phba->sli; |
| 8703 | |
| 8704 | spin_lock_irq(&phba->hbalock); |
| 8705 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8706 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8707 | spin_unlock_irq(&phba->hbalock); |
| 8708 | return; |
| 8709 | } |
| 8710 | |
| 8711 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8712 | * successful or timeout, after timing-out the outstanding mailbox |
| 8713 | * command shall always be removed, so just unblock posting async |
| 8714 | * mailbox command and resume |
| 8715 | */ |
| 8716 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8717 | spin_unlock_irq(&phba->hbalock); |
| 8718 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 8719 | /* wake up worker thread to post asynchronous mailbox command */ |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8720 | lpfc_worker_wake_up(phba); |
| 8721 | } |
| 8722 | |
| 8723 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8724 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8725 | * @phba: Pointer to HBA context object. |
| 8726 | * @mboxq: Pointer to mailbox object. |
| 8727 | * |
| 8728 | * The function waits for the bootstrap mailbox register ready bit from |
| 8729 | * port for twice the regular mailbox command timeout value. |
| 8730 | * |
| 8731 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8732 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8733 | **/ |
| 8734 | static int |
| 8735 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8736 | { |
| 8737 | uint32_t db_ready; |
| 8738 | unsigned long timeout; |
| 8739 | struct lpfc_register bmbx_reg; |
| 8740 | |
| 8741 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8742 | * 1000) + jiffies; |
| 8743 | |
| 8744 | do { |
| 8745 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8746 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8747 | if (!db_ready) |
James Smart | e2ffe4d | 2019-03-12 16:30:15 -0700 | [diff] [blame] | 8748 | mdelay(2); |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8749 | |
| 8750 | if (time_after(jiffies, timeout)) |
| 8751 | return MBXERR_ERROR; |
| 8752 | } while (!db_ready); |
| 8753 | |
| 8754 | return 0; |
| 8755 | } |
| 8756 | |
| 8757 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8758 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8759 | * @phba: Pointer to HBA context object. |
| 8760 | * @mboxq: Pointer to mailbox object. |
| 8761 | * |
| 8762 | * The function posts a mailbox to the port. The mailbox is expected |
| 8763 | * to be comletely filled in and ready for the port to operate on it. |
| 8764 | * This routine executes a synchronous completion operation on the |
| 8765 | * mailbox by polling for its completion. |
| 8766 | * |
| 8767 | * The caller must not be holding any locks when calling this routine. |
| 8768 | * |
| 8769 | * Returns: |
| 8770 | * MBX_SUCCESS - mailbox posted successfully |
| 8771 | * Any of the MBX error values. |
| 8772 | **/ |
| 8773 | static int |
| 8774 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8775 | { |
| 8776 | int rc = MBX_SUCCESS; |
| 8777 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8778 | uint32_t mcqe_status; |
| 8779 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8780 | struct lpfc_sli *psli = &phba->sli; |
| 8781 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8782 | struct lpfc_bmbx_create *mbox_rgn; |
| 8783 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8784 | |
| 8785 | /* |
| 8786 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8787 | * at a time and there is no queueing provided. |
| 8788 | */ |
| 8789 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8790 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8791 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8792 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8793 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8794 | "cannot issue Data: x%x x%x\n", |
| 8795 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8796 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8797 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8798 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8799 | psli->sli_flag, MBX_POLL); |
| 8800 | return MBXERR_ERROR; |
| 8801 | } |
| 8802 | /* The server grabs the token and owns it until release */ |
| 8803 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8804 | phba->sli.mbox_active = mboxq; |
| 8805 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8806 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8807 | /* wait for bootstrap mbox register for readyness */ |
| 8808 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8809 | if (rc) |
| 8810 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8811 | /* |
| 8812 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8813 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8814 | * the bmbx mailbox region. |
| 8815 | */ |
| 8816 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8817 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8818 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8819 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8820 | |
| 8821 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8822 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8823 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8824 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8825 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8826 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8827 | if (rc) |
| 8828 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8829 | |
| 8830 | /* Post the low mailbox dma address to the port. */ |
| 8831 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8832 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8833 | /* wait for bootstrap mbox register for low address write done */ |
| 8834 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8835 | if (rc) |
| 8836 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8837 | |
| 8838 | /* |
| 8839 | * Read the CQ to ensure the mailbox has completed. |
| 8840 | * If so, update the mailbox status so that the upper layers |
| 8841 | * can complete the request normally. |
| 8842 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8843 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8844 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8845 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8846 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8847 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8848 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8849 | /* |
| 8850 | * When the CQE status indicates a failure and the mailbox status |
| 8851 | * indicates success then copy the CQE status into the mailbox status |
| 8852 | * (and prefix it with x4000). |
| 8853 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8854 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8855 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8856 | bf_set(lpfc_mqe_status, mb, |
| 8857 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8858 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8859 | } else |
| 8860 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8861 | |
| 8862 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8863 | "(%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] | 8864 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8865 | " 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] | 8866 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 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 | bf_get(lpfc_mqe_status, mb), |
| 8870 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8871 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8872 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8873 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8874 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8875 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8876 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8877 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8878 | mboxq->mcqe.trailer); |
| 8879 | exit: |
| 8880 | /* We are holding the token, no needed for lock when release */ |
| 8881 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8882 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8883 | phba->sli.mbox_active = NULL; |
| 8884 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8885 | return rc; |
| 8886 | } |
| 8887 | |
| 8888 | /** |
| 8889 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8890 | * @phba: Pointer to HBA context object. |
| 8891 | * @pmbox: Pointer to mailbox object. |
| 8892 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8893 | * |
| 8894 | * This function is called by discovery code and HBA management code to submit |
| 8895 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8896 | * |
| 8897 | * Return codes the caller owns the mailbox command after the return of the |
| 8898 | * function. |
| 8899 | **/ |
| 8900 | static int |
| 8901 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8902 | uint32_t flag) |
| 8903 | { |
| 8904 | struct lpfc_sli *psli = &phba->sli; |
| 8905 | unsigned long iflags; |
| 8906 | int rc; |
| 8907 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8908 | /* dump from issue mailbox command if setup */ |
| 8909 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8910 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8911 | rc = lpfc_mbox_dev_check(phba); |
| 8912 | if (unlikely(rc)) { |
| 8913 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8914 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8915 | "cannot issue Data: x%x x%x\n", |
| 8916 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8917 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8918 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8919 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8920 | psli->sli_flag, flag); |
| 8921 | goto out_not_finished; |
| 8922 | } |
| 8923 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8924 | /* Detect polling mode and jump to a handler */ |
| 8925 | if (!phba->sli4_hba.intr_enable) { |
| 8926 | if (flag == MBX_POLL) |
| 8927 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8928 | else |
| 8929 | rc = -EIO; |
| 8930 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8931 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8932 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8933 | "(x%x/x%x) failure: " |
| 8934 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8935 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8936 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8937 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8938 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8939 | mboxq), |
| 8940 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8941 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8942 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8943 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8944 | bf_get(lpfc_mcqe_ext_status, |
| 8945 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8946 | psli->sli_flag, flag); |
| 8947 | return rc; |
| 8948 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8949 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8950 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8951 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8952 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8953 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8954 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8955 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8956 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8957 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8958 | /* Try to block the asynchronous mailbox posting */ |
| 8959 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8960 | if (!rc) { |
| 8961 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8962 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8963 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8964 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8965 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8966 | "(%d):2597 Sync Mailbox command " |
| 8967 | "x%x (x%x/x%x) failure: " |
| 8968 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8969 | "Data: x%x x%x\n,", |
| 8970 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8971 | mboxq->u.mb.mbxCommand, |
| 8972 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8973 | mboxq), |
| 8974 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8975 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8976 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8977 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8978 | bf_get(lpfc_mcqe_ext_status, |
| 8979 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8980 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8981 | /* Unblock the async mailbox posting afterward */ |
| 8982 | lpfc_sli4_async_mbox_unblock(phba); |
| 8983 | } |
| 8984 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8985 | } |
| 8986 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 8987 | /* Now, interrupt mode asynchronous mailbox command */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8988 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8989 | if (rc) { |
| 8990 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8991 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8992 | "cannot issue Data: x%x x%x\n", |
| 8993 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8994 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8995 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8996 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8997 | psli->sli_flag, flag); |
| 8998 | goto out_not_finished; |
| 8999 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9000 | |
| 9001 | /* Put the mailbox command to the driver internal FIFO */ |
| 9002 | psli->slistat.mbox_busy++; |
| 9003 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9004 | lpfc_mbox_put(phba, mboxq); |
| 9005 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9006 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 9007 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9008 | "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] | 9009 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 9010 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9011 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9012 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9013 | phba->pport->port_state, |
| 9014 | psli->sli_flag, MBX_NOWAIT); |
| 9015 | /* Wake up worker thread to transport mailbox command from head */ |
| 9016 | lpfc_worker_wake_up(phba); |
| 9017 | |
| 9018 | return MBX_BUSY; |
| 9019 | |
| 9020 | out_not_finished: |
| 9021 | return MBX_NOT_FINISHED; |
| 9022 | } |
| 9023 | |
| 9024 | /** |
| 9025 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 9026 | * @phba: Pointer to HBA context object. |
| 9027 | * |
| 9028 | * This function is called by worker thread to send a mailbox command to |
| 9029 | * SLI4 HBA firmware. |
| 9030 | * |
| 9031 | **/ |
| 9032 | int |
| 9033 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 9034 | { |
| 9035 | struct lpfc_sli *psli = &phba->sli; |
| 9036 | LPFC_MBOXQ_t *mboxq; |
| 9037 | int rc = MBX_SUCCESS; |
| 9038 | unsigned long iflags; |
| 9039 | struct lpfc_mqe *mqe; |
| 9040 | uint32_t mbx_cmnd; |
| 9041 | |
| 9042 | /* Check interrupt mode before post async mailbox command */ |
| 9043 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 9044 | return MBX_NOT_FINISHED; |
| 9045 | |
| 9046 | /* Check for mailbox command service token */ |
| 9047 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9048 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 9049 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9050 | return MBX_NOT_FINISHED; |
| 9051 | } |
| 9052 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9053 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9054 | return MBX_NOT_FINISHED; |
| 9055 | } |
| 9056 | if (unlikely(phba->sli.mbox_active)) { |
| 9057 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9058 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 9059 | "0384 There is pending active mailbox cmd\n"); |
| 9060 | return MBX_NOT_FINISHED; |
| 9061 | } |
| 9062 | /* Take the mailbox command service token */ |
| 9063 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 9064 | |
| 9065 | /* Get the next mailbox command from head of queue */ |
| 9066 | mboxq = lpfc_mbox_get(phba); |
| 9067 | |
| 9068 | /* If no more mailbox command waiting for post, we're done */ |
| 9069 | if (!mboxq) { |
| 9070 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9071 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9072 | return MBX_SUCCESS; |
| 9073 | } |
| 9074 | phba->sli.mbox_active = mboxq; |
| 9075 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9076 | |
| 9077 | /* Check device readiness for posting mailbox command */ |
| 9078 | rc = lpfc_mbox_dev_check(phba); |
| 9079 | if (unlikely(rc)) |
| 9080 | /* Driver clean routine will clean up pending mailbox */ |
| 9081 | goto out_not_finished; |
| 9082 | |
| 9083 | /* Prepare the mbox command to be posted */ |
| 9084 | mqe = &mboxq->u.mqe; |
| 9085 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 9086 | |
| 9087 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 9088 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9089 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9090 | |
| 9091 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9092 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9093 | "x%x x%x\n", |
| 9094 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9095 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9096 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9097 | phba->pport->port_state, psli->sli_flag); |
| 9098 | |
| 9099 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 9100 | if (mboxq->vport) { |
| 9101 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 9102 | LPFC_DISC_TRC_MBOX_VPORT, |
| 9103 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 9104 | mbx_cmnd, mqe->un.mb_words[0], |
| 9105 | mqe->un.mb_words[1]); |
| 9106 | } else { |
| 9107 | lpfc_debugfs_disc_trc(phba->pport, |
| 9108 | LPFC_DISC_TRC_MBOX, |
| 9109 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 9110 | mbx_cmnd, mqe->un.mb_words[0], |
| 9111 | mqe->un.mb_words[1]); |
| 9112 | } |
| 9113 | } |
| 9114 | psli->slistat.mbox_cmd++; |
| 9115 | |
| 9116 | /* Post the mailbox command to the port */ |
| 9117 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 9118 | if (rc != MBX_SUCCESS) { |
| 9119 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9120 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9121 | "cannot issue Data: x%x x%x\n", |
| 9122 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9123 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9124 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9125 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9126 | psli->sli_flag, MBX_NOWAIT); |
| 9127 | goto out_not_finished; |
| 9128 | } |
| 9129 | |
| 9130 | return rc; |
| 9131 | |
| 9132 | out_not_finished: |
| 9133 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 9134 | if (phba->sli.mbox_active) { |
| 9135 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9136 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 9137 | /* Release the token */ |
| 9138 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9139 | phba->sli.mbox_active = NULL; |
| 9140 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9141 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9142 | |
| 9143 | return MBX_NOT_FINISHED; |
| 9144 | } |
| 9145 | |
| 9146 | /** |
| 9147 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 9148 | * @phba: Pointer to HBA context object. |
| 9149 | * @pmbox: Pointer to mailbox object. |
| 9150 | * @flag: Flag indicating how the mailbox need to be processed. |
| 9151 | * |
| 9152 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 9153 | * the API jump table function pointer from the lpfc_hba struct. |
| 9154 | * |
| 9155 | * Return codes the caller owns the mailbox command after the return of the |
| 9156 | * function. |
| 9157 | **/ |
| 9158 | int |
| 9159 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 9160 | { |
| 9161 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 9162 | } |
| 9163 | |
| 9164 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9165 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9166 | * @phba: The hba struct for which this call is being executed. |
| 9167 | * @dev_grp: The HBA PCI-Device group number. |
| 9168 | * |
| 9169 | * This routine sets up the mbox interface API function jump table in @phba |
| 9170 | * struct. |
| 9171 | * Returns: 0 - success, -ENODEV - failure. |
| 9172 | **/ |
| 9173 | int |
| 9174 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9175 | { |
| 9176 | |
| 9177 | switch (dev_grp) { |
| 9178 | case LPFC_PCI_DEV_LP: |
| 9179 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 9180 | phba->lpfc_sli_handle_slow_ring_event = |
| 9181 | lpfc_sli_handle_slow_ring_event_s3; |
| 9182 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 9183 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 9184 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 9185 | break; |
| 9186 | case LPFC_PCI_DEV_OC: |
| 9187 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 9188 | phba->lpfc_sli_handle_slow_ring_event = |
| 9189 | lpfc_sli_handle_slow_ring_event_s4; |
| 9190 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 9191 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 9192 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 9193 | break; |
| 9194 | default: |
| 9195 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9196 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 9197 | dev_grp); |
| 9198 | return -ENODEV; |
| 9199 | break; |
| 9200 | } |
| 9201 | return 0; |
| 9202 | } |
| 9203 | |
| 9204 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9205 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9206 | * @phba: Pointer to HBA context object. |
| 9207 | * @pring: Pointer to driver SLI ring object. |
| 9208 | * @piocb: Pointer to address of newly added command iocb. |
| 9209 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9210 | * This function is called with hbalock held for SLI3 ports or |
| 9211 | * the ring lock held for SLI4 ports to add a command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9212 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 9213 | * to the ring. |
| 9214 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9215 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9216 | __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] | 9217 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9218 | { |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9219 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9220 | lockdep_assert_held(&pring->ring_lock); |
| 9221 | else |
| 9222 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9223 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 9224 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9225 | } |
| 9226 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9227 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9228 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9229 | * @phba: Pointer to HBA context object. |
| 9230 | * @pring: Pointer to driver SLI ring object. |
| 9231 | * @piocb: Pointer to address of newly added command iocb. |
| 9232 | * |
| 9233 | * This function is called with hbalock held before a new |
| 9234 | * iocb is submitted to the firmware. This function checks |
| 9235 | * txq to flush the iocbs in txq to Firmware before |
| 9236 | * submitting new iocbs to the Firmware. |
| 9237 | * If there are iocbs in the txq which need to be submitted |
| 9238 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 9239 | * of the txq after dequeuing it from txq. |
| 9240 | * If there is no iocb in the txq then the function will return |
| 9241 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 9242 | * *piocb to find if there are more commands in the txq. |
| 9243 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9244 | static struct lpfc_iocbq * |
| 9245 | 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] | 9246 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9247 | { |
| 9248 | struct lpfc_iocbq * nextiocb; |
| 9249 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9250 | lockdep_assert_held(&phba->hbalock); |
| 9251 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9252 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9253 | if (!nextiocb) { |
| 9254 | nextiocb = *piocb; |
| 9255 | *piocb = NULL; |
| 9256 | } |
| 9257 | |
| 9258 | return nextiocb; |
| 9259 | } |
| 9260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9261 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9262 | * __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] | 9263 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9264 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9265 | * @piocb: Pointer to command iocb. |
| 9266 | * @flag: Flag indicating if this command can be put into txq. |
| 9267 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9268 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9269 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9270 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9271 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9272 | * this function allows only iocbs for posting buffers. This function finds |
| 9273 | * next available slot in the command ring and posts the command to the |
| 9274 | * available slot and writes the port attention register to request HBA start |
| 9275 | * processing new iocb. If there is no slot available in the ring and |
| 9276 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9277 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9278 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9279 | * This function is called with hbalock held. The function will return success |
| 9280 | * after it successfully submit the iocb to firmware or after adding to the |
| 9281 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9282 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9283 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9284 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9285 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9286 | { |
| 9287 | struct lpfc_iocbq *nextiocb; |
| 9288 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9289 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9290 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9291 | lockdep_assert_held(&phba->hbalock); |
| 9292 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9293 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9294 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9295 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 9296 | lpfc_printf_log(phba, KERN_ERR, |
| 9297 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9298 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9299 | piocb->iocb.ulpCommand); |
| 9300 | dump_stack(); |
| 9301 | return IOCB_ERROR; |
| 9302 | } |
| 9303 | |
| 9304 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9305 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9306 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9307 | return IOCB_ERROR; |
| 9308 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9309 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9310 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9311 | return IOCB_ERROR; |
| 9312 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9313 | /* |
| 9314 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9315 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9316 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9317 | return IOCB_ERROR; |
| 9318 | |
| 9319 | /* |
| 9320 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9321 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9322 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9323 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9324 | goto iocb_busy; |
| 9325 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9326 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9327 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9328 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9329 | * can be issued if the link is not up. |
| 9330 | */ |
| 9331 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9332 | case CMD_GEN_REQUEST64_CR: |
| 9333 | case CMD_GEN_REQUEST64_CX: |
| 9334 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9335 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9336 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9337 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9338 | MENLO_TRANSPORT_TYPE)) |
| 9339 | |
| 9340 | goto iocb_busy; |
| 9341 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9342 | case CMD_QUE_RING_BUF_CN: |
| 9343 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9344 | /* |
| 9345 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9346 | * completion, iocb_cmpl MUST be 0. |
| 9347 | */ |
| 9348 | if (piocb->iocb_cmpl) |
| 9349 | piocb->iocb_cmpl = NULL; |
| 9350 | /*FALLTHROUGH*/ |
| 9351 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9352 | case CMD_CLOSE_XRI_CN: |
| 9353 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9354 | break; |
| 9355 | default: |
| 9356 | goto iocb_busy; |
| 9357 | } |
| 9358 | |
| 9359 | /* |
| 9360 | * For FCP commands, we must be in a state where we can process link |
| 9361 | * attention events. |
| 9362 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9363 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9364 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9365 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9366 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9367 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9368 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9369 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9370 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9371 | |
| 9372 | if (iocb) |
| 9373 | lpfc_sli_update_ring(phba, pring); |
| 9374 | else |
| 9375 | lpfc_sli_update_full_ring(phba, pring); |
| 9376 | |
| 9377 | if (!piocb) |
| 9378 | return IOCB_SUCCESS; |
| 9379 | |
| 9380 | goto out_busy; |
| 9381 | |
| 9382 | iocb_busy: |
| 9383 | pring->stats.iocb_cmd_delay++; |
| 9384 | |
| 9385 | out_busy: |
| 9386 | |
| 9387 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9388 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9389 | return IOCB_SUCCESS; |
| 9390 | } |
| 9391 | |
| 9392 | return IOCB_BUSY; |
| 9393 | } |
| 9394 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9395 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9396 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9397 | * @phba: Pointer to HBA context object. |
| 9398 | * @piocb: Pointer to command iocb. |
| 9399 | * @sglq: Pointer to the scatter gather queue object. |
| 9400 | * |
| 9401 | * This routine converts the bpl or bde that is in the IOCB |
| 9402 | * to a sgl list for the sli4 hardware. The physical address |
| 9403 | * of the bpl/bde is converted back to a virtual address. |
| 9404 | * If the IOCB contains a BPL then the list of BDE's is |
| 9405 | * converted to sli4_sge's. If the IOCB contains a single |
| 9406 | * BDE then it is converted to a single sli_sge. |
| 9407 | * The IOCB is still in cpu endianess so the contents of |
| 9408 | * the bpl can be used without byte swapping. |
| 9409 | * |
| 9410 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9411 | **/ |
| 9412 | static uint16_t |
| 9413 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9414 | struct lpfc_sglq *sglq) |
| 9415 | { |
| 9416 | uint16_t xritag = NO_XRI; |
| 9417 | struct ulp_bde64 *bpl = NULL; |
| 9418 | struct ulp_bde64 bde; |
| 9419 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9420 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9421 | IOCB_t *icmd; |
| 9422 | int numBdes = 0; |
| 9423 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9424 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9425 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9426 | |
| 9427 | if (!piocbq || !sglq) |
| 9428 | return xritag; |
| 9429 | |
| 9430 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9431 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9432 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9433 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9434 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9435 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9436 | sizeof(struct ulp_bde64); |
| 9437 | /* The addrHigh and addrLow fields within the IOCB |
| 9438 | * have not been byteswapped yet so there is no |
| 9439 | * need to swap them back. |
| 9440 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9441 | if (piocbq->context3) |
| 9442 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9443 | else |
| 9444 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9445 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9446 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9447 | if (!bpl) |
| 9448 | return xritag; |
| 9449 | |
| 9450 | for (i = 0; i < numBdes; i++) { |
| 9451 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9452 | sgl->addr_hi = bpl->addrHigh; |
| 9453 | sgl->addr_lo = bpl->addrLow; |
| 9454 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9455 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9456 | if ((i+1) == numBdes) |
| 9457 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9458 | else |
| 9459 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9460 | /* swap the size field back to the cpu so we |
| 9461 | * can assign it to the sgl. |
| 9462 | */ |
| 9463 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9464 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9465 | /* The offsets in the sgl need to be accumulated |
| 9466 | * separately for the request and reply lists. |
| 9467 | * The request is always first, the reply follows. |
| 9468 | */ |
| 9469 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9470 | /* add up the reply sg entries */ |
| 9471 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9472 | inbound++; |
| 9473 | /* first inbound? reset the offset */ |
| 9474 | if (inbound == 1) |
| 9475 | offset = 0; |
| 9476 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9477 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9478 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9479 | offset += bde.tus.f.bdeSize; |
| 9480 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9481 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9482 | bpl++; |
| 9483 | sgl++; |
| 9484 | } |
| 9485 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9486 | /* The addrHigh and addrLow fields of the BDE have not |
| 9487 | * been byteswapped yet so they need to be swapped |
| 9488 | * before putting them in the sgl. |
| 9489 | */ |
| 9490 | sgl->addr_hi = |
| 9491 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9492 | sgl->addr_lo = |
| 9493 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9494 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9495 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9496 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9497 | sgl->sge_len = |
| 9498 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9499 | } |
| 9500 | return sglq->sli4_xritag; |
| 9501 | } |
| 9502 | |
| 9503 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9504 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 9505 | * @phba: Pointer to HBA context object. |
| 9506 | * @piocb: Pointer to command iocb. |
| 9507 | * @wqe: Pointer to the work queue entry. |
| 9508 | * |
| 9509 | * This routine converts the iocb command to its Work Queue Entry |
| 9510 | * equivalent. The wqe pointer should not have any fields set when |
| 9511 | * this routine is called because it will memcpy over them. |
| 9512 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9513 | * wqe. |
| 9514 | * |
| 9515 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9516 | **/ |
| 9517 | static int |
| 9518 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9519 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9520 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9521 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9522 | uint8_t ct = 0; |
| 9523 | uint32_t fip; |
| 9524 | uint32_t abort_tag; |
| 9525 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9526 | uint8_t cmnd; |
| 9527 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9528 | uint16_t abrt_iotag; |
| 9529 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9530 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9531 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9532 | int numBdes, i; |
| 9533 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9534 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9535 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9536 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9537 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9538 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9539 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9540 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9541 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9542 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9543 | command_type = ELS_COMMAND_FIP; |
| 9544 | else |
| 9545 | command_type = ELS_COMMAND_NON_FIP; |
| 9546 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9547 | if (phba->fcp_embed_io) |
| 9548 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9549 | /* Some of the fields are in the right position already */ |
| 9550 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9551 | /* The ct field has moved so reset */ |
| 9552 | wqe->generic.wqe_com.word7 = 0; |
| 9553 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9554 | |
| 9555 | abort_tag = (uint32_t) iocbq->iotag; |
| 9556 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9557 | /* words0-2 bpl convert bde */ |
| 9558 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9559 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9560 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9561 | bpl = (struct ulp_bde64 *) |
| 9562 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9563 | if (!bpl) |
| 9564 | return IOCB_ERROR; |
| 9565 | |
| 9566 | /* Should already be byte swapped. */ |
| 9567 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9568 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9569 | /* swap the size field back to the cpu so we |
| 9570 | * can assign it to the sgl. |
| 9571 | */ |
| 9572 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9573 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9574 | total_len = 0; |
| 9575 | for (i = 0; i < numBdes; i++) { |
| 9576 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9577 | total_len += bde.tus.f.bdeSize; |
| 9578 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9579 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9580 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9581 | |
| 9582 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9583 | cmnd = iocbq->iocb.ulpCommand; |
| 9584 | |
| 9585 | switch (iocbq->iocb.ulpCommand) { |
| 9586 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9587 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9588 | ndlp = iocbq->context_un.ndlp; |
| 9589 | else |
| 9590 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9591 | if (!iocbq->iocb.ulpLe) { |
| 9592 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9593 | "2007 Only Limited Edition cmd Format" |
| 9594 | " supported 0x%x\n", |
| 9595 | iocbq->iocb.ulpCommand); |
| 9596 | return IOCB_ERROR; |
| 9597 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9598 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9599 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9600 | /* Els_reguest64 has a TMO */ |
| 9601 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9602 | iocbq->iocb.ulpTimeout); |
| 9603 | /* Need a VF for word 4 set the vf bit*/ |
| 9604 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9605 | /* And a VFID for word 12 */ |
| 9606 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9607 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9608 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9609 | iocbq->iocb.ulpContext); |
| 9610 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9611 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9612 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9613 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9614 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9615 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9616 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9617 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9618 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9619 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9620 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9621 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9622 | *pcmd == ELS_CMD_SCR || |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 9623 | *pcmd == ELS_CMD_RDF || |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 9624 | *pcmd == ELS_CMD_RSCN_XMT || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9625 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9626 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9627 | *pcmd == ELS_CMD_PLOGI)) { |
| 9628 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9629 | bf_set(els_req64_sid, &wqe->els_req, |
| 9630 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9631 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9632 | !(phba->fc_topology == |
| 9633 | LPFC_TOPOLOGY_LOOP)) |
| 9634 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9635 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9636 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9637 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9638 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9639 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9640 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9641 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9642 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9643 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9644 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9645 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9646 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9647 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9648 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9649 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9650 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9651 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9652 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9653 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9654 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9655 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9656 | iocbq->iocb.un.ulpWord[3]); |
| 9657 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9658 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9659 | /* The entire sequence is transmitted for this IOCB */ |
| 9660 | xmit_len = total_len; |
| 9661 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9662 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9663 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 9664 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9665 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9666 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9667 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9668 | /* word4 relative_offset memcpy */ |
| 9669 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9670 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9671 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9672 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9673 | LPFC_WQE_IOD_WRITE); |
| 9674 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9675 | LPFC_WQE_LENLOC_WORD12); |
| 9676 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9677 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9678 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9679 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9680 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9681 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9682 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9683 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9684 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9685 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9686 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9687 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9688 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9689 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9690 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9691 | LPFC_WQE_LENLOC_WORD3); |
| 9692 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9693 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9694 | case CMD_FCP_IWRITE64_CR: |
| 9695 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9696 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9697 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9698 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9699 | xmit_len + sizeof(struct fcp_rsp)); |
| 9700 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9701 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9702 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9703 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9704 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9705 | iocbq->iocb.ulpFCP2Rcvy); |
| 9706 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9707 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9708 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9709 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9710 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9711 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9712 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9713 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9714 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9715 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9716 | if (iocbq->priority) { |
| 9717 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9718 | (iocbq->priority << 1)); |
| 9719 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9720 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9721 | (phba->cfg_XLanePriority << 1)); |
| 9722 | } |
| 9723 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9724 | /* Note, word 10 is already initialized to 0 */ |
| 9725 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9726 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9727 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9728 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9729 | else |
| 9730 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9731 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9732 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9733 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9734 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9735 | struct fcp_cmnd *fcp_cmnd; |
| 9736 | uint32_t *ptr; |
| 9737 | |
| 9738 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9739 | |
| 9740 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9741 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9742 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9743 | |
| 9744 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9745 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9746 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9747 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9748 | wqe->generic.bde.addrHigh = 0; |
| 9749 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9750 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9751 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9752 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9753 | |
| 9754 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9755 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9756 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9757 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9758 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9759 | case CMD_FCP_IREAD64_CR: |
| 9760 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9761 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9762 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9763 | xmit_len + sizeof(struct fcp_rsp)); |
| 9764 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9765 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9766 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9767 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9768 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9769 | iocbq->iocb.ulpFCP2Rcvy); |
| 9770 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9771 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9772 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9773 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9774 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9775 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9776 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9777 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9778 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9779 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9780 | if (iocbq->priority) { |
| 9781 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9782 | (iocbq->priority << 1)); |
| 9783 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9784 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9785 | (phba->cfg_XLanePriority << 1)); |
| 9786 | } |
| 9787 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9788 | /* Note, word 10 is already initialized to 0 */ |
| 9789 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9790 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9791 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9792 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9793 | else |
| 9794 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9795 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9796 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9797 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9798 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9799 | struct fcp_cmnd *fcp_cmnd; |
| 9800 | uint32_t *ptr; |
| 9801 | |
| 9802 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9803 | |
| 9804 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9805 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9806 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9807 | |
| 9808 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9809 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9810 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9811 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9812 | wqe->generic.bde.addrHigh = 0; |
| 9813 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9814 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9815 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9816 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9817 | |
| 9818 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9819 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9820 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9821 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9822 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9823 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9824 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9825 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9826 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9827 | xmit_len + sizeof(struct fcp_rsp)); |
| 9828 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9829 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9830 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9831 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9832 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9833 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9834 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9835 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9836 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9837 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9838 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9839 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9840 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9841 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9842 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9843 | if (iocbq->priority) { |
| 9844 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9845 | (iocbq->priority << 1)); |
| 9846 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9847 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9848 | (phba->cfg_XLanePriority << 1)); |
| 9849 | } |
| 9850 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9851 | /* Note, word 10 is already initialized to 0 */ |
| 9852 | |
| 9853 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9854 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9855 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9856 | struct fcp_cmnd *fcp_cmnd; |
| 9857 | uint32_t *ptr; |
| 9858 | |
| 9859 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9860 | |
| 9861 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9862 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9863 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9864 | |
| 9865 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9866 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9867 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9868 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9869 | wqe->generic.bde.addrHigh = 0; |
| 9870 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9871 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9872 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9873 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9874 | |
| 9875 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9876 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9877 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9878 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9879 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9880 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9881 | /* For this command calculate the xmit length of the |
| 9882 | * request bde. |
| 9883 | */ |
| 9884 | xmit_len = 0; |
| 9885 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9886 | sizeof(struct ulp_bde64); |
| 9887 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9888 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9889 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9890 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9891 | xmit_len += bde.tus.f.bdeSize; |
| 9892 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9893 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9894 | wqe->gen_req.request_payload_len = xmit_len; |
| 9895 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9896 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9897 | /* word6 context tag copied in memcpy */ |
| 9898 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9899 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9900 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9901 | "2015 Invalid CT %x command 0x%x\n", |
| 9902 | ct, iocbq->iocb.ulpCommand); |
| 9903 | return IOCB_ERROR; |
| 9904 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9905 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9906 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9907 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9908 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9909 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9910 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9911 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9912 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9913 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9914 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9915 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9916 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9917 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9918 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9919 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9920 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9921 | /* word4 */ |
| 9922 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9923 | /* word5 iocb=rsvd wge=did */ |
| 9924 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9925 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9926 | |
| 9927 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9928 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9929 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9930 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9931 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9932 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9933 | iocbq->vport->fc_myDID); |
| 9934 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9935 | bf_set(wqe_els_did, |
| 9936 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9937 | } |
| 9938 | } |
| 9939 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9940 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9941 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9942 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9943 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9944 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9945 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9946 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9947 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9948 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9949 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9950 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9951 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9952 | LPFC_WQE_LENLOC_WORD3); |
| 9953 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9954 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9955 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9956 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9957 | iocbq->context2)->virt); |
| 9958 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9959 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9960 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9961 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9962 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9963 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9964 | phba->vpi_ids[phba->pport->vpi]); |
| 9965 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9966 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9967 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9968 | case CMD_CLOSE_XRI_CN: |
| 9969 | case CMD_ABORT_XRI_CN: |
| 9970 | case CMD_ABORT_XRI_CX: |
| 9971 | /* words 0-2 memcpy should be 0 rserved */ |
| 9972 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9973 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9974 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9975 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9976 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9977 | } else |
| 9978 | fip = 0; |
| 9979 | |
| 9980 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9981 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9982 | * The link is down, or the command was ELS_FIP |
| 9983 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9984 | * on the wire. |
| 9985 | */ |
| 9986 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9987 | else |
| 9988 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9989 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9990 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9991 | wqe->abort_cmd.rsrvd5 = 0; |
| 9992 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9993 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9994 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9995 | /* |
| 9996 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9997 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9998 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9999 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 10000 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 10001 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 10002 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10003 | cmnd = CMD_ABORT_XRI_CX; |
| 10004 | command_type = OTHER_COMMAND; |
| 10005 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10006 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10007 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10008 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10009 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10010 | * we re-construct this WQE here based on information in |
| 10011 | * iocbq from scratch. |
| 10012 | */ |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 10013 | memset(wqe, 0, sizeof(*wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10014 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10015 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10016 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 10017 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10018 | LPFC_ABTS_UNSOL_INT) { |
| 10019 | /* ABTS sent by initiator to CT exchange, the |
| 10020 | * RX_ID field will be filled with the newly |
| 10021 | * allocated responder XRI. |
| 10022 | */ |
| 10023 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 10024 | iocbq->sli4_xritag); |
| 10025 | } else { |
| 10026 | /* ABTS sent by responder to CT exchange, the |
| 10027 | * RX_ID field will be filled with the responder |
| 10028 | * RX_ID from ABTS. |
| 10029 | */ |
| 10030 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10031 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10032 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10033 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 10034 | 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] | 10035 | |
| 10036 | /* Use CT=VPI */ |
| 10037 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 10038 | ndlp->nlp_DID); |
| 10039 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 10040 | iocbq->iocb.ulpContext); |
| 10041 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10042 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10043 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10044 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 10045 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 10046 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10047 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 10048 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10049 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 10050 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 10051 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 10052 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 10053 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 10054 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 10055 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 10056 | } |
| 10057 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10058 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 10059 | case CMD_SEND_FRAME: |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 10060 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME); |
| 10061 | bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */ |
| 10062 | bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */ |
| 10063 | bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1); |
| 10064 | bf_set(wqe_xbl, &wqe->generic.wqe_com, 1); |
| 10065 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 10066 | bf_set(wqe_xc, &wqe->generic.wqe_com, 1); |
| 10067 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA); |
| 10068 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 10069 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 10070 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 10071 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10072 | case CMD_XRI_ABORTED_CX: |
| 10073 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10074 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 10075 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 10076 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 10077 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 10078 | default: |
| 10079 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 10080 | "2014 Invalid command 0x%x\n", |
| 10081 | iocbq->iocb.ulpCommand); |
| 10082 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10083 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10084 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10085 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 10086 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 10087 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 10088 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 10089 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 10090 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 10091 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 10092 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 10093 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10094 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 10095 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 10096 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 10097 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 10098 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 10099 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 10100 | 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] | 10101 | return 0; |
| 10102 | } |
| 10103 | |
| 10104 | /** |
| 10105 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 10106 | * @phba: Pointer to HBA context object. |
| 10107 | * @ring_number: SLI ring number to issue iocb on. |
| 10108 | * @piocb: Pointer to command iocb. |
| 10109 | * @flag: Flag indicating if this command can be put into txq. |
| 10110 | * |
| 10111 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 10112 | * an iocb command to an HBA with SLI-4 interface spec. |
| 10113 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 10114 | * This function is called with ringlock held. The function will return success |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10115 | * after it successfully submit the iocb to firmware or after adding to the |
| 10116 | * txq. |
| 10117 | **/ |
| 10118 | static int |
| 10119 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 10120 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10121 | { |
| 10122 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10123 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10124 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10125 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10126 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10127 | /* Get the WQ */ |
| 10128 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 10129 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10130 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10131 | } else { |
| 10132 | wq = phba->sli4_hba.els_wq; |
| 10133 | } |
| 10134 | |
| 10135 | /* Get corresponding ring */ |
| 10136 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10137 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10138 | /* |
| 10139 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10140 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10141 | |
James Smart | cda7fa18 | 2019-03-04 15:15:43 -0800 | [diff] [blame] | 10142 | lockdep_assert_held(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10143 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10144 | if (piocb->sli4_xritag == NO_XRI) { |
| 10145 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10146 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10147 | sglq = NULL; |
| 10148 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10149 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10150 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 10151 | __lpfc_sli_ringtx_put(phba, |
| 10152 | pring, piocb); |
| 10153 | return IOCB_SUCCESS; |
| 10154 | } else { |
| 10155 | return IOCB_BUSY; |
| 10156 | } |
| 10157 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10158 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10159 | if (!sglq) { |
| 10160 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 10161 | __lpfc_sli_ringtx_put(phba, |
| 10162 | pring, |
| 10163 | piocb); |
| 10164 | return IOCB_SUCCESS; |
| 10165 | } else |
| 10166 | return IOCB_BUSY; |
| 10167 | } |
| 10168 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10169 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 10170 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10171 | /* These IO's already have an XRI and a mapped sgl. */ |
| 10172 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 10173 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10174 | /* |
| 10175 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10176 | * sglq is on the active list |
| 10177 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 10178 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10179 | if (!sglq) |
| 10180 | return IOCB_ERROR; |
| 10181 | } |
| 10182 | |
| 10183 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10184 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10185 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10186 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10187 | return IOCB_ERROR; |
| 10188 | } |
| 10189 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10190 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10191 | return IOCB_ERROR; |
| 10192 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10193 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10194 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10195 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 10196 | |
| 10197 | return 0; |
| 10198 | } |
| 10199 | |
| 10200 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10201 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 10202 | * |
| 10203 | * This routine wraps the actual lockless version for issusing IOCB function |
| 10204 | * pointer from the lpfc_hba struct. |
| 10205 | * |
| 10206 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10207 | * IOCB_ERROR - Error |
| 10208 | * IOCB_SUCCESS - Success |
| 10209 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10210 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10211 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10212 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 10213 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10214 | { |
| 10215 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10216 | } |
| 10217 | |
| 10218 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10219 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10220 | * @phba: The hba struct for which this call is being executed. |
| 10221 | * @dev_grp: The HBA PCI-Device group number. |
| 10222 | * |
| 10223 | * This routine sets up the SLI interface API function jump table in @phba |
| 10224 | * struct. |
| 10225 | * Returns: 0 - success, -ENODEV - failure. |
| 10226 | **/ |
| 10227 | int |
| 10228 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 10229 | { |
| 10230 | |
| 10231 | switch (dev_grp) { |
| 10232 | case LPFC_PCI_DEV_LP: |
| 10233 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 10234 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 10235 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10236 | case LPFC_PCI_DEV_OC: |
| 10237 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 10238 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 10239 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10240 | default: |
| 10241 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10242 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 10243 | dev_grp); |
| 10244 | return -ENODEV; |
| 10245 | break; |
| 10246 | } |
| 10247 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 10248 | return 0; |
| 10249 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10250 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10251 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10252 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10253 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10254 | * @piocb: Pointer to command iocb. |
| 10255 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10256 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 10257 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10258 | * 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] | 10259 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10260 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10261 | struct lpfc_sli_ring * |
| 10262 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10263 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10264 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10265 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10266 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10267 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 10268 | return NULL; |
| 10269 | /* |
| 10270 | * for abort iocb hba_wqidx should already |
| 10271 | * be setup based on what work queue we used. |
| 10272 | */ |
| 10273 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10274 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 10275 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10276 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10277 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10278 | } else { |
| 10279 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10280 | return NULL; |
| 10281 | piocb->hba_wqidx = 0; |
| 10282 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10283 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10284 | } |
| 10285 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10286 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10287 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10288 | * @phba: Pointer to HBA context object. |
| 10289 | * @pring: Pointer to driver SLI ring object. |
| 10290 | * @piocb: Pointer to command iocb. |
| 10291 | * @flag: Flag indicating if this command can be put into txq. |
| 10292 | * |
| 10293 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10294 | * function. This function gets the hbalock and calls |
| 10295 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10296 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10297 | * functions which do not hold hbalock. |
| 10298 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10299 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10300 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10301 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10302 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10303 | struct lpfc_sli_ring *pring; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10304 | struct lpfc_queue *eq; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10305 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10306 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10307 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10308 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10309 | eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq; |
| 10310 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10311 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10312 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10313 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10314 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10315 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10316 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10317 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10318 | |
| 10319 | lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10320 | } else { |
| 10321 | /* For now, SLI2/3 will still use hbalock */ |
| 10322 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10323 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10324 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10325 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10326 | return rc; |
| 10327 | } |
| 10328 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10329 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10330 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10331 | * @phba: Pointer to HBA context object. |
| 10332 | * |
| 10333 | * This function is called while driver attaches with the |
| 10334 | * HBA to setup the extra ring. The extra ring is used |
| 10335 | * only when driver needs to support target mode functionality |
| 10336 | * or IP over FC functionalities. |
| 10337 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10338 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10339 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10340 | static int |
| 10341 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10342 | { |
| 10343 | struct lpfc_sli *psli; |
| 10344 | struct lpfc_sli_ring *pring; |
| 10345 | |
| 10346 | psli = &phba->sli; |
| 10347 | |
| 10348 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10349 | |
| 10350 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10351 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10352 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10353 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10354 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10355 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10356 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10357 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10358 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10359 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10360 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10361 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10362 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10363 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10364 | |
| 10365 | /* Setup default profile for this ring */ |
| 10366 | pring->iotag_max = 4096; |
| 10367 | pring->num_mask = 1; |
| 10368 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10369 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10370 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10371 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10372 | return 0; |
| 10373 | } |
| 10374 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10375 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10376 | * @phba: Pointer to HBA context object. |
| 10377 | * @iocbq: Pointer to iocb object. |
| 10378 | * |
| 10379 | * The async_event handler calls this routine when it receives |
| 10380 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10381 | * this event when an Abort Sequence request to an rport fails |
| 10382 | * twice in succession. The abort could be originated by the |
| 10383 | * driver or by the port. The ABTS could have been for an ELS |
| 10384 | * or FCP IO. The port only generates this event when an ABTS |
| 10385 | * fails to complete after one retry. |
| 10386 | */ |
| 10387 | static void |
| 10388 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10389 | struct lpfc_iocbq *iocbq) |
| 10390 | { |
| 10391 | struct lpfc_nodelist *ndlp = NULL; |
| 10392 | uint16_t rpi = 0, vpi = 0; |
| 10393 | struct lpfc_vport *vport = NULL; |
| 10394 | |
| 10395 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10396 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10397 | rpi = iocbq->iocb.ulpContext; |
| 10398 | |
| 10399 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10400 | "3092 Port generated ABTS async event " |
| 10401 | "on vpi %d rpi %d status 0x%x\n", |
| 10402 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10403 | |
| 10404 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10405 | if (!vport) |
| 10406 | goto err_exit; |
| 10407 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 10408 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 10409 | goto err_exit; |
| 10410 | |
| 10411 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10412 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10413 | return; |
| 10414 | |
| 10415 | err_exit: |
| 10416 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10417 | "3095 Event Context not found, no " |
| 10418 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10419 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10420 | vpi, rpi); |
| 10421 | } |
| 10422 | |
| 10423 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10424 | * @phba: pointer to HBA context object. |
| 10425 | * @ndlp: nodelist pointer for the impacted rport. |
| 10426 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10427 | * |
| 10428 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10429 | * port. The port generates this event when an abort exchange request to an |
| 10430 | * rport fails twice in succession with no reply. The abort could be originated |
| 10431 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10432 | */ |
| 10433 | void |
| 10434 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10435 | struct lpfc_nodelist *ndlp, |
| 10436 | struct sli4_wcqe_xri_aborted *axri) |
| 10437 | { |
| 10438 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10439 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10440 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10441 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10442 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10443 | "3115 Node Context not found, driver " |
| 10444 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10445 | return; |
| 10446 | } |
| 10447 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10448 | vport = ndlp->vport; |
| 10449 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10450 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10451 | "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] | 10452 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10453 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10454 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10455 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10456 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10457 | /* |
| 10458 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10459 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10460 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10461 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10462 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10463 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10464 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10465 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10466 | } |
| 10467 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10468 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10469 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10470 | * @phba: Pointer to HBA context object. |
| 10471 | * @pring: Pointer to driver SLI ring object. |
| 10472 | * @iocbq: Pointer to iocb object. |
| 10473 | * |
| 10474 | * This function is called by the slow ring event handler |
| 10475 | * function when there is an ASYNC event iocb in the ring. |
| 10476 | * This function is called with no lock held. |
| 10477 | * Currently this function handles only temperature related |
| 10478 | * ASYNC events. The function decodes the temperature sensor |
| 10479 | * event message and posts events for the management applications. |
| 10480 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10481 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10482 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10483 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10484 | { |
| 10485 | IOCB_t *icmd; |
| 10486 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10487 | struct temp_event temp_event_data; |
| 10488 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10489 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10490 | |
| 10491 | icmd = &iocbq->iocb; |
| 10492 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10493 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10494 | switch (evt_code) { |
| 10495 | case ASYNC_TEMP_WARN: |
| 10496 | case ASYNC_TEMP_SAFE: |
| 10497 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10498 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10499 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10500 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 10501 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10502 | "0347 Adapter is very hot, please take " |
| 10503 | "corrective action. temperature : %d Celsius\n", |
| 10504 | (uint32_t) icmd->ulpContext); |
| 10505 | } else { |
| 10506 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 10507 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10508 | "0340 Adapter temperature is OK now. " |
| 10509 | "temperature : %d Celsius\n", |
| 10510 | (uint32_t) icmd->ulpContext); |
| 10511 | } |
| 10512 | |
| 10513 | /* Send temperature change event to applications */ |
| 10514 | shost = lpfc_shost_from_vport(phba->pport); |
| 10515 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10516 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10517 | LPFC_NL_VENDOR_ID); |
| 10518 | break; |
| 10519 | case ASYNC_STATUS_CN: |
| 10520 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10521 | break; |
| 10522 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10523 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10524 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10525 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10526 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10527 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10528 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10529 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10530 | "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] | 10531 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10532 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10533 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10534 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10535 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10536 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10537 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10538 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10539 | } |
| 10540 | |
| 10541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10542 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10543 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10544 | * @phba: Pointer to HBA context object. |
| 10545 | * |
| 10546 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10547 | * number of iocbs per ring and iotags. This function is |
| 10548 | * called while driver attach to the HBA and before the |
| 10549 | * interrupts are enabled. So there is no need for locking. |
| 10550 | * |
| 10551 | * This function always returns 0. |
| 10552 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10553 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10554 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10555 | { |
| 10556 | struct lpfc_sli_ring *pring; |
| 10557 | |
| 10558 | pring = phba->sli4_hba.els_wq->pring; |
| 10559 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10560 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10561 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10562 | pring->prt[0].type = FC_TYPE_ELS; |
| 10563 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10564 | lpfc_els_unsol_event; |
| 10565 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10566 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10567 | pring->prt[1].type = FC_TYPE_ELS; |
| 10568 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10569 | lpfc_els_unsol_event; |
| 10570 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10571 | /* NameServer Inquiry */ |
| 10572 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10573 | /* NameServer */ |
| 10574 | pring->prt[2].type = FC_TYPE_CT; |
| 10575 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10576 | lpfc_ct_unsol_event; |
| 10577 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10578 | /* NameServer response */ |
| 10579 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10580 | /* NameServer */ |
| 10581 | pring->prt[3].type = FC_TYPE_CT; |
| 10582 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10583 | lpfc_ct_unsol_event; |
| 10584 | return 0; |
| 10585 | } |
| 10586 | |
| 10587 | /** |
| 10588 | * lpfc_sli_setup - SLI ring setup function |
| 10589 | * @phba: Pointer to HBA context object. |
| 10590 | * |
| 10591 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10592 | * number of iocbs per ring and iotags. This function is |
| 10593 | * called while driver attach to the HBA and before the |
| 10594 | * interrupts are enabled. So there is no need for locking. |
| 10595 | * |
| 10596 | * This function always returns 0. SLI3 only. |
| 10597 | **/ |
| 10598 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10599 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10600 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10601 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10602 | struct lpfc_sli *psli = &phba->sli; |
| 10603 | struct lpfc_sli_ring *pring; |
| 10604 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10605 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10606 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10607 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10608 | psli->iocbq_lookup = NULL; |
| 10609 | psli->iocbq_lookup_len = 0; |
| 10610 | psli->last_iotag = 0; |
| 10611 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10612 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10613 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10614 | switch (i) { |
| 10615 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10616 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10617 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10618 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10619 | pring->sli.sli3.numCiocb += |
| 10620 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10621 | pring->sli.sli3.numRiocb += |
| 10622 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10623 | pring->sli.sli3.numCiocb += |
| 10624 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10625 | pring->sli.sli3.numRiocb += |
| 10626 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10627 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10628 | SLI3_IOCB_CMD_SIZE : |
| 10629 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10630 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10631 | SLI3_IOCB_RSP_SIZE : |
| 10632 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10633 | pring->iotag_ctr = 0; |
| 10634 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10635 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10636 | pring->fast_iotag = pring->iotag_max; |
| 10637 | pring->num_mask = 0; |
| 10638 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10639 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10640 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10641 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10642 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10643 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10644 | SLI3_IOCB_CMD_SIZE : |
| 10645 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10646 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10647 | SLI3_IOCB_RSP_SIZE : |
| 10648 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10649 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10650 | pring->num_mask = 0; |
| 10651 | break; |
| 10652 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10653 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10654 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10655 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10656 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10657 | SLI3_IOCB_CMD_SIZE : |
| 10658 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10659 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10660 | SLI3_IOCB_RSP_SIZE : |
| 10661 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10662 | pring->fast_iotag = 0; |
| 10663 | pring->iotag_ctr = 0; |
| 10664 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10665 | pring->lpfc_sli_rcv_async_status = |
| 10666 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10667 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10668 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10669 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10670 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10671 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10672 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10673 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10674 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10675 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10676 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10677 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10678 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10679 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10680 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10681 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10682 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10683 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10684 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10685 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10686 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10687 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10688 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10689 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10690 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10691 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10692 | break; |
| 10693 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10694 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10695 | pring->sli.sli3.sizeCiocb) + |
| 10696 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10697 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10698 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10699 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10700 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10701 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10702 | phba->brd_no, totiocbsize, |
| 10703 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10704 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10705 | if (phba->cfg_multi_ring_support == 2) |
| 10706 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10707 | |
| 10708 | return 0; |
| 10709 | } |
| 10710 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10711 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10712 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10713 | * @phba: Pointer to HBA context object. |
| 10714 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10715 | * 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] | 10716 | * ring. This function also initializes ring indices of each ring. |
| 10717 | * This function is called during the initialization of the SLI |
| 10718 | * interface of an HBA. |
| 10719 | * This function is called with no lock held and always returns |
| 10720 | * 1. |
| 10721 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10722 | void |
| 10723 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10724 | { |
| 10725 | struct lpfc_sli *psli; |
| 10726 | struct lpfc_sli_ring *pring; |
| 10727 | int i; |
| 10728 | |
| 10729 | psli = &phba->sli; |
| 10730 | spin_lock_irq(&phba->hbalock); |
| 10731 | INIT_LIST_HEAD(&psli->mboxq); |
| 10732 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10733 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10734 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10735 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10736 | pring->flag = 0; |
| 10737 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10738 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10739 | INIT_LIST_HEAD(&pring->txq); |
| 10740 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10741 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10742 | spin_lock_init(&pring->ring_lock); |
| 10743 | } |
| 10744 | pring = phba->sli4_hba.els_wq->pring; |
| 10745 | pring->flag = 0; |
| 10746 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10747 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10748 | INIT_LIST_HEAD(&pring->txq); |
| 10749 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10750 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10751 | spin_lock_init(&pring->ring_lock); |
| 10752 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10753 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10754 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10755 | pring->flag = 0; |
| 10756 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10757 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10758 | INIT_LIST_HEAD(&pring->txq); |
| 10759 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10760 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10761 | spin_lock_init(&pring->ring_lock); |
| 10762 | } |
| 10763 | |
| 10764 | spin_unlock_irq(&phba->hbalock); |
| 10765 | } |
| 10766 | |
| 10767 | /** |
| 10768 | * lpfc_sli_queue_init - Queue initialization function |
| 10769 | * @phba: Pointer to HBA context object. |
| 10770 | * |
| 10771 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10772 | * ring. This function also initializes ring indices of each ring. |
| 10773 | * This function is called during the initialization of the SLI |
| 10774 | * interface of an HBA. |
| 10775 | * This function is called with no lock held and always returns |
| 10776 | * 1. |
| 10777 | **/ |
| 10778 | void |
| 10779 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10780 | { |
| 10781 | struct lpfc_sli *psli; |
| 10782 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10783 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10784 | |
| 10785 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10786 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10787 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10788 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10789 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10790 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10791 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10792 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10793 | pring->sli.sli3.next_cmdidx = 0; |
| 10794 | pring->sli.sli3.local_getidx = 0; |
| 10795 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10796 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10797 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10798 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10799 | pring->flag = 0; |
| 10800 | INIT_LIST_HEAD(&pring->txq); |
| 10801 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10802 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10803 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10804 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10805 | } |
| 10806 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10807 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10808 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10809 | * @phba: Pointer to HBA context object. |
| 10810 | * |
| 10811 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10812 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10813 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10814 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10815 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10816 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10817 | * pending mailbox command queue from the various clients must be stopped; |
| 10818 | * either the HBA is in a state that it will never works on the outstanding |
| 10819 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10820 | * mailbox command has been completed. |
| 10821 | **/ |
| 10822 | static void |
| 10823 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10824 | { |
| 10825 | LIST_HEAD(completions); |
| 10826 | struct lpfc_sli *psli = &phba->sli; |
| 10827 | LPFC_MBOXQ_t *pmb; |
| 10828 | unsigned long iflag; |
| 10829 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10830 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10831 | local_bh_disable(); |
| 10832 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10833 | /* Flush all the mailbox commands in the mbox system */ |
| 10834 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10835 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10836 | /* The pending mailbox command queue */ |
| 10837 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10838 | /* The outstanding active mailbox command */ |
| 10839 | if (psli->mbox_active) { |
| 10840 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10841 | psli->mbox_active = NULL; |
| 10842 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10843 | } |
| 10844 | /* The completed mailbox command queue */ |
| 10845 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10846 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10847 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10848 | /* Enable softirqs again, done with phba->hbalock */ |
| 10849 | local_bh_enable(); |
| 10850 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10851 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10852 | while (!list_empty(&completions)) { |
| 10853 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10854 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10855 | if (pmb->mbox_cmpl) |
| 10856 | pmb->mbox_cmpl(phba, pmb); |
| 10857 | } |
| 10858 | } |
| 10859 | |
| 10860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10861 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10862 | * @vport: Pointer to virtual port object. |
| 10863 | * |
| 10864 | * lpfc_sli_host_down is called to clean up the resources |
| 10865 | * associated with a vport before destroying virtual |
| 10866 | * port data structures. |
| 10867 | * This function does following operations: |
| 10868 | * - Free discovery resources associated with this virtual |
| 10869 | * port. |
| 10870 | * - Free iocbs associated with this virtual port in |
| 10871 | * the txq. |
| 10872 | * - Send abort for all iocb commands associated with this |
| 10873 | * vport in txcmplq. |
| 10874 | * |
| 10875 | * This function is called with no lock held and always returns 1. |
| 10876 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10877 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10878 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10879 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10880 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10881 | struct lpfc_hba *phba = vport->phba; |
| 10882 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10883 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10884 | struct lpfc_sli_ring *pring; |
| 10885 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10886 | int i; |
| 10887 | unsigned long flags = 0; |
| 10888 | uint16_t prev_pring_flag; |
| 10889 | |
| 10890 | lpfc_cleanup_discovery_resources(vport); |
| 10891 | |
| 10892 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10893 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10894 | /* |
| 10895 | * Error everything on the txq since these iocbs |
| 10896 | * have not been given to the FW yet. |
| 10897 | * Also issue ABTS for everything on the txcmplq |
| 10898 | */ |
| 10899 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10900 | for (i = 0; i < psli->num_rings; i++) { |
| 10901 | pring = &psli->sli3_ring[i]; |
| 10902 | prev_pring_flag = pring->flag; |
| 10903 | /* Only slow rings */ |
| 10904 | if (pring->ringno == LPFC_ELS_RING) { |
| 10905 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10906 | /* Set the lpfc data pending flag */ |
| 10907 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10908 | } |
| 10909 | list_for_each_entry_safe(iocb, next_iocb, |
| 10910 | &pring->txq, list) { |
| 10911 | if (iocb->vport != vport) |
| 10912 | continue; |
| 10913 | list_move_tail(&iocb->list, &completions); |
| 10914 | } |
| 10915 | list_for_each_entry_safe(iocb, next_iocb, |
| 10916 | &pring->txcmplq, list) { |
| 10917 | if (iocb->vport != vport) |
| 10918 | continue; |
| 10919 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10920 | } |
| 10921 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10922 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10923 | } else { |
| 10924 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10925 | pring = qp->pring; |
| 10926 | if (!pring) |
| 10927 | continue; |
| 10928 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10929 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10930 | /* Set the lpfc data pending flag */ |
| 10931 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10932 | } |
| 10933 | prev_pring_flag = pring->flag; |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10934 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10935 | list_for_each_entry_safe(iocb, next_iocb, |
| 10936 | &pring->txq, list) { |
| 10937 | if (iocb->vport != vport) |
| 10938 | continue; |
| 10939 | list_move_tail(&iocb->list, &completions); |
| 10940 | } |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10941 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10942 | list_for_each_entry_safe(iocb, next_iocb, |
| 10943 | &pring->txcmplq, list) { |
| 10944 | if (iocb->vport != vport) |
| 10945 | continue; |
| 10946 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10947 | } |
| 10948 | pring->flag = prev_pring_flag; |
| 10949 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10950 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10951 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10952 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10953 | /* Cancel all the IOCBs from the completions list */ |
| 10954 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10955 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10956 | return 1; |
| 10957 | } |
| 10958 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10959 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10960 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10961 | * @phba: Pointer to HBA context object. |
| 10962 | * |
| 10963 | * This function cleans up all iocb, buffers, mailbox commands |
| 10964 | * while shutting down the HBA. This function is called with no |
| 10965 | * lock held and always returns 1. |
| 10966 | * This function does the following to cleanup driver resources: |
| 10967 | * - Free discovery resources for each virtual port |
| 10968 | * - Cleanup any pending fabric iocbs |
| 10969 | * - Iterate through the iocb txq and free each entry |
| 10970 | * in the list. |
| 10971 | * - Free up any buffer posted to the HBA |
| 10972 | * - Free mailbox commands in the mailbox queue. |
| 10973 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10974 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10975 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10976 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10977 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10978 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10979 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10980 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10981 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10982 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10983 | int i; |
| 10984 | |
| 10985 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10986 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10987 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10988 | lpfc_hba_down_prep(phba); |
| 10989 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10990 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10991 | local_bh_disable(); |
| 10992 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10993 | lpfc_fabric_abort_hba(phba); |
| 10994 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10995 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10996 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10997 | /* |
| 10998 | * Error everything on the txq since these iocbs |
| 10999 | * have not been given to the FW yet. |
| 11000 | */ |
| 11001 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11002 | for (i = 0; i < psli->num_rings; i++) { |
| 11003 | pring = &psli->sli3_ring[i]; |
| 11004 | /* Only slow rings */ |
| 11005 | if (pring->ringno == LPFC_ELS_RING) { |
| 11006 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11007 | /* Set the lpfc data pending flag */ |
| 11008 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11009 | } |
| 11010 | list_splice_init(&pring->txq, &completions); |
| 11011 | } |
| 11012 | } else { |
| 11013 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11014 | pring = qp->pring; |
| 11015 | if (!pring) |
| 11016 | continue; |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 11017 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11018 | list_splice_init(&pring->txq, &completions); |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 11019 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11020 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 11021 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11022 | /* Set the lpfc data pending flag */ |
| 11023 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11024 | } |
| 11025 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11026 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11027 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11028 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11029 | /* Cancel all the IOCBs from the completions list */ |
| 11030 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 11031 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 11032 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 11033 | spin_lock_irqsave(&phba->hbalock, flags); |
| 11034 | list_splice_init(&phba->elsbuf, &completions); |
| 11035 | phba->elsbuf_cnt = 0; |
| 11036 | phba->elsbuf_prev_cnt = 0; |
| 11037 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 11038 | |
| 11039 | while (!list_empty(&completions)) { |
| 11040 | list_remove_head(&completions, buf_ptr, |
| 11041 | struct lpfc_dmabuf, list); |
| 11042 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 11043 | kfree(buf_ptr); |
| 11044 | } |
| 11045 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11046 | /* Enable softirqs again, done with phba->hbalock */ |
| 11047 | local_bh_enable(); |
| 11048 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11049 | /* Return any active mbox cmds */ |
| 11050 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11051 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11052 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11053 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11054 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11055 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11056 | return 1; |
| 11057 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11058 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11059 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11060 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11061 | * @srcp: Source memory pointer. |
| 11062 | * @destp: Destination memory pointer. |
| 11063 | * @cnt: Number of words required to be copied. |
| 11064 | * |
| 11065 | * This function is used for copying data between driver memory |
| 11066 | * and the SLI memory. This function also changes the endianness |
| 11067 | * of each word if native endianness is different from SLI |
| 11068 | * endianness. This function can be called with or without |
| 11069 | * lock. |
| 11070 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11071 | void |
| 11072 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 11073 | { |
| 11074 | uint32_t *src = srcp; |
| 11075 | uint32_t *dest = destp; |
| 11076 | uint32_t ldata; |
| 11077 | int i; |
| 11078 | |
| 11079 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 11080 | ldata = *src; |
| 11081 | ldata = le32_to_cpu(ldata); |
| 11082 | *dest = ldata; |
| 11083 | src++; |
| 11084 | dest++; |
| 11085 | } |
| 11086 | } |
| 11087 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11088 | |
| 11089 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 11090 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 11091 | * @srcp: Source memory pointer. |
| 11092 | * @destp: Destination memory pointer. |
| 11093 | * @cnt: Number of words required to be copied. |
| 11094 | * |
| 11095 | * This function is used for copying data between a data structure |
| 11096 | * with big endian representation to local endianness. |
| 11097 | * This function can be called with or without lock. |
| 11098 | **/ |
| 11099 | void |
| 11100 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 11101 | { |
| 11102 | uint32_t *src = srcp; |
| 11103 | uint32_t *dest = destp; |
| 11104 | uint32_t ldata; |
| 11105 | int i; |
| 11106 | |
| 11107 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 11108 | ldata = *src; |
| 11109 | ldata = be32_to_cpu(ldata); |
| 11110 | *dest = ldata; |
| 11111 | src++; |
| 11112 | dest++; |
| 11113 | } |
| 11114 | } |
| 11115 | |
| 11116 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11117 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11118 | * @phba: Pointer to HBA context object. |
| 11119 | * @pring: Pointer to driver SLI ring object. |
| 11120 | * @mp: Pointer to driver buffer object. |
| 11121 | * |
| 11122 | * This function is called with no lock held. |
| 11123 | * It always return zero after adding the buffer to the postbufq |
| 11124 | * buffer list. |
| 11125 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11126 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11127 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11128 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11129 | { |
| 11130 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 11131 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11132 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11133 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11134 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11135 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11136 | return 0; |
| 11137 | } |
| 11138 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11139 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11140 | * 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] | 11141 | * @phba: Pointer to HBA context object. |
| 11142 | * |
| 11143 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 11144 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 11145 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 11146 | * does not conflict with tags of buffer posted for unsolicited events. |
| 11147 | * The function returns the allocated tag. The function is called with |
| 11148 | * no locks held. |
| 11149 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11150 | uint32_t |
| 11151 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 11152 | { |
| 11153 | spin_lock_irq(&phba->hbalock); |
| 11154 | phba->buffer_tag_count++; |
| 11155 | /* |
| 11156 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 11157 | * a tag assigned by HBQ. |
| 11158 | */ |
| 11159 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 11160 | spin_unlock_irq(&phba->hbalock); |
| 11161 | return phba->buffer_tag_count; |
| 11162 | } |
| 11163 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11164 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11165 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11166 | * @phba: Pointer to HBA context object. |
| 11167 | * @pring: Pointer to driver SLI ring object. |
| 11168 | * @tag: Buffer tag. |
| 11169 | * |
| 11170 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 11171 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 11172 | * iocb is posted to the response ring with the tag of the buffer. |
| 11173 | * This function searches the pring->postbufq list using the tag |
| 11174 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 11175 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 11176 | * buffer is returned to the caller else NULL is returned. |
| 11177 | * This function is called with no lock held. |
| 11178 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11179 | struct lpfc_dmabuf * |
| 11180 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11181 | uint32_t tag) |
| 11182 | { |
| 11183 | struct lpfc_dmabuf *mp, *next_mp; |
| 11184 | struct list_head *slp = &pring->postbufq; |
| 11185 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11186 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11187 | spin_lock_irq(&phba->hbalock); |
| 11188 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11189 | if (mp->buffer_tag == tag) { |
| 11190 | list_del_init(&mp->list); |
| 11191 | pring->postbufq_cnt--; |
| 11192 | spin_unlock_irq(&phba->hbalock); |
| 11193 | return mp; |
| 11194 | } |
| 11195 | } |
| 11196 | |
| 11197 | spin_unlock_irq(&phba->hbalock); |
| 11198 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11199 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11200 | "ring %d Data x%lx x%px x%px x%x\n", |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11201 | pring->ringno, (unsigned long) tag, |
| 11202 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11203 | |
| 11204 | return NULL; |
| 11205 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11208 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11209 | * @phba: Pointer to HBA context object. |
| 11210 | * @pring: Pointer to driver SLI ring object. |
| 11211 | * @phys: DMA address of the buffer. |
| 11212 | * |
| 11213 | * This function searches the buffer list using the dma_address |
| 11214 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 11215 | * corresponding to the dma_address. The function returns the |
| 11216 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 11217 | * This function is called by the ct and els unsolicited event |
| 11218 | * handlers to get the buffer associated with the unsolicited |
| 11219 | * event. |
| 11220 | * |
| 11221 | * This function is called with no lock held. |
| 11222 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11223 | struct lpfc_dmabuf * |
| 11224 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11225 | dma_addr_t phys) |
| 11226 | { |
| 11227 | struct lpfc_dmabuf *mp, *next_mp; |
| 11228 | struct list_head *slp = &pring->postbufq; |
| 11229 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11230 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11231 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11232 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11233 | if (mp->phys == phys) { |
| 11234 | list_del_init(&mp->list); |
| 11235 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11236 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11237 | return mp; |
| 11238 | } |
| 11239 | } |
| 11240 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11241 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11243 | "0410 Cannot find virtual addr for mapped buf on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11244 | "ring %d Data x%llx x%px x%px x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11245 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11246 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11247 | return NULL; |
| 11248 | } |
| 11249 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11251 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11252 | * @phba: Pointer to HBA context object. |
| 11253 | * @cmdiocb: Pointer to driver command iocb object. |
| 11254 | * @rspiocb: Pointer to driver response iocb object. |
| 11255 | * |
| 11256 | * This function is the completion handler for the abort iocbs for |
| 11257 | * ELS commands. This function is called from the ELS ring event |
| 11258 | * handler with no lock held. This function frees memory resources |
| 11259 | * associated with the abort iocb. |
| 11260 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11261 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11262 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11263 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11264 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11265 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11266 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11267 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11268 | |
| 11269 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11270 | |
| 11271 | /* |
| 11272 | * Assume that the port already completed and returned, or |
| 11273 | * will return the iocb. Just Log the message. |
| 11274 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11275 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11276 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11277 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11278 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11279 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11280 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11281 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11282 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11283 | spin_unlock_irq(&phba->hbalock); |
| 11284 | goto release_iocb; |
| 11285 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11286 | if (abort_iotag != 0 && |
| 11287 | abort_iotag <= phba->sli.last_iotag) |
| 11288 | abort_iocb = |
| 11289 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11290 | } else |
| 11291 | /* For sli4 the abort_tag is the XRI, |
| 11292 | * so the abort routine puts the iotag of the iocb |
| 11293 | * being aborted in the context field of the abort |
| 11294 | * IOCB. |
| 11295 | */ |
| 11296 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11297 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11298 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11299 | "0327 Cannot abort els iocb x%px " |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11300 | "with tag %x context %x, abort status %x, " |
| 11301 | "abort code %x\n", |
| 11302 | abort_iocb, abort_iotag, abort_context, |
| 11303 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11304 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11305 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11306 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11307 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11308 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11309 | return; |
| 11310 | } |
| 11311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11313 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11314 | * @phba: Pointer to HBA context object. |
| 11315 | * @cmdiocb: Pointer to driver command iocb object. |
| 11316 | * @rspiocb: Pointer to driver response iocb object. |
| 11317 | * |
| 11318 | * The function is called from SLI ring event handler with no |
| 11319 | * lock held. This function is the completion handler for ELS commands |
| 11320 | * which are aborted. The function frees memory resources used for |
| 11321 | * the aborted ELS commands. |
| 11322 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11323 | static void |
| 11324 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11325 | struct lpfc_iocbq *rspiocb) |
| 11326 | { |
| 11327 | IOCB_t *irsp = &rspiocb->iocb; |
| 11328 | |
| 11329 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11330 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11331 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11332 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11333 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11334 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11335 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11336 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11337 | else |
| 11338 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11339 | return; |
| 11340 | } |
| 11341 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11342 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11343 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11344 | * @phba: Pointer to HBA context object. |
| 11345 | * @pring: Pointer to driver SLI ring object. |
| 11346 | * @cmdiocb: Pointer to driver command iocb object. |
| 11347 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11348 | * This function issues an abort iocb for the provided command iocb down to |
| 11349 | * the port. Other than the case the outstanding command iocb is an abort |
| 11350 | * request, this function issues abort out unconditionally. This function is |
| 11351 | * called with hbalock held. The function returns 0 when it fails due to |
| 11352 | * memory allocation failure or when the command iocb is an abort request. |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 11353 | * The hbalock is asserted held in the code path calling this routine. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11354 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11355 | static int |
| 11356 | 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] | 11357 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11358 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11359 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11360 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11361 | IOCB_t *icmd = NULL; |
| 11362 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11363 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11364 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11365 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11366 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11367 | /* |
| 11368 | * There are certain command types we don't want to abort. And we |
| 11369 | * don't want to abort commands that are already in the process of |
| 11370 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11371 | */ |
| 11372 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11373 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11374 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11375 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11376 | return 0; |
| 11377 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11378 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11379 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11380 | if (abtsiocbp == NULL) |
| 11381 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11382 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11383 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11384 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11385 | */ |
| 11386 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11387 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11388 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11389 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11390 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11391 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11392 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11393 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11394 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11395 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11396 | if (pring->ringno == LPFC_ELS_RING) { |
| 11397 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11398 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11399 | } |
| 11400 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11401 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11402 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11403 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11404 | /* 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] | 11405 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11406 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 11407 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11408 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11409 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11410 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11411 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11412 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11413 | else |
| 11414 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11415 | |
| 11416 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11417 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11418 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11419 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11420 | "0339 Abort xri x%x, original iotag x%x, " |
| 11421 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11422 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11423 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11424 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11425 | |
| 11426 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11427 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11428 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11429 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11430 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11431 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11432 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11433 | abtsiocbp, 0); |
| 11434 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11435 | } else { |
| 11436 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11437 | abtsiocbp, 0); |
| 11438 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11439 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11440 | if (retval) |
| 11441 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11442 | |
| 11443 | /* |
| 11444 | * Caller to this routine should check for IOCB_ERROR |
| 11445 | * and handle it properly. This routine no longer removes |
| 11446 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 11447 | */ |
| 11448 | return retval; |
| 11449 | } |
| 11450 | |
| 11451 | /** |
| 11452 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 11453 | * @phba: Pointer to HBA context object. |
| 11454 | * @pring: Pointer to driver SLI ring object. |
| 11455 | * @cmdiocb: Pointer to driver command iocb object. |
| 11456 | * |
| 11457 | * This function issues an abort iocb for the provided command iocb. In case |
| 11458 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11459 | * ring. Instead, the callback function shall be changed to those commands |
| 11460 | * so that nothing happens when them finishes. This function is called with |
| 11461 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 11462 | * request. |
| 11463 | **/ |
| 11464 | int |
| 11465 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11466 | struct lpfc_iocbq *cmdiocb) |
| 11467 | { |
| 11468 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11469 | int retval = IOCB_ERROR; |
| 11470 | IOCB_t *icmd = NULL; |
| 11471 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11472 | lockdep_assert_held(&phba->hbalock); |
| 11473 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11474 | /* |
| 11475 | * There are certain command types we don't want to abort. And we |
| 11476 | * don't want to abort commands that are already in the process of |
| 11477 | * being aborted. |
| 11478 | */ |
| 11479 | icmd = &cmdiocb->iocb; |
| 11480 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11481 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11482 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11483 | return 0; |
| 11484 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 11485 | if (!pring) { |
| 11486 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11487 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11488 | else |
| 11489 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11490 | goto abort_iotag_exit; |
| 11491 | } |
| 11492 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11493 | /* |
| 11494 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11495 | * the callback so that nothing happens when it finishes. |
| 11496 | */ |
| 11497 | if ((vport->load_flag & FC_UNLOADING) && |
| 11498 | (pring->ringno == LPFC_ELS_RING)) { |
| 11499 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11500 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11501 | else |
| 11502 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11503 | goto abort_iotag_exit; |
| 11504 | } |
| 11505 | |
| 11506 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 11507 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 11508 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11509 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11510 | /* |
| 11511 | * Caller to this routine should check for IOCB_ERROR |
| 11512 | * and handle it properly. This routine no longer removes |
| 11513 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11514 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11515 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11516 | } |
| 11517 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11518 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11519 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11520 | * @phba: pointer to lpfc HBA data structure. |
| 11521 | * |
| 11522 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11523 | **/ |
| 11524 | void |
| 11525 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11526 | { |
| 11527 | struct lpfc_sli *psli = &phba->sli; |
| 11528 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11529 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11530 | int i; |
| 11531 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11532 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11533 | for (i = 0; i < psli->num_rings; i++) { |
| 11534 | pring = &psli->sli3_ring[i]; |
| 11535 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11536 | } |
| 11537 | return; |
| 11538 | } |
| 11539 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11540 | pring = qp->pring; |
| 11541 | if (!pring) |
| 11542 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11543 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11544 | } |
| 11545 | } |
| 11546 | |
| 11547 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11548 | * 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] | 11549 | * @iocbq: Pointer to driver iocb object. |
| 11550 | * @vport: Pointer to driver virtual port object. |
| 11551 | * @tgt_id: SCSI ID of the target. |
| 11552 | * @lun_id: LUN ID of the scsi device. |
| 11553 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11554 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11555 | * 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] | 11556 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11557 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11558 | * 1 if the filtering criteria is not met. |
| 11559 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11560 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11561 | * lun_id parameter. |
| 11562 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11563 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11564 | * parameters. |
| 11565 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11566 | * given iocb is for the SCSI host associated with the given vport. |
| 11567 | * This function is called with no locks held. |
| 11568 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11569 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11570 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11571 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11572 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11573 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11574 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11575 | int rc = 1; |
| 11576 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11577 | if (iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11578 | return rc; |
| 11579 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11580 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11581 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11582 | return rc; |
| 11583 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11584 | 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] | 11585 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11586 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11587 | return rc; |
| 11588 | |
| 11589 | switch (ctx_cmd) { |
| 11590 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11591 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11592 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11593 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11594 | rc = 0; |
| 11595 | break; |
| 11596 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11597 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11598 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11599 | rc = 0; |
| 11600 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11601 | case LPFC_CTX_HOST: |
| 11602 | rc = 0; |
| 11603 | break; |
| 11604 | default: |
| 11605 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11606 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11607 | break; |
| 11608 | } |
| 11609 | |
| 11610 | return rc; |
| 11611 | } |
| 11612 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11613 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11614 | * 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] | 11615 | * @vport: Pointer to virtual port. |
| 11616 | * @tgt_id: SCSI ID of the target. |
| 11617 | * @lun_id: LUN ID of the scsi device. |
| 11618 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11619 | * |
| 11620 | * This function returns number of FCP commands pending for the vport. |
| 11621 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11622 | * commands pending on the vport associated with SCSI device specified |
| 11623 | * by tgt_id and lun_id parameters. |
| 11624 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11625 | * commands pending on the vport associated with SCSI target specified |
| 11626 | * by tgt_id parameter. |
| 11627 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11628 | * commands pending on the vport. |
| 11629 | * This function returns the number of iocbs which satisfy the filter. |
| 11630 | * This function is called without any lock held. |
| 11631 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11632 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11633 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11634 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11635 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11636 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11637 | struct lpfc_iocbq *iocbq; |
| 11638 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11639 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11640 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11641 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11642 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11643 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11644 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11645 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11646 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11647 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11648 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11649 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11650 | return sum; |
| 11651 | } |
| 11652 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11653 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11654 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11655 | * @phba: Pointer to HBA context object |
| 11656 | * @cmdiocb: Pointer to command iocb object. |
| 11657 | * @rspiocb: Pointer to response iocb object. |
| 11658 | * |
| 11659 | * This function is called when an aborted FCP iocb completes. This |
| 11660 | * function is called by the ring event handler with no lock held. |
| 11661 | * This function frees the iocb. |
| 11662 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11663 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11664 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11665 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11666 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11667 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11668 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11669 | "original iotag x%x, abort cmd iotag x%x " |
| 11670 | "status 0x%x, reason 0x%x\n", |
| 11671 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11672 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11673 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11674 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11675 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11676 | return; |
| 11677 | } |
| 11678 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11679 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11680 | * 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] | 11681 | * @vport: Pointer to virtual port. |
| 11682 | * @pring: Pointer to driver SLI ring object. |
| 11683 | * @tgt_id: SCSI ID of the target. |
| 11684 | * @lun_id: LUN ID of the scsi device. |
| 11685 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11686 | * |
| 11687 | * This function sends an abort command for every SCSI command |
| 11688 | * associated with the given virtual port pending on the ring |
| 11689 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11690 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11691 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11692 | * parameters |
| 11693 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11694 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11695 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11696 | * FCP iocbs associated with virtual port. |
| 11697 | * This function returns number of iocbs it failed to abort. |
| 11698 | * This function is called with no locks held. |
| 11699 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11700 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11701 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11702 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11703 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11704 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11705 | struct lpfc_iocbq *iocbq; |
| 11706 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11707 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11708 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11709 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11710 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11711 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11712 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11713 | if (phba->hba_flag & HBA_IOQ_FLUSH) |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11714 | return errcnt; |
| 11715 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11716 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11717 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11718 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11719 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11720 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11721 | continue; |
| 11722 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11723 | /* |
| 11724 | * If the iocbq is already being aborted, don't take a second |
| 11725 | * action, but do count it. |
| 11726 | */ |
| 11727 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11728 | continue; |
| 11729 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11730 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11731 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11732 | if (abtsiocb == NULL) { |
| 11733 | errcnt++; |
| 11734 | continue; |
| 11735 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11736 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11737 | /* indicate the IO is being aborted by the driver. */ |
| 11738 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11739 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11740 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11741 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11742 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11743 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11744 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11745 | else |
| 11746 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11747 | abtsiocb->iocb.ulpLe = 1; |
| 11748 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11749 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11750 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11751 | /* 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] | 11752 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11753 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11754 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11755 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11756 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11757 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11758 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11759 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11760 | else |
| 11761 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11762 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11763 | /* Setup callback routine and issue the command. */ |
| 11764 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11765 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11766 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11767 | if (!pring_s4) |
| 11768 | continue; |
| 11769 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11770 | abtsiocb, 0); |
| 11771 | } else |
| 11772 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11773 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11774 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11775 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11776 | errcnt++; |
| 11777 | continue; |
| 11778 | } |
| 11779 | } |
| 11780 | |
| 11781 | return errcnt; |
| 11782 | } |
| 11783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11784 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11785 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11786 | * @vport: Pointer to virtual port. |
| 11787 | * @pring: Pointer to driver SLI ring object. |
| 11788 | * @tgt_id: SCSI ID of the target. |
| 11789 | * @lun_id: LUN ID of the scsi device. |
| 11790 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11791 | * |
| 11792 | * This function sends an abort command for every SCSI command |
| 11793 | * associated with the given virtual port pending on the ring |
| 11794 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11795 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11796 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11797 | * parameters |
| 11798 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11799 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11800 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11801 | * FCP iocbs associated with virtual port. |
| 11802 | * This function returns number of iocbs it aborted . |
| 11803 | * This function is called with no locks held right after a taskmgmt |
| 11804 | * command is sent. |
| 11805 | **/ |
| 11806 | int |
| 11807 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11808 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11809 | { |
| 11810 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11811 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11812 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11813 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11814 | struct lpfc_iocbq *iocbq; |
| 11815 | IOCB_t *icmd; |
| 11816 | int sum, i, ret_val; |
| 11817 | unsigned long iflags; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11818 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11819 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11820 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11821 | |
| 11822 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11823 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11824 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11825 | return 0; |
| 11826 | } |
| 11827 | sum = 0; |
| 11828 | |
| 11829 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11830 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11831 | |
| 11832 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11833 | cmd) != 0) |
| 11834 | continue; |
| 11835 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11836 | /* Guard against IO completion being called at same time */ |
| 11837 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
| 11838 | spin_lock(&lpfc_cmd->buf_lock); |
| 11839 | |
| 11840 | if (!lpfc_cmd->pCmd) { |
| 11841 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11842 | continue; |
| 11843 | } |
| 11844 | |
| 11845 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11846 | pring_s4 = |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11847 | phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11848 | if (!pring_s4) { |
| 11849 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11850 | continue; |
| 11851 | } |
| 11852 | /* Note: both hbalock and ring_lock must be set here */ |
| 11853 | spin_lock(&pring_s4->ring_lock); |
| 11854 | } |
| 11855 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11856 | /* |
| 11857 | * If the iocbq is already being aborted, don't take a second |
| 11858 | * action, but do count it. |
| 11859 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11860 | if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) || |
| 11861 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
| 11862 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11863 | spin_unlock(&pring_s4->ring_lock); |
| 11864 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11865 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11866 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11867 | |
| 11868 | /* issue ABTS for this IOCB based on iotag */ |
| 11869 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11870 | if (!abtsiocbq) { |
| 11871 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11872 | spin_unlock(&pring_s4->ring_lock); |
| 11873 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11874 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11875 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11876 | |
| 11877 | icmd = &iocbq->iocb; |
| 11878 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11879 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11880 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11881 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11882 | iocbq->sli4_xritag; |
| 11883 | else |
| 11884 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11885 | abtsiocbq->iocb.ulpLe = 1; |
| 11886 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11887 | abtsiocbq->vport = vport; |
| 11888 | |
| 11889 | /* 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] | 11890 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11891 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11892 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11893 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11894 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11895 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11896 | ndlp = lpfc_cmd->rdata->pnode; |
| 11897 | |
| 11898 | if (lpfc_is_link_up(phba) && |
| 11899 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11900 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11901 | else |
| 11902 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11903 | |
| 11904 | /* Setup callback routine and issue the command. */ |
| 11905 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11906 | |
| 11907 | /* |
| 11908 | * Indicate the IO is being aborted by the driver and set |
| 11909 | * the caller's flag into the aborted IO. |
| 11910 | */ |
| 11911 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11912 | |
| 11913 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11914 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11915 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11916 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11917 | } else { |
| 11918 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11919 | abtsiocbq, 0); |
| 11920 | } |
| 11921 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11922 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11923 | |
| 11924 | if (ret_val == IOCB_ERROR) |
| 11925 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11926 | else |
| 11927 | sum++; |
| 11928 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11929 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11930 | return sum; |
| 11931 | } |
| 11932 | |
| 11933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11934 | * 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] | 11935 | * @phba: Pointer to HBA context object. |
| 11936 | * @cmdiocbq: Pointer to command iocb. |
| 11937 | * @rspiocbq: Pointer to response iocb. |
| 11938 | * |
| 11939 | * This function is the completion handler for iocbs issued using |
| 11940 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11941 | * ring event handler function without any lock held. This function |
| 11942 | * can be called from both worker thread context and interrupt |
| 11943 | * context. This function also can be called from other thread which |
| 11944 | * cleans up the SLI layer objects. |
| 11945 | * This function copy the contents of the response iocb to the |
| 11946 | * response iocb memory object provided by the caller of |
| 11947 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11948 | * sleeps for the iocb completion. |
| 11949 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11950 | static void |
| 11951 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11952 | struct lpfc_iocbq *cmdiocbq, |
| 11953 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11954 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11955 | wait_queue_head_t *pdone_q; |
| 11956 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11957 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11958 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11959 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11960 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11961 | |
| 11962 | /* |
| 11963 | * A time out has occurred for the iocb. If a time out |
| 11964 | * completion handler has been supplied, call it. Otherwise, |
| 11965 | * just free the iocbq. |
| 11966 | */ |
| 11967 | |
| 11968 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11969 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11970 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11971 | if (cmdiocbq->iocb_cmpl) |
| 11972 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11973 | else |
| 11974 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11975 | return; |
| 11976 | } |
| 11977 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11978 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11979 | if (cmdiocbq->context2 && rspiocbq) |
| 11980 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11981 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11982 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11983 | /* Set the exchange busy flag for task management commands */ |
| 11984 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11985 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11986 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11987 | cur_iocbq); |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 11988 | if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY)) |
| 11989 | lpfc_cmd->flags |= LPFC_SBUF_XBUSY; |
| 11990 | else |
| 11991 | lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11992 | } |
| 11993 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11994 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11995 | if (pdone_q) |
| 11996 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11997 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11998 | return; |
| 11999 | } |
| 12000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12001 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 12002 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 12003 | * @phba: Pointer to HBA context object.. |
| 12004 | * @piocbq: Pointer to command iocb. |
| 12005 | * @flag: Flag to test. |
| 12006 | * |
| 12007 | * This routine grabs the hbalock and then test the iocb_flag to |
| 12008 | * see if the passed in flag is set. |
| 12009 | * Returns: |
| 12010 | * 1 if flag is set. |
| 12011 | * 0 if flag is not set. |
| 12012 | **/ |
| 12013 | static int |
| 12014 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 12015 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 12016 | { |
| 12017 | unsigned long iflags; |
| 12018 | int ret; |
| 12019 | |
| 12020 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12021 | ret = piocbq->iocb_flag & flag; |
| 12022 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12023 | return ret; |
| 12024 | |
| 12025 | } |
| 12026 | |
| 12027 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12028 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12029 | * @phba: Pointer to HBA context object.. |
| 12030 | * @pring: Pointer to sli ring. |
| 12031 | * @piocb: Pointer to command iocb. |
| 12032 | * @prspiocbq: Pointer to response iocb. |
| 12033 | * @timeout: Timeout in number of seconds. |
| 12034 | * |
| 12035 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12036 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 12037 | * to handle iocbs which time out. If the field is NULL, the |
| 12038 | * function shall free the iocbq structure. If more clean up is |
| 12039 | * needed, the caller is expected to provide a completion function |
| 12040 | * that will provide the needed clean up. If the iocb command is |
| 12041 | * not completed within timeout seconds, the function will either |
| 12042 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 12043 | * completion function set in the iocb_cmpl field and then return |
| 12044 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 12045 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12046 | * The function waits for the iocb completion using an |
| 12047 | * non-interruptible wait. |
| 12048 | * This function will sleep while waiting for iocb completion. |
| 12049 | * So, this function should not be called from any context which |
| 12050 | * does not allow sleeping. Due to the same reason, this function |
| 12051 | * cannot be called with interrupt disabled. |
| 12052 | * This function assumes that the iocb completions occur while |
| 12053 | * this function sleep. So, this function cannot be called from |
| 12054 | * the thread which process iocb completion for this ring. |
| 12055 | * This function clears the iocb_flag of the iocb object before |
| 12056 | * issuing the iocb and the iocb completion handler sets this |
| 12057 | * flag and wakes this thread when the iocb completes. |
| 12058 | * The contents of the response iocb will be copied to prspiocbq |
| 12059 | * by the completion handler when the command completes. |
| 12060 | * This function returns IOCB_SUCCESS when success. |
| 12061 | * This function is called with no lock held. |
| 12062 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12063 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12064 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12065 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12066 | struct lpfc_iocbq *piocb, |
| 12067 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12068 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12069 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 12070 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12071 | long timeleft, timeout_req = 0; |
| 12072 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12073 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12074 | struct lpfc_iocbq *iocb; |
| 12075 | int txq_cnt = 0; |
| 12076 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12077 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12078 | unsigned long iflags; |
| 12079 | bool iocb_completed = true; |
| 12080 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12081 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 12082 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 12083 | else |
| 12084 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12085 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12086 | * If the caller has provided a response iocbq buffer, then context2 |
| 12087 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12088 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12089 | if (prspiocbq) { |
| 12090 | if (piocb->context2) |
| 12091 | return IOCB_ERROR; |
| 12092 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12093 | } |
| 12094 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12095 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12096 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 12097 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12098 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12099 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12100 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12101 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12102 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12103 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 12104 | writel(creg_val, phba->HCregaddr); |
| 12105 | readl(phba->HCregaddr); /* flush */ |
| 12106 | } |
| 12107 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12108 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 12109 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12110 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 12111 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12112 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 12113 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12114 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12115 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12116 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12117 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12118 | /* |
| 12119 | * IOCB timed out. Inform the wake iocb wait |
| 12120 | * completion function and set local status |
| 12121 | */ |
| 12122 | |
| 12123 | iocb_completed = false; |
| 12124 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 12125 | } |
| 12126 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12127 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12128 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12129 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 12130 | /* Note: we are not indicating if the IOCB has a success |
| 12131 | * status or not - that's for the caller to check. |
| 12132 | * IOCB_SUCCESS means just that the command was sent and |
| 12133 | * completed. Not that it completed successfully. |
| 12134 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12135 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12136 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12137 | "0338 IOCB wait timeout error - no " |
| 12138 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12139 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12140 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12141 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12142 | "0330 IOCB wake NOT set, " |
| 12143 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12144 | timeout, (timeleft / jiffies)); |
| 12145 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12146 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12147 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12148 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 12149 | list_for_each_entry(iocb, &pring->txq, list) { |
| 12150 | txq_cnt++; |
| 12151 | } |
| 12152 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 12153 | txcmplq_cnt++; |
| 12154 | } |
| 12155 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12156 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 12157 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 12158 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12159 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12160 | } else { |
| 12161 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12162 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12163 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12164 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12165 | } |
| 12166 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12167 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12168 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12169 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12170 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 12171 | writel(creg_val, phba->HCregaddr); |
| 12172 | readl(phba->HCregaddr); /* flush */ |
| 12173 | } |
| 12174 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12175 | if (prspiocbq) |
| 12176 | piocb->context2 = NULL; |
| 12177 | |
| 12178 | piocb->context_un.wait_queue = NULL; |
| 12179 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12180 | return retval; |
| 12181 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12183 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12184 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12185 | * @phba: Pointer to HBA context object. |
| 12186 | * @pmboxq: Pointer to driver mailbox object. |
| 12187 | * @timeout: Timeout in number of seconds. |
| 12188 | * |
| 12189 | * This function issues the mailbox to firmware and waits for the |
| 12190 | * mailbox command to complete. If the mailbox command is not |
| 12191 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 12192 | * The function waits for the mailbox completion using an |
| 12193 | * interruptible wait. If the thread is woken up due to a |
| 12194 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 12195 | * should not free the mailbox resources, if this function returns |
| 12196 | * MBX_TIMEOUT. |
| 12197 | * This function will sleep while waiting for mailbox completion. |
| 12198 | * So, this function should not be called from any context which |
| 12199 | * does not allow sleeping. Due to the same reason, this function |
| 12200 | * cannot be called with interrupt disabled. |
| 12201 | * This function assumes that the mailbox completion occurs while |
| 12202 | * this function sleep. So, this function cannot be called from |
| 12203 | * the worker thread which processes mailbox completion. |
| 12204 | * This function is called in the context of HBA management |
| 12205 | * applications. |
| 12206 | * This function returns MBX_SUCCESS when successful. |
| 12207 | * This function is called with no lock held. |
| 12208 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12209 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12210 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12211 | uint32_t timeout) |
| 12212 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12213 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12214 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12215 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12216 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12217 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12218 | /* setup wake call as IOCB callback */ |
| 12219 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12220 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12221 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 12222 | init_completion(&mbox_done); |
| 12223 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12224 | /* now issue the command */ |
| 12225 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12226 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12227 | wait_for_completion_timeout(&mbox_done, |
| 12228 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12229 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12230 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12231 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12232 | /* |
| 12233 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 12234 | * else do not free the resources. |
| 12235 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12236 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12237 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12238 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12239 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12240 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12241 | } |
| 12242 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12243 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12244 | return retval; |
| 12245 | } |
| 12246 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12247 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12248 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12249 | * @phba: Pointer to HBA context. |
| 12250 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12251 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12252 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12253 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12254 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12255 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12256 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12257 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12258 | * as with offline or HBA function reset), this routine will wait for the |
| 12259 | * outstanding mailbox command to complete before invoking the mailbox |
| 12260 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12261 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12262 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12263 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12264 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12265 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12266 | unsigned long timeout; |
| 12267 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12268 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12269 | /* delay 100ms for port state */ |
| 12270 | msleep(100); |
| 12271 | lpfc_sli_mbox_sys_flush(phba); |
| 12272 | return; |
| 12273 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12274 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12275 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12276 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12277 | local_bh_disable(); |
| 12278 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12279 | spin_lock_irq(&phba->hbalock); |
| 12280 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12281 | |
| 12282 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12283 | /* Determine how long we might wait for the active mailbox |
| 12284 | * command to be gracefully completed by firmware. |
| 12285 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12286 | if (phba->sli.mbox_active) |
| 12287 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12288 | phba->sli.mbox_active) * |
| 12289 | 1000) + jiffies; |
| 12290 | spin_unlock_irq(&phba->hbalock); |
| 12291 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12292 | /* Enable softirqs again, done with phba->hbalock */ |
| 12293 | local_bh_enable(); |
| 12294 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12295 | while (phba->sli.mbox_active) { |
| 12296 | /* Check active mailbox complete status every 2ms */ |
| 12297 | msleep(2); |
| 12298 | if (time_after(jiffies, timeout)) |
| 12299 | /* Timeout, let the mailbox flush routine to |
| 12300 | * forcefully release active mailbox command |
| 12301 | */ |
| 12302 | break; |
| 12303 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12304 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12305 | spin_unlock_irq(&phba->hbalock); |
| 12306 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12307 | /* Enable softirqs again, done with phba->hbalock */ |
| 12308 | local_bh_enable(); |
| 12309 | } |
| 12310 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12311 | lpfc_sli_mbox_sys_flush(phba); |
| 12312 | } |
| 12313 | |
| 12314 | /** |
| 12315 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12316 | * @phba: Pointer to HBA context. |
| 12317 | * |
| 12318 | * This function is called to read the SLI3 device error attention registers |
| 12319 | * for possible error attention events. The caller must hold the hostlock |
| 12320 | * with spin_lock_irq(). |
| 12321 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12322 | * 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] | 12323 | * Register and returns 0 otherwise. |
| 12324 | **/ |
| 12325 | static int |
| 12326 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12327 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12328 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12329 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12330 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12331 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12332 | goto unplug_err; |
| 12333 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12334 | if (ha_copy & HA_ERATT) { |
| 12335 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12336 | if (lpfc_sli_read_hs(phba)) |
| 12337 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12338 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12339 | /* Check if there is a deferred error condition is active */ |
| 12340 | if ((HS_FFER1 & phba->work_hs) && |
| 12341 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12342 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12343 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12344 | /* Clear all interrupt enable conditions */ |
| 12345 | writel(0, phba->HCregaddr); |
| 12346 | readl(phba->HCregaddr); |
| 12347 | } |
| 12348 | |
| 12349 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12350 | phba->work_ha |= HA_ERATT; |
| 12351 | /* Indicate polling handles this ERATT */ |
| 12352 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12353 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12354 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12355 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12356 | |
| 12357 | unplug_err: |
| 12358 | /* Set the driver HS work bitmap */ |
| 12359 | phba->work_hs |= UNPLUG_ERR; |
| 12360 | /* Set the driver HA work bitmap */ |
| 12361 | phba->work_ha |= HA_ERATT; |
| 12362 | /* Indicate polling handles this ERATT */ |
| 12363 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12364 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12365 | } |
| 12366 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12367 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12368 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12369 | * @phba: Pointer to HBA context. |
| 12370 | * |
| 12371 | * This function is called to read the SLI4 device error attention registers |
| 12372 | * for possible error attention events. The caller must hold the hostlock |
| 12373 | * with spin_lock_irq(). |
| 12374 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12375 | * 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] | 12376 | * Register and returns 0 otherwise. |
| 12377 | **/ |
| 12378 | static int |
| 12379 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12380 | { |
| 12381 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12382 | uint32_t if_type, portsmphr; |
| 12383 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12384 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12385 | /* |
| 12386 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12387 | * registers for error attention. This can be changed later. |
| 12388 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12389 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12390 | switch (if_type) { |
| 12391 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12392 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12393 | &uerr_sta_lo) || |
| 12394 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12395 | &uerr_sta_hi)) { |
| 12396 | phba->work_hs |= UNPLUG_ERR; |
| 12397 | phba->work_ha |= HA_ERATT; |
| 12398 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12399 | return 1; |
| 12400 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12401 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12402 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 12403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12404 | "1423 HBA Unrecoverable error: " |
| 12405 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12406 | "ue_mask_lo_reg=0x%x, " |
| 12407 | "ue_mask_hi_reg=0x%x\n", |
| 12408 | uerr_sta_lo, uerr_sta_hi, |
| 12409 | phba->sli4_hba.ue_mask_lo, |
| 12410 | phba->sli4_hba.ue_mask_hi); |
| 12411 | phba->work_status[0] = uerr_sta_lo; |
| 12412 | phba->work_status[1] = uerr_sta_hi; |
| 12413 | phba->work_ha |= HA_ERATT; |
| 12414 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12415 | return 1; |
| 12416 | } |
| 12417 | break; |
| 12418 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12419 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12420 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12421 | &portstat_reg.word0) || |
| 12422 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12423 | &portsmphr)){ |
| 12424 | phba->work_hs |= UNPLUG_ERR; |
| 12425 | phba->work_ha |= HA_ERATT; |
| 12426 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12427 | return 1; |
| 12428 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12429 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12430 | phba->work_status[0] = |
| 12431 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12432 | phba->work_status[1] = |
| 12433 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 12434 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12435 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12436 | "port status reg 0x%x, " |
| 12437 | "port smphr reg 0x%x, " |
| 12438 | "error 1=0x%x, error 2=0x%x\n", |
| 12439 | portstat_reg.word0, |
| 12440 | portsmphr, |
| 12441 | phba->work_status[0], |
| 12442 | phba->work_status[1]); |
| 12443 | phba->work_ha |= HA_ERATT; |
| 12444 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12445 | return 1; |
| 12446 | } |
| 12447 | break; |
| 12448 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12449 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12450 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12451 | "2886 HBA Error Attention on unsupported " |
| 12452 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12453 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12454 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12455 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12456 | return 0; |
| 12457 | } |
| 12458 | |
| 12459 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12460 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12461 | * @phba: Pointer to HBA context. |
| 12462 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12463 | * 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] | 12464 | * error attention register bit for error attention events. |
| 12465 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12466 | * 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] | 12467 | * Register and returns 0 otherwise. |
| 12468 | **/ |
| 12469 | int |
| 12470 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12471 | { |
| 12472 | uint32_t ha_copy; |
| 12473 | |
| 12474 | /* If somebody is waiting to handle an eratt, don't process it |
| 12475 | * here. The brdkill function will do this. |
| 12476 | */ |
| 12477 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12478 | return 0; |
| 12479 | |
| 12480 | /* Check if interrupt handler handles this ERATT */ |
| 12481 | spin_lock_irq(&phba->hbalock); |
| 12482 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12483 | /* Interrupt handler has handled ERATT */ |
| 12484 | spin_unlock_irq(&phba->hbalock); |
| 12485 | return 0; |
| 12486 | } |
| 12487 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12488 | /* |
| 12489 | * If there is deferred error attention, do not check for error |
| 12490 | * attention |
| 12491 | */ |
| 12492 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12493 | spin_unlock_irq(&phba->hbalock); |
| 12494 | return 0; |
| 12495 | } |
| 12496 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12497 | /* If PCI channel is offline, don't process it */ |
| 12498 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12499 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12500 | return 0; |
| 12501 | } |
| 12502 | |
| 12503 | switch (phba->sli_rev) { |
| 12504 | case LPFC_SLI_REV2: |
| 12505 | case LPFC_SLI_REV3: |
| 12506 | /* Read chip Host Attention (HA) register */ |
| 12507 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12508 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12509 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12510 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12511 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12512 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12513 | default: |
| 12514 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12515 | "0299 Invalid SLI revision (%d)\n", |
| 12516 | phba->sli_rev); |
| 12517 | ha_copy = 0; |
| 12518 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12519 | } |
| 12520 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12521 | |
| 12522 | return ha_copy; |
| 12523 | } |
| 12524 | |
| 12525 | /** |
| 12526 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12527 | * @phba: Pointer to HBA context. |
| 12528 | * |
| 12529 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12530 | * that the interrupt should be handled. |
| 12531 | * |
| 12532 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12533 | * interrupt should be handled, otherwise -EIO. |
| 12534 | */ |
| 12535 | static inline int |
| 12536 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12537 | { |
| 12538 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12539 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12540 | return -EIO; |
| 12541 | |
| 12542 | /* Update device level interrupt statistics */ |
| 12543 | phba->sli.slistat.sli_intr++; |
| 12544 | |
| 12545 | /* Ignore all interrupts during initialization. */ |
| 12546 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12547 | return -EIO; |
| 12548 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12549 | return 0; |
| 12550 | } |
| 12551 | |
| 12552 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12553 | * 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] | 12554 | * @irq: Interrupt number. |
| 12555 | * @dev_id: The device context pointer. |
| 12556 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12557 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12558 | * service routine when device with SLI-3 interface spec is enabled with |
| 12559 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12560 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12561 | * interrupt mode, this function is called as part of the device-level |
| 12562 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12563 | * is undergoing initialization, the interrupt handler will not process |
| 12564 | * the interrupt. The link attention and ELS ring attention events are |
| 12565 | * handled by the worker thread. The interrupt handler signals the worker |
| 12566 | * thread and returns for these events. This function is called without |
| 12567 | * 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] | 12568 | * structures. |
| 12569 | * |
| 12570 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12571 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12572 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12573 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12574 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12575 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12576 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12577 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12578 | uint32_t work_ha_copy; |
| 12579 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12580 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12581 | uint32_t control; |
| 12582 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12583 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12584 | struct lpfc_vport *vport; |
| 12585 | struct lpfc_nodelist *ndlp; |
| 12586 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12587 | LPFC_MBOXQ_t *pmb; |
| 12588 | int rc; |
| 12589 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12590 | /* |
| 12591 | * Get the driver's phba structure from the dev_id and |
| 12592 | * assume the HBA is not interrupting. |
| 12593 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12594 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12595 | |
| 12596 | if (unlikely(!phba)) |
| 12597 | return IRQ_NONE; |
| 12598 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12599 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12600 | * Stuff needs to be attented to when this function is invoked as an |
| 12601 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12602 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12603 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12604 | /* Check device state for handling interrupt */ |
| 12605 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12606 | return IRQ_NONE; |
| 12607 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12608 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12609 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12610 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12611 | /* If somebody is waiting to handle an eratt don't process it |
| 12612 | * here. The brdkill function will do this. |
| 12613 | */ |
| 12614 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12615 | ha_copy &= ~HA_ERATT; |
| 12616 | /* Check the need for handling ERATT in interrupt handler */ |
| 12617 | if (ha_copy & HA_ERATT) { |
| 12618 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12619 | /* ERATT polling has handled ERATT */ |
| 12620 | ha_copy &= ~HA_ERATT; |
| 12621 | else |
| 12622 | /* Indicate interrupt handler handles ERATT */ |
| 12623 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12624 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12625 | |
| 12626 | /* |
| 12627 | * If there is deferred error attention, do not check for any |
| 12628 | * interrupt. |
| 12629 | */ |
| 12630 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12631 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12632 | return IRQ_NONE; |
| 12633 | } |
| 12634 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12635 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12636 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12637 | goto unplug_error; |
| 12638 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12639 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12640 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12641 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12642 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12643 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12644 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12645 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12646 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12647 | } else |
| 12648 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12649 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12650 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12651 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12652 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12653 | if (work_ha_copy & HA_LATT) { |
| 12654 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12655 | /* |
| 12656 | * Turn off Link Attention interrupts |
| 12657 | * until CLEAR_LA done |
| 12658 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12659 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12660 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12661 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12662 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12663 | control &= ~HC_LAINT_ENA; |
| 12664 | writel(control, phba->HCregaddr); |
| 12665 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12666 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12667 | } |
| 12668 | else |
| 12669 | work_ha_copy &= ~HA_LATT; |
| 12670 | } |
| 12671 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12672 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12673 | /* |
| 12674 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12675 | * the only slow ring. |
| 12676 | */ |
| 12677 | status = (work_ha_copy & |
| 12678 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12679 | status >>= (4*LPFC_ELS_RING); |
| 12680 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12681 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12682 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12683 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12684 | |
| 12685 | lpfc_debugfs_slow_ring_trc(phba, |
| 12686 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12687 | control, status, |
| 12688 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12689 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12690 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12691 | lpfc_debugfs_slow_ring_trc(phba, |
| 12692 | "ISR Disable ring:" |
| 12693 | "pwork:x%x hawork:x%x wait:x%x", |
| 12694 | phba->work_ha, work_ha_copy, |
| 12695 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12696 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12697 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12698 | control &= |
| 12699 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12700 | writel(control, phba->HCregaddr); |
| 12701 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12702 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12703 | else { |
| 12704 | lpfc_debugfs_slow_ring_trc(phba, |
| 12705 | "ISR slow ring: pwork:" |
| 12706 | "x%x hawork:x%x wait:x%x", |
| 12707 | phba->work_ha, work_ha_copy, |
| 12708 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12709 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12710 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12711 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12712 | } |
| 12713 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12714 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12715 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12716 | if (lpfc_sli_read_hs(phba)) |
| 12717 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12718 | /* |
| 12719 | * Check if there is a deferred error condition |
| 12720 | * is active |
| 12721 | */ |
| 12722 | if ((HS_FFER1 & phba->work_hs) && |
| 12723 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12724 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12725 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12726 | phba->hba_flag |= DEFER_ERATT; |
| 12727 | /* Clear all interrupt enable conditions */ |
| 12728 | writel(0, phba->HCregaddr); |
| 12729 | readl(phba->HCregaddr); |
| 12730 | } |
| 12731 | } |
| 12732 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12733 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12734 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12735 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12736 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12737 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12738 | |
| 12739 | /* First check out the status word */ |
| 12740 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12741 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12742 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12743 | /* |
| 12744 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12745 | * mbxStatus <status> |
| 12746 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12747 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12748 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12749 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12750 | "Interrupt mbxCommand x%x " |
| 12751 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12752 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12753 | pmbox->mbxCommand, |
| 12754 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12755 | /* clear mailbox attention bit */ |
| 12756 | work_ha_copy &= ~HA_MBATT; |
| 12757 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12758 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12759 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12760 | phba->last_completion_time = jiffies; |
| 12761 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12762 | if (pmb->mbox_cmpl) { |
| 12763 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12764 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12765 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12766 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12767 | lpfc_sli_pcimem_bcopy( |
| 12768 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12769 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12770 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12771 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12772 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12773 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12774 | |
| 12775 | lpfc_debugfs_disc_trc(vport, |
| 12776 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12777 | "MBOX dflt rpi: : " |
| 12778 | "status:x%x rpi:x%x", |
| 12779 | (uint32_t)pmbox->mbxStatus, |
| 12780 | pmbox->un.varWords[0], 0); |
| 12781 | |
| 12782 | if (!pmbox->mbxStatus) { |
| 12783 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12784 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12785 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12786 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12787 | |
| 12788 | /* Reg_LOGIN of dflt RPI was |
| 12789 | * successful. new lets get |
| 12790 | * rid of the RPI using the |
| 12791 | * same mbox buffer. |
| 12792 | */ |
| 12793 | lpfc_unreg_login(phba, |
| 12794 | vport->vpi, |
| 12795 | pmbox->un.varWords[0], |
| 12796 | pmb); |
| 12797 | pmb->mbox_cmpl = |
| 12798 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12799 | pmb->ctx_buf = mp; |
| 12800 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12801 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12802 | rc = lpfc_sli_issue_mbox(phba, |
| 12803 | pmb, |
| 12804 | MBX_NOWAIT); |
| 12805 | if (rc != MBX_BUSY) |
| 12806 | lpfc_printf_log(phba, |
| 12807 | KERN_ERR, |
| 12808 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12809 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12810 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12811 | if (rc != MBX_NOT_FINISHED) |
| 12812 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12813 | } |
| 12814 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12815 | spin_lock_irqsave( |
| 12816 | &phba->pport->work_port_lock, |
| 12817 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12818 | phba->pport->work_port_events &= |
| 12819 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12820 | spin_unlock_irqrestore( |
| 12821 | &phba->pport->work_port_lock, |
| 12822 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12823 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12824 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12825 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12826 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12827 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12828 | if ((work_ha_copy & HA_MBATT) && |
| 12829 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12830 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12831 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12832 | do { |
| 12833 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12834 | MBX_NOWAIT); |
| 12835 | } while (rc == MBX_NOT_FINISHED); |
| 12836 | if (rc != MBX_SUCCESS) |
| 12837 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12838 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12839 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12840 | } |
| 12841 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12842 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12843 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12844 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12845 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12846 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12847 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12848 | unplug_error: |
| 12849 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12850 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12851 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12852 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12853 | |
| 12854 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12855 | * 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] | 12856 | * @irq: Interrupt number. |
| 12857 | * @dev_id: The device context pointer. |
| 12858 | * |
| 12859 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12860 | * service routine when device with SLI-3 interface spec is enabled with |
| 12861 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12862 | * ring event in the HBA. However, when the device is enabled with either |
| 12863 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12864 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12865 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12866 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12867 | * the intrrupt context. This function is called without any lock held. |
| 12868 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12869 | * |
| 12870 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12871 | * returns IRQ_NONE. |
| 12872 | **/ |
| 12873 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12874 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12875 | { |
| 12876 | struct lpfc_hba *phba; |
| 12877 | uint32_t ha_copy; |
| 12878 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12879 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12880 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12881 | |
| 12882 | /* Get the driver's phba structure from the dev_id and |
| 12883 | * assume the HBA is not interrupting. |
| 12884 | */ |
| 12885 | phba = (struct lpfc_hba *) dev_id; |
| 12886 | |
| 12887 | if (unlikely(!phba)) |
| 12888 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12889 | |
| 12890 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12891 | * Stuff needs to be attented to when this function is invoked as an |
| 12892 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12893 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12894 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12895 | /* Check device state for handling interrupt */ |
| 12896 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12897 | return IRQ_NONE; |
| 12898 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12899 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12900 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12901 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12902 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12903 | /* |
| 12904 | * If there is deferred error attention, do not check for |
| 12905 | * any interrupt. |
| 12906 | */ |
| 12907 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12908 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12909 | return IRQ_NONE; |
| 12910 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12911 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12912 | phba->HAregaddr); |
| 12913 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12914 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12915 | } else |
| 12916 | ha_copy = phba->ha_copy; |
| 12917 | |
| 12918 | /* |
| 12919 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12920 | */ |
| 12921 | ha_copy &= ~(phba->work_ha_mask); |
| 12922 | |
| 12923 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12924 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12925 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12926 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12927 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12928 | |
| 12929 | if (phba->cfg_multi_ring_support == 2) { |
| 12930 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12931 | * Process all events on extra ring. Take the optimized path |
| 12932 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12933 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12934 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12935 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12936 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12937 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12938 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12939 | status); |
| 12940 | } |
| 12941 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12942 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12943 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12944 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12945 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12946 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12947 | * @irq: Interrupt number. |
| 12948 | * @dev_id: The device context pointer. |
| 12949 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12950 | * This function is the HBA device-level interrupt handler to device with |
| 12951 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12952 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12953 | * requires driver attention. This function invokes the slow-path interrupt |
| 12954 | * attention handling function and fast-path interrupt attention handling |
| 12955 | * function in turn to process the relevant HBA attention events. This |
| 12956 | * function is called without any lock held. It gets the hbalock to access |
| 12957 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12958 | * |
| 12959 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12960 | * returns IRQ_NONE. |
| 12961 | **/ |
| 12962 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12963 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12964 | { |
| 12965 | struct lpfc_hba *phba; |
| 12966 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12967 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12968 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12969 | |
| 12970 | /* |
| 12971 | * Get the driver's phba structure from the dev_id and |
| 12972 | * assume the HBA is not interrupting. |
| 12973 | */ |
| 12974 | phba = (struct lpfc_hba *) dev_id; |
| 12975 | |
| 12976 | if (unlikely(!phba)) |
| 12977 | return IRQ_NONE; |
| 12978 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12979 | /* Check device state for handling interrupt */ |
| 12980 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12981 | return IRQ_NONE; |
| 12982 | |
| 12983 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12984 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12985 | spin_unlock(&phba->hbalock); |
| 12986 | return IRQ_HANDLED; |
| 12987 | } |
| 12988 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12989 | if (unlikely(!phba->ha_copy)) { |
| 12990 | spin_unlock(&phba->hbalock); |
| 12991 | return IRQ_NONE; |
| 12992 | } else if (phba->ha_copy & HA_ERATT) { |
| 12993 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12994 | /* ERATT polling has handled ERATT */ |
| 12995 | phba->ha_copy &= ~HA_ERATT; |
| 12996 | else |
| 12997 | /* Indicate interrupt handler handles ERATT */ |
| 12998 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12999 | } |
| 13000 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13001 | /* |
| 13002 | * If there is deferred error attention, do not check for any interrupt. |
| 13003 | */ |
| 13004 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 13005 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13006 | return IRQ_NONE; |
| 13007 | } |
| 13008 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13009 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13010 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 13011 | spin_unlock(&phba->hbalock); |
| 13012 | return IRQ_HANDLED; |
| 13013 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13014 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 13015 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 13016 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13017 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13018 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13019 | readl(phba->HAregaddr); /* flush */ |
| 13020 | spin_unlock(&phba->hbalock); |
| 13021 | |
| 13022 | /* |
| 13023 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 13024 | */ |
| 13025 | |
| 13026 | /* status of events with mailbox and link attention */ |
| 13027 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 13028 | |
| 13029 | /* status of events with ELS ring */ |
| 13030 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 13031 | status2 >>= (4*LPFC_ELS_RING); |
| 13032 | |
| 13033 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13034 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13035 | else |
| 13036 | sp_irq_rc = IRQ_NONE; |
| 13037 | |
| 13038 | /* |
| 13039 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 13040 | */ |
| 13041 | |
| 13042 | /* status of events with FCP ring */ |
| 13043 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 13044 | status1 >>= (4*LPFC_FCP_RING); |
| 13045 | |
| 13046 | /* status of events with extra ring */ |
| 13047 | if (phba->cfg_multi_ring_support == 2) { |
| 13048 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 13049 | status2 >>= (4*LPFC_EXTRA_RING); |
| 13050 | } else |
| 13051 | status2 = 0; |
| 13052 | |
| 13053 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13054 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13055 | else |
| 13056 | fp_irq_rc = IRQ_NONE; |
| 13057 | |
| 13058 | /* Return device-level interrupt handling status */ |
| 13059 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13060 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13061 | |
| 13062 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13063 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 13064 | * @phba: pointer to lpfc hba data structure. |
| 13065 | * |
| 13066 | * This routine is invoked by the worker thread to process all the pending |
| 13067 | * SLI4 els abort xri events. |
| 13068 | **/ |
| 13069 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 13070 | { |
| 13071 | struct lpfc_cq_event *cq_event; |
| 13072 | |
| 13073 | /* First, declare the els xri abort event has been handled */ |
| 13074 | spin_lock_irq(&phba->hbalock); |
| 13075 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 13076 | spin_unlock_irq(&phba->hbalock); |
| 13077 | /* Now, handle all the els xri abort events */ |
| 13078 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 13079 | /* Get the first event from the head of the event queue */ |
| 13080 | spin_lock_irq(&phba->hbalock); |
| 13081 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 13082 | cq_event, struct lpfc_cq_event, list); |
| 13083 | spin_unlock_irq(&phba->hbalock); |
| 13084 | /* Notify aborted XRI for ELS work queue */ |
| 13085 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 13086 | /* Free the event processed back to the free pool */ |
| 13087 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 13088 | } |
| 13089 | } |
| 13090 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13091 | /** |
| 13092 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 13093 | * @phba: pointer to lpfc hba data structure |
| 13094 | * @pIocbIn: pointer to the rspiocbq |
| 13095 | * @pIocbOut: pointer to the cmdiocbq |
| 13096 | * @wcqe: pointer to the complete wcqe |
| 13097 | * |
| 13098 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 13099 | * by copying all the IOCB fields from command iocbq and transferring the |
| 13100 | * completion status information from the complete wcqe. |
| 13101 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13102 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13103 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 13104 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13105 | struct lpfc_iocbq *pIocbOut, |
| 13106 | struct lpfc_wcqe_complete *wcqe) |
| 13107 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13108 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13109 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13110 | uint32_t status, max_response; |
| 13111 | struct lpfc_dmabuf *dmabuf; |
| 13112 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13113 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 13114 | |
| 13115 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 13116 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13117 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13118 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 13119 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13120 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 13121 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 13122 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 13123 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 13124 | wcqe->total_data_placed; |
| 13125 | else |
| 13126 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13127 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13128 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13129 | switch (pIocbOut->iocb.ulpCommand) { |
| 13130 | case CMD_ELS_REQUEST64_CR: |
| 13131 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 13132 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 13133 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 13134 | max_response = bde.tus.f.bdeSize; |
| 13135 | break; |
| 13136 | case CMD_GEN_REQUEST64_CR: |
| 13137 | max_response = 0; |
| 13138 | if (!pIocbOut->context3) |
| 13139 | break; |
| 13140 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 13141 | sizeof(struct ulp_bde64); |
| 13142 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 13143 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 13144 | for (i = 0; i < numBdes; i++) { |
| 13145 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 13146 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 13147 | max_response += bde.tus.f.bdeSize; |
| 13148 | } |
| 13149 | break; |
| 13150 | default: |
| 13151 | max_response = wcqe->total_data_placed; |
| 13152 | break; |
| 13153 | } |
| 13154 | if (max_response < wcqe->total_data_placed) |
| 13155 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 13156 | else |
| 13157 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 13158 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13159 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13160 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13161 | /* Convert BG errors for completion status */ |
| 13162 | if (status == CQE_STATUS_DI_ERROR) { |
| 13163 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 13164 | |
| 13165 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 13166 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 13167 | else |
| 13168 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 13169 | |
| 13170 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 13171 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 13172 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13173 | BGS_GUARD_ERR_MASK; |
| 13174 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 13175 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13176 | BGS_APPTAG_ERR_MASK; |
| 13177 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 13178 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13179 | BGS_REFTAG_ERR_MASK; |
| 13180 | |
| 13181 | /* Check to see if there was any good data before the error */ |
| 13182 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 13183 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13184 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 13185 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 13186 | wcqe->total_data_placed; |
| 13187 | } |
| 13188 | |
| 13189 | /* |
| 13190 | * Set ALL the error bits to indicate we don't know what |
| 13191 | * type of error it is. |
| 13192 | */ |
| 13193 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 13194 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13195 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 13196 | BGS_GUARD_ERR_MASK); |
| 13197 | } |
| 13198 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13199 | /* Pick up HBA exchange busy condition */ |
| 13200 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 13201 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13202 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 13203 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13204 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13205 | } |
| 13206 | |
| 13207 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13208 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 13209 | * @phba: Pointer to HBA context object. |
| 13210 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13211 | * |
| 13212 | * This routine handles an ELS work-queue completion event and construct |
| 13213 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 13214 | * discovery engine to handle. |
| 13215 | * |
| 13216 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 13217 | **/ |
| 13218 | static struct lpfc_iocbq * |
| 13219 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 13220 | struct lpfc_iocbq *irspiocbq) |
| 13221 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13222 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13223 | struct lpfc_iocbq *cmdiocbq; |
| 13224 | struct lpfc_wcqe_complete *wcqe; |
| 13225 | unsigned long iflags; |
| 13226 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13227 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 13228 | if (unlikely(!pring)) |
| 13229 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13230 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13231 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13232 | pring->stats.iocb_event++; |
| 13233 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 13234 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13235 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13236 | if (unlikely(!cmdiocbq)) { |
| 13237 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13238 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13239 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 13240 | wcqe->word0, wcqe->total_data_placed, |
| 13241 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13242 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 13243 | return NULL; |
| 13244 | } |
| 13245 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13246 | spin_lock_irqsave(&pring->ring_lock, iflags); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13247 | /* Put the iocb back on the txcmplq */ |
| 13248 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13249 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13250 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13251 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13252 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13253 | |
| 13254 | return irspiocbq; |
| 13255 | } |
| 13256 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13257 | inline struct lpfc_cq_event * |
| 13258 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13259 | { |
| 13260 | struct lpfc_cq_event *cq_event; |
| 13261 | |
| 13262 | /* Allocate a new internal CQ_EVENT entry */ |
| 13263 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13264 | if (!cq_event) { |
| 13265 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13266 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13267 | return NULL; |
| 13268 | } |
| 13269 | |
| 13270 | /* Move the CQE into the event */ |
| 13271 | memcpy(&cq_event->cqe, entry, size); |
| 13272 | return cq_event; |
| 13273 | } |
| 13274 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13275 | /** |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13276 | * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13277 | * @phba: Pointer to HBA context object. |
| 13278 | * @cqe: Pointer to mailbox completion queue entry. |
| 13279 | * |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13280 | * This routine process a mailbox completion queue entry with asynchronous |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13281 | * event. |
| 13282 | * |
| 13283 | * Return: true if work posted to worker thread, otherwise false. |
| 13284 | **/ |
| 13285 | static bool |
| 13286 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13287 | { |
| 13288 | struct lpfc_cq_event *cq_event; |
| 13289 | unsigned long iflags; |
| 13290 | |
| 13291 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13292 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13293 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13294 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13295 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13296 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13297 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13298 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13299 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13300 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 13301 | /* Set the async event flag */ |
| 13302 | phba->hba_flag |= ASYNC_EVENT; |
| 13303 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13304 | |
| 13305 | return true; |
| 13306 | } |
| 13307 | |
| 13308 | /** |
| 13309 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13310 | * @phba: Pointer to HBA context object. |
| 13311 | * @cqe: Pointer to mailbox completion queue entry. |
| 13312 | * |
| 13313 | * This routine process a mailbox completion queue entry with mailbox |
| 13314 | * completion event. |
| 13315 | * |
| 13316 | * Return: true if work posted to worker thread, otherwise false. |
| 13317 | **/ |
| 13318 | static bool |
| 13319 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13320 | { |
| 13321 | uint32_t mcqe_status; |
| 13322 | MAILBOX_t *mbox, *pmbox; |
| 13323 | struct lpfc_mqe *mqe; |
| 13324 | struct lpfc_vport *vport; |
| 13325 | struct lpfc_nodelist *ndlp; |
| 13326 | struct lpfc_dmabuf *mp; |
| 13327 | unsigned long iflags; |
| 13328 | LPFC_MBOXQ_t *pmb; |
| 13329 | bool workposted = false; |
| 13330 | int rc; |
| 13331 | |
| 13332 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13333 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13334 | goto out_no_mqe_complete; |
| 13335 | |
| 13336 | /* Get the reference to the active mbox command */ |
| 13337 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13338 | pmb = phba->sli.mbox_active; |
| 13339 | if (unlikely(!pmb)) { |
| 13340 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13341 | "1832 No pending MBOX command to handle\n"); |
| 13342 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13343 | goto out_no_mqe_complete; |
| 13344 | } |
| 13345 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13346 | mqe = &pmb->u.mqe; |
| 13347 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13348 | mbox = phba->mbox; |
| 13349 | vport = pmb->vport; |
| 13350 | |
| 13351 | /* Reset heartbeat timer */ |
| 13352 | phba->last_completion_time = jiffies; |
| 13353 | del_timer(&phba->sli.mbox_tmo); |
| 13354 | |
| 13355 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13356 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13357 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13358 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13359 | /* |
| 13360 | * For mcqe errors, conditionally move a modified error code to |
| 13361 | * the mbox so that the error will not be missed. |
| 13362 | */ |
| 13363 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13364 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13365 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13366 | bf_set(lpfc_mqe_status, mqe, |
| 13367 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13368 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13369 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13370 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13371 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13372 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13373 | mcqe_status, |
| 13374 | pmbox->un.varWords[0], 0); |
| 13375 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13376 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13377 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13378 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 13379 | * RID of the PPI using the same mbox buffer. |
| 13380 | */ |
| 13381 | lpfc_unreg_login(phba, vport->vpi, |
| 13382 | pmbox->un.varWords[0], pmb); |
| 13383 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13384 | pmb->ctx_buf = mp; |
| 13385 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13386 | pmb->vport = vport; |
| 13387 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13388 | if (rc != MBX_BUSY) |
| 13389 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 13390 | LOG_SLI, "0385 rc should " |
| 13391 | "have been MBX_BUSY\n"); |
| 13392 | if (rc != MBX_NOT_FINISHED) |
| 13393 | goto send_current_mbox; |
| 13394 | } |
| 13395 | } |
| 13396 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13397 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13398 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13399 | |
| 13400 | /* There is mailbox completion work to do */ |
| 13401 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13402 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13403 | phba->work_ha |= HA_MBATT; |
| 13404 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13405 | workposted = true; |
| 13406 | |
| 13407 | send_current_mbox: |
| 13408 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13409 | /* Release the mailbox command posting token */ |
| 13410 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13411 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13412 | phba->sli.mbox_active = NULL; |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13413 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13414 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13415 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13416 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13417 | lpfc_worker_wake_up(phba); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13418 | return workposted; |
| 13419 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13420 | out_no_mqe_complete: |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13421 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13422 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13423 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13424 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13425 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13426 | } |
| 13427 | |
| 13428 | /** |
| 13429 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13430 | * @phba: Pointer to HBA context object. |
| 13431 | * @cqe: Pointer to mailbox completion queue entry. |
| 13432 | * |
| 13433 | * This routine process a mailbox completion queue entry, it invokes the |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13434 | * proper mailbox complete handling or asynchronous event handling routine |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13435 | * according to the MCQE's async bit. |
| 13436 | * |
| 13437 | * Return: true if work posted to worker thread, otherwise false. |
| 13438 | **/ |
| 13439 | static bool |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13440 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13441 | struct lpfc_cqe *cqe) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13442 | { |
| 13443 | struct lpfc_mcqe mcqe; |
| 13444 | bool workposted; |
| 13445 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13446 | cq->CQ_mbox++; |
| 13447 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13448 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13449 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13450 | |
| 13451 | /* Invoke the proper event handling routine */ |
| 13452 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13453 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13454 | else |
| 13455 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13456 | return workposted; |
| 13457 | } |
| 13458 | |
| 13459 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13460 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13461 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13462 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13463 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13464 | * |
| 13465 | * This routine handles an ELS work-queue completion event. |
| 13466 | * |
| 13467 | * Return: true if work posted to worker thread, otherwise false. |
| 13468 | **/ |
| 13469 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13470 | 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] | 13471 | struct lpfc_wcqe_complete *wcqe) |
| 13472 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13473 | struct lpfc_iocbq *irspiocbq; |
| 13474 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13475 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13476 | int txq_cnt = 0; |
| 13477 | int txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13478 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13479 | /* Check for response status */ |
| 13480 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13481 | /* Log the error status */ |
| 13482 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13483 | "0357 ELS CQE error: status=x%x: " |
| 13484 | "CQE: %08x %08x %08x %08x\n", |
| 13485 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13486 | wcqe->word0, wcqe->total_data_placed, |
| 13487 | wcqe->parameter, wcqe->word3); |
| 13488 | } |
| 13489 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13490 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13491 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13492 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13493 | if (!list_empty(&pring->txq)) |
| 13494 | txq_cnt++; |
| 13495 | if (!list_empty(&pring->txcmplq)) |
| 13496 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13497 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13498 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
James Smart | ff349bc | 2019-09-21 20:59:05 -0700 | [diff] [blame] | 13499 | "els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13500 | txq_cnt, phba->iocb_cnt, |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13501 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13502 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13503 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13504 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13505 | /* Save off the slow-path queue event for work thread to process */ |
| 13506 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13507 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13508 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13509 | &phba->sli4_hba.sp_queue_event); |
| 13510 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13511 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13512 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13513 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13514 | } |
| 13515 | |
| 13516 | /** |
| 13517 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13518 | * @phba: Pointer to HBA context object. |
| 13519 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13520 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13521 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13522 | * proper WQ release routine to the slow-path WQ. |
| 13523 | **/ |
| 13524 | static void |
| 13525 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13526 | struct lpfc_wcqe_release *wcqe) |
| 13527 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13528 | /* sanity check on queue memory */ |
| 13529 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13530 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13531 | /* Check for the slow-path ELS work queue */ |
| 13532 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13533 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13534 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13535 | else |
| 13536 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13537 | "2579 Slow-path wqe consume event carries " |
| 13538 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13539 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13540 | phba->sli4_hba.els_wq->queue_id); |
| 13541 | } |
| 13542 | |
| 13543 | /** |
| 13544 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13545 | * @phba: Pointer to HBA context object. |
| 13546 | * @cq: Pointer to a WQ completion queue. |
| 13547 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13548 | * |
| 13549 | * This routine handles an XRI abort event. |
| 13550 | * |
| 13551 | * Return: true if work posted to worker thread, otherwise false. |
| 13552 | **/ |
| 13553 | static bool |
| 13554 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13555 | struct lpfc_queue *cq, |
| 13556 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13557 | { |
| 13558 | bool workposted = false; |
| 13559 | struct lpfc_cq_event *cq_event; |
| 13560 | unsigned long iflags; |
| 13561 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13562 | switch (cq->subtype) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13563 | case LPFC_IO: |
| 13564 | lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq); |
| 13565 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13566 | /* Notify aborted XRI for NVME work queue */ |
| 13567 | if (phba->nvmet_support) |
| 13568 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13569 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13570 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13571 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13572 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13573 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13574 | cq_event = lpfc_cq_event_setup( |
| 13575 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13576 | if (!cq_event) |
| 13577 | return false; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13578 | cq_event->hdwq = cq->hdwq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13579 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13580 | list_add_tail(&cq_event->list, |
| 13581 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13582 | /* Set the els xri abort event flag */ |
| 13583 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13584 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13585 | workposted = true; |
| 13586 | break; |
| 13587 | default: |
| 13588 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13589 | "0603 Invalid CQ subtype %d: " |
| 13590 | "%08x %08x %08x %08x\n", |
| 13591 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13592 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13593 | workposted = false; |
| 13594 | break; |
| 13595 | } |
| 13596 | return workposted; |
| 13597 | } |
| 13598 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13599 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13600 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13601 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13602 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13603 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13604 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13605 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13606 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13607 | * |
| 13608 | * Return: true if work posted to worker thread, otherwise false. |
| 13609 | **/ |
| 13610 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13611 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13612 | { |
| 13613 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13614 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13615 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13616 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13617 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13618 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13619 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13620 | unsigned long iflags; |
| 13621 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13622 | /* sanity check on queue memory */ |
| 13623 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13624 | return workposted; |
| 13625 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13626 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13627 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13628 | else |
| 13629 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13630 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13631 | goto out; |
| 13632 | |
| 13633 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13634 | switch (status) { |
| 13635 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13636 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13637 | "2537 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 13638 | /* fall through */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13639 | case FC_STATUS_RQ_SUCCESS: |
| 13640 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13641 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13642 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13643 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13644 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13645 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13646 | goto out; |
| 13647 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13648 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13649 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13650 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13651 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13652 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13653 | |
| 13654 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13655 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13656 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13657 | /* Handle MDS Loopback frames */ |
| 13658 | lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf); |
| 13659 | break; |
| 13660 | } |
| 13661 | |
| 13662 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13663 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13664 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13665 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13666 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13667 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13668 | workposted = true; |
| 13669 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13670 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13671 | if (phba->nvmet_support) { |
| 13672 | tgtp = phba->targetport->private; |
| 13673 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13674 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13675 | "%d: %x %x %x\n", |
| 13676 | status, hrq->RQ_buf_posted, |
| 13677 | hrq->RQ_no_posted_buf, |
| 13678 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13679 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13680 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13681 | } |
| 13682 | /* fallthrough */ |
| 13683 | |
| 13684 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13685 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13686 | /* Post more buffers if possible */ |
| 13687 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13688 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13689 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13690 | workposted = true; |
| 13691 | break; |
| 13692 | } |
| 13693 | out: |
| 13694 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13695 | } |
| 13696 | |
| 13697 | /** |
| 13698 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13699 | * @phba: Pointer to HBA context object. |
| 13700 | * @cq: Pointer to the completion queue. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13701 | * @cqe: Pointer to a completion queue entry. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13702 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13703 | * 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] | 13704 | * entry. |
| 13705 | * |
| 13706 | * Return: true if work posted to worker thread, otherwise false. |
| 13707 | **/ |
| 13708 | static bool |
| 13709 | 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] | 13710 | struct lpfc_cqe *cqe) |
| 13711 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13712 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13713 | bool workposted = false; |
| 13714 | |
| 13715 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13716 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13717 | |
| 13718 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13719 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13720 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13721 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13722 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13723 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13724 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13725 | break; |
| 13726 | case CQE_CODE_RELEASE_WQE: |
| 13727 | /* Process the WQ release event */ |
| 13728 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13729 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13730 | break; |
| 13731 | case CQE_CODE_XRI_ABORTED: |
| 13732 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13733 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13734 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13735 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13736 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13737 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13738 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13739 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13740 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13741 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13742 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13743 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13744 | default: |
| 13745 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13746 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13747 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13748 | break; |
| 13749 | } |
| 13750 | return workposted; |
| 13751 | } |
| 13752 | |
| 13753 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13754 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13755 | * @phba: Pointer to HBA context object. |
| 13756 | * @eqe: Pointer to fast-path event queue entry. |
| 13757 | * |
| 13758 | * This routine process a event queue entry from the slow-path event queue. |
| 13759 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13760 | * completion event on a completion queue, if not, an error shall be logged |
| 13761 | * and just return. Otherwise, it will get to the corresponding completion |
| 13762 | * queue and process all the entries on that completion queue, rearm the |
| 13763 | * completion queue, and then return. |
| 13764 | * |
| 13765 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13766 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13767 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13768 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13769 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13770 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13771 | uint16_t cqid; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 13772 | int ret = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13773 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13774 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13775 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13776 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13777 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13778 | if (childq->queue_id == cqid) { |
| 13779 | cq = childq; |
| 13780 | break; |
| 13781 | } |
| 13782 | } |
| 13783 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13784 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13785 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13786 | "0365 Slow-path CQ identifier " |
| 13787 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13788 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13789 | } |
| 13790 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13791 | /* Save EQ associated with this CQ */ |
| 13792 | cq->assoc_qp = speq; |
| 13793 | |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 13794 | if (is_kdump_kernel()) |
| 13795 | ret = queue_work(phba->wq, &cq->spwork); |
| 13796 | else |
| 13797 | ret = queue_work_on(cq->chann, phba->wq, &cq->spwork); |
| 13798 | |
| 13799 | if (!ret) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13800 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 13801 | "0390 Cannot schedule queue work " |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13802 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 13803 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13804 | } |
| 13805 | |
| 13806 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13807 | * __lpfc_sli4_process_cq - Process elements of a CQ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13808 | * @phba: Pointer to HBA context object. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13809 | * @cq: Pointer to CQ to be processed |
| 13810 | * @handler: Routine to process each cqe |
| 13811 | * @delay: Pointer to usdelay to set in case of rescheduling of the handler |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 13812 | * @poll_mode: Polling mode we were called from |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13813 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13814 | * This routine processes completion queue entries in a CQ. While a valid |
| 13815 | * queue element is found, the handler is called. During processing checks |
| 13816 | * are made for periodic doorbell writes to let the hardware know of |
| 13817 | * element consumption. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13818 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13819 | * If the max limit on cqes to process is hit, or there are no more valid |
| 13820 | * entries, the loop stops. If we processed a sufficient number of elements, |
| 13821 | * meaning there is sufficient load, rather than rearming and generating |
| 13822 | * another interrupt, a cq rescheduling delay will be set. A delay of 0 |
| 13823 | * indicates no rescheduling. |
| 13824 | * |
| 13825 | * Returns True if work scheduled, False otherwise. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13826 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13827 | static bool |
| 13828 | __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13829 | bool (*handler)(struct lpfc_hba *, struct lpfc_queue *, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 13830 | struct lpfc_cqe *), unsigned long *delay, |
| 13831 | enum lpfc_poll_mode poll_mode) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13832 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13833 | struct lpfc_cqe *cqe; |
| 13834 | bool workposted = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13835 | int count = 0, consumed = 0; |
| 13836 | bool arm = true; |
| 13837 | |
| 13838 | /* default - no reschedule */ |
| 13839 | *delay = 0; |
| 13840 | |
| 13841 | if (cmpxchg(&cq->queue_claimed, 0, 1) != 0) |
| 13842 | goto rearm_and_exit; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13843 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13844 | /* Process all the entries to the CQ */ |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13845 | cq->q_flag = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13846 | cqe = lpfc_sli4_cq_get(cq); |
| 13847 | while (cqe) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13848 | workposted |= handler(phba, cq, cqe); |
| 13849 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 13850 | |
| 13851 | consumed++; |
| 13852 | if (!(++count % cq->max_proc_limit)) |
| 13853 | break; |
| 13854 | |
| 13855 | if (!(count % cq->notify_interval)) { |
| 13856 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13857 | LPFC_QUEUE_NOARM); |
| 13858 | consumed = 0; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 13859 | cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13860 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13861 | |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13862 | if (count == LPFC_NVMET_CQ_NOTIFY) |
| 13863 | cq->q_flag |= HBA_NVMET_CQ_NOTIFY; |
| 13864 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13865 | cqe = lpfc_sli4_cq_get(cq); |
| 13866 | } |
| 13867 | if (count >= phba->cfg_cq_poll_threshold) { |
| 13868 | *delay = 1; |
| 13869 | arm = false; |
| 13870 | } |
| 13871 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 13872 | /* Note: complete the irq_poll softirq before rearming CQ */ |
| 13873 | if (poll_mode == LPFC_IRQ_POLL) |
| 13874 | irq_poll_complete(&cq->iop); |
| 13875 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13876 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13877 | if (count > cq->CQ_max_cqe) |
| 13878 | cq->CQ_max_cqe = count; |
| 13879 | |
| 13880 | cq->assoc_qp->EQ_cqe_cnt += count; |
| 13881 | |
| 13882 | /* Catch the no cq entry condition */ |
| 13883 | if (unlikely(count == 0)) |
| 13884 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13885 | "0369 No entry from completion queue " |
| 13886 | "qid=%d\n", cq->queue_id); |
| 13887 | |
Dick Kennedy | 164ba8d | 2020-05-01 14:43:03 -0700 | [diff] [blame] | 13888 | xchg(&cq->queue_claimed, 0); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13889 | |
| 13890 | rearm_and_exit: |
| 13891 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13892 | arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM); |
| 13893 | |
| 13894 | return workposted; |
| 13895 | } |
| 13896 | |
| 13897 | /** |
| 13898 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13899 | * @cq: pointer to CQ to process |
| 13900 | * |
| 13901 | * This routine calls the cq processing routine with a handler specific |
| 13902 | * to the type of queue bound to it. |
| 13903 | * |
| 13904 | * The CQ routine returns two values: the first is the calling status, |
| 13905 | * which indicates whether work was queued to the background discovery |
| 13906 | * thread. If true, the routine should wakeup the discovery thread; |
| 13907 | * the second is the delay parameter. If non-zero, rather than rearming |
| 13908 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 13909 | * that it is processed in a subsequent polling action. The value of |
| 13910 | * the delay indicates when to reschedule it. |
| 13911 | **/ |
| 13912 | static void |
| 13913 | __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq) |
| 13914 | { |
| 13915 | struct lpfc_hba *phba = cq->phba; |
| 13916 | unsigned long delay; |
| 13917 | bool workposted = false; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 13918 | int ret = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13919 | |
| 13920 | /* Process and rearm the CQ */ |
| 13921 | switch (cq->type) { |
| 13922 | case LPFC_MCQ: |
| 13923 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13924 | lpfc_sli4_sp_handle_mcqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 13925 | &delay, LPFC_QUEUE_WORK); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13926 | break; |
| 13927 | case LPFC_WCQ: |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13928 | if (cq->subtype == LPFC_IO) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13929 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13930 | lpfc_sli4_fp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 13931 | &delay, LPFC_QUEUE_WORK); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13932 | else |
| 13933 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13934 | lpfc_sli4_sp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 13935 | &delay, LPFC_QUEUE_WORK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13936 | break; |
| 13937 | default: |
| 13938 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13939 | "0370 Invalid completion queue type (%d)\n", |
| 13940 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13941 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13942 | } |
| 13943 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13944 | if (delay) { |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 13945 | if (is_kdump_kernel()) |
| 13946 | ret = queue_delayed_work(phba->wq, &cq->sched_spwork, |
| 13947 | delay); |
| 13948 | else |
| 13949 | ret = queue_delayed_work_on(cq->chann, phba->wq, |
| 13950 | &cq->sched_spwork, delay); |
| 13951 | if (!ret) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13952 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 13953 | "0394 Cannot schedule queue work " |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13954 | "for cqid=%d on CPU %d\n", |
| 13955 | cq->queue_id, cq->chann); |
| 13956 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13957 | |
| 13958 | /* wake up worker thread if there are works to be done */ |
| 13959 | if (workposted) |
| 13960 | lpfc_worker_wake_up(phba); |
| 13961 | } |
| 13962 | |
| 13963 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13964 | * lpfc_sli4_sp_process_cq - slow-path work handler when started by |
| 13965 | * interrupt |
| 13966 | * @work: pointer to work element |
| 13967 | * |
| 13968 | * translates from the work handler and calls the slow-path handler. |
| 13969 | **/ |
| 13970 | static void |
| 13971 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13972 | { |
| 13973 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork); |
| 13974 | |
| 13975 | __lpfc_sli4_sp_process_cq(cq); |
| 13976 | } |
| 13977 | |
| 13978 | /** |
| 13979 | * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer |
| 13980 | * @work: pointer to work element |
| 13981 | * |
| 13982 | * translates from the work handler and calls the slow-path handler. |
| 13983 | **/ |
| 13984 | static void |
| 13985 | lpfc_sli4_dly_sp_process_cq(struct work_struct *work) |
| 13986 | { |
| 13987 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 13988 | struct lpfc_queue, sched_spwork); |
| 13989 | |
| 13990 | __lpfc_sli4_sp_process_cq(cq); |
| 13991 | } |
| 13992 | |
| 13993 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13994 | * 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] | 13995 | * @phba: Pointer to HBA context object. |
| 13996 | * @cq: Pointer to associated CQ |
| 13997 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13998 | * |
| 13999 | * This routine process a fast-path work queue completion entry from fast-path |
| 14000 | * event queue for FCP command response completion. |
| 14001 | **/ |
| 14002 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14003 | 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] | 14004 | struct lpfc_wcqe_complete *wcqe) |
| 14005 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14006 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14007 | struct lpfc_iocbq *cmdiocbq; |
| 14008 | struct lpfc_iocbq irspiocbq; |
| 14009 | unsigned long iflags; |
| 14010 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14011 | /* Check for response status */ |
| 14012 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 14013 | /* If resource errors reported from HBA, reduce queue |
| 14014 | * depth of the SCSI device. |
| 14015 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 14016 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 14017 | IOSTAT_LOCAL_REJECT)) && |
| 14018 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 14019 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14020 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 14021 | |
Dick Kennedy | 28ed737 | 2020-06-30 14:49:56 -0700 | [diff] [blame] | 14022 | /* Log the cmpl status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 14023 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
Dick Kennedy | 28ed737 | 2020-06-30 14:49:56 -0700 | [diff] [blame] | 14024 | "0373 FCP CQE cmpl: status=x%x: " |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 14025 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14026 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 14027 | wcqe->word0, wcqe->total_data_placed, |
| 14028 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14029 | } |
| 14030 | |
| 14031 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 14032 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 14033 | pring->stats.iocb_event++; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 14034 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14035 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 14036 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14037 | if (unlikely(!cmdiocbq)) { |
| 14038 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14039 | "0374 FCP complete with no corresponding " |
| 14040 | "cmdiocb: iotag (%d)\n", |
| 14041 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 14042 | return; |
| 14043 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 14044 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 14045 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 14046 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14047 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 14048 | if (cmdiocbq->wqe_cmpl) { |
| 14049 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 14050 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14051 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 14052 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14053 | } |
| 14054 | |
| 14055 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 14056 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 14057 | return; |
| 14058 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14059 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14060 | "0375 FCP cmdiocb not callback function " |
| 14061 | "iotag: (%d)\n", |
| 14062 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 14063 | return; |
| 14064 | } |
| 14065 | |
| 14066 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14067 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14068 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 14069 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 14070 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14071 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 14072 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14073 | } |
| 14074 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14075 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 14076 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 14077 | } |
| 14078 | |
| 14079 | /** |
| 14080 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 14081 | * @phba: Pointer to HBA context object. |
| 14082 | * @cq: Pointer to completion queue. |
| 14083 | * @wcqe: Pointer to work-queue completion queue entry. |
| 14084 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 14085 | * 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] | 14086 | * proper WQ release routine to the slow-path WQ. |
| 14087 | **/ |
| 14088 | static void |
| 14089 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14090 | struct lpfc_wcqe_release *wcqe) |
| 14091 | { |
| 14092 | struct lpfc_queue *childwq; |
| 14093 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14094 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14095 | |
| 14096 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14097 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14098 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14099 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14100 | lpfc_sli4_wq_release(childwq, |
| 14101 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14102 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 14103 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14104 | wqid_matched = true; |
| 14105 | break; |
| 14106 | } |
| 14107 | } |
| 14108 | /* Report warning log message if no match found */ |
| 14109 | if (wqid_matched != true) |
| 14110 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14111 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14112 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14113 | } |
| 14114 | |
| 14115 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14116 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 14117 | * @phba: Pointer to HBA context object. |
| 14118 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 14119 | * |
| 14120 | * This routine process a receive-queue completion queue entry. |
| 14121 | * |
| 14122 | * Return: true if work posted to worker thread, otherwise false. |
| 14123 | **/ |
| 14124 | static bool |
| 14125 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14126 | struct lpfc_rcqe *rcqe) |
| 14127 | { |
| 14128 | bool workposted = false; |
| 14129 | struct lpfc_queue *hrq; |
| 14130 | struct lpfc_queue *drq; |
| 14131 | struct rqb_dmabuf *dma_buf; |
| 14132 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14133 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14134 | uint32_t status, rq_id; |
| 14135 | unsigned long iflags; |
| 14136 | uint32_t fctl, idx; |
| 14137 | |
| 14138 | if ((phba->nvmet_support == 0) || |
| 14139 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 14140 | return workposted; |
| 14141 | |
| 14142 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14143 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 14144 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 14145 | |
| 14146 | /* sanity check on queue memory */ |
| 14147 | if (unlikely(!hrq) || unlikely(!drq)) |
| 14148 | return workposted; |
| 14149 | |
| 14150 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 14151 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 14152 | else |
| 14153 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 14154 | |
| 14155 | if ((phba->nvmet_support == 0) || |
| 14156 | (rq_id != hrq->queue_id)) |
| 14157 | return workposted; |
| 14158 | |
| 14159 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 14160 | switch (status) { |
| 14161 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 14162 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14163 | "6126 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14164 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14165 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14166 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 14167 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14168 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 14169 | if (!dma_buf) { |
| 14170 | hrq->RQ_no_buf_found++; |
| 14171 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14172 | goto out; |
| 14173 | } |
| 14174 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14175 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14176 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14177 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 14178 | |
| 14179 | /* Just some basic sanity checks on FCP Command frame */ |
| 14180 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 14181 | fc_hdr->fh_f_ctl[1] << 8 | |
| 14182 | fc_hdr->fh_f_ctl[2]); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14183 | if (((fctl & |
| 14184 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 14185 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 14186 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 14187 | goto drop; |
| 14188 | |
| 14189 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14190 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 14191 | lpfc_nvmet_unsol_fcp_event( |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14192 | phba, idx, dma_buf, cq->isr_timestamp, |
| 14193 | cq->q_flag & HBA_NVMET_CQ_NOTIFY); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14194 | return false; |
| 14195 | } |
| 14196 | drop: |
James Smart | 22b738a | 2019-03-12 16:30:11 -0700 | [diff] [blame] | 14197 | lpfc_rq_buf_free(phba, &dma_buf->hbuf); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14198 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14199 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14200 | if (phba->nvmet_support) { |
| 14201 | tgtp = phba->targetport->private; |
| 14202 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 14203 | "6401 RQE Error x%x, posted %d err_cnt " |
| 14204 | "%d: %x %x %x\n", |
| 14205 | status, hrq->RQ_buf_posted, |
| 14206 | hrq->RQ_no_posted_buf, |
| 14207 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 14208 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 14209 | atomic_read(&tgtp->xmt_fcp_release)); |
| 14210 | } |
| 14211 | /* fallthrough */ |
| 14212 | |
| 14213 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14214 | hrq->RQ_no_posted_buf++; |
| 14215 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14216 | break; |
| 14217 | } |
| 14218 | out: |
| 14219 | return workposted; |
| 14220 | } |
| 14221 | |
| 14222 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14223 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14224 | * @phba: adapter with cq |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14225 | * @cq: Pointer to the completion queue. |
| 14226 | * @eqe: Pointer to fast-path completion queue entry. |
| 14227 | * |
| 14228 | * This routine process a fast-path work queue completion entry from fast-path |
| 14229 | * event queue for FCP command response completion. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14230 | * |
| 14231 | * Return: true if work posted to worker thread, otherwise false. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14232 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14233 | static bool |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14234 | 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] | 14235 | struct lpfc_cqe *cqe) |
| 14236 | { |
| 14237 | struct lpfc_wcqe_release wcqe; |
| 14238 | bool workposted = false; |
| 14239 | |
| 14240 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14241 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14242 | |
| 14243 | /* Check and process for different type of WCQE and dispatch */ |
| 14244 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 14245 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14246 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14247 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14248 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 14249 | phba->last_completion_time = jiffies; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14250 | if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14251 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14252 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14253 | break; |
| 14254 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14255 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14256 | /* Process the WQ release event */ |
| 14257 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 14258 | (struct lpfc_wcqe_release *)&wcqe); |
| 14259 | break; |
| 14260 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14261 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14262 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14263 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14264 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 14265 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 14266 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14267 | case CQE_CODE_RECEIVE_V1: |
| 14268 | case CQE_CODE_RECEIVE: |
| 14269 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14270 | if (cq->subtype == LPFC_NVMET) { |
| 14271 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 14272 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 14273 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14274 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14275 | default: |
| 14276 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14277 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14278 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 14279 | break; |
| 14280 | } |
| 14281 | return workposted; |
| 14282 | } |
| 14283 | |
| 14284 | /** |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 14285 | * lpfc_sli4_sched_cq_work - Schedules cq work |
| 14286 | * @phba: Pointer to HBA context object. |
| 14287 | * @cq: Pointer to CQ |
| 14288 | * @cqid: CQ ID |
| 14289 | * |
| 14290 | * This routine checks the poll mode of the CQ corresponding to |
| 14291 | * cq->chann, then either schedules a softirq or queue_work to complete |
| 14292 | * cq work. |
| 14293 | * |
| 14294 | * queue_work path is taken if in NVMET mode, or if poll_mode is in |
| 14295 | * LPFC_QUEUE_WORK mode. Otherwise, softirq path is taken. |
| 14296 | * |
| 14297 | **/ |
| 14298 | static void lpfc_sli4_sched_cq_work(struct lpfc_hba *phba, |
| 14299 | struct lpfc_queue *cq, uint16_t cqid) |
| 14300 | { |
| 14301 | int ret = 0; |
| 14302 | |
| 14303 | switch (cq->poll_mode) { |
| 14304 | case LPFC_IRQ_POLL: |
| 14305 | irq_poll_sched(&cq->iop); |
| 14306 | break; |
| 14307 | case LPFC_QUEUE_WORK: |
| 14308 | default: |
| 14309 | if (is_kdump_kernel()) |
| 14310 | ret = queue_work(phba->wq, &cq->irqwork); |
| 14311 | else |
| 14312 | ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork); |
| 14313 | if (!ret) |
| 14314 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14315 | "0383 Cannot schedule queue work " |
| 14316 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 14317 | cqid, cq->queue_id, |
| 14318 | raw_smp_processor_id()); |
| 14319 | } |
| 14320 | } |
| 14321 | |
| 14322 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14323 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14324 | * @phba: Pointer to HBA context object. |
| 14325 | * @eqe: Pointer to fast-path event queue entry. |
| 14326 | * |
| 14327 | * This routine process a event queue entry from the fast-path event queue. |
| 14328 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14329 | * completion event on a completion queue, if not, an error shall be logged |
| 14330 | * and just return. Otherwise, it will get to the corresponding completion |
| 14331 | * queue and process all the entries on the completion queue, rearm the |
| 14332 | * completion queue, and then return. |
| 14333 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14334 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14335 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 14336 | struct lpfc_eqe *eqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14337 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14338 | struct lpfc_queue *cq = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14339 | uint32_t qidx = eq->hdwq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14340 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14341 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14342 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14343 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14344 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14345 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14346 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14347 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14348 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14349 | } |
| 14350 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14351 | /* Get the reference to the corresponding CQ */ |
| 14352 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14353 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14354 | /* Use the fast lookup method first */ |
| 14355 | if (cqid <= phba->sli4_hba.cq_max) { |
| 14356 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 14357 | if (cq) |
| 14358 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14359 | } |
| 14360 | |
| 14361 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14362 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14363 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14364 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14365 | /* Process NVMET unsol rcv */ |
| 14366 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14367 | goto process_cq; |
| 14368 | } |
| 14369 | } |
| 14370 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14371 | if (phba->sli4_hba.nvmels_cq && |
| 14372 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14373 | /* Process NVME unsol rcv */ |
| 14374 | cq = phba->sli4_hba.nvmels_cq; |
| 14375 | } |
| 14376 | |
| 14377 | /* Otherwise this is a Slow path event */ |
| 14378 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14379 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 14380 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14381 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14382 | } |
| 14383 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14384 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14385 | if (unlikely(cqid != cq->queue_id)) { |
| 14386 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14387 | "0368 Miss-matched fast-path completion " |
| 14388 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14389 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14390 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14391 | } |
| 14392 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14393 | work_cq: |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14394 | #if defined(CONFIG_SCSI_LPFC_DEBUG_FS) |
| 14395 | if (phba->ktime_on) |
| 14396 | cq->isr_timestamp = ktime_get_ns(); |
| 14397 | else |
| 14398 | cq->isr_timestamp = 0; |
| 14399 | #endif |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 14400 | lpfc_sli4_sched_cq_work(phba, cq, cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14401 | } |
| 14402 | |
| 14403 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14404 | * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14405 | * @cq: Pointer to CQ to be processed |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 14406 | * @poll_mode: Enum lpfc_poll_state to determine poll mode |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14407 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14408 | * This routine calls the cq processing routine with the handler for |
| 14409 | * fast path CQEs. |
| 14410 | * |
| 14411 | * The CQ routine returns two values: the first is the calling status, |
| 14412 | * which indicates whether work was queued to the background discovery |
| 14413 | * thread. If true, the routine should wakeup the discovery thread; |
| 14414 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14415 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14416 | * that it is processed in a subsequent polling action. The value of |
| 14417 | * the delay indicates when to reschedule it. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14418 | **/ |
| 14419 | static void |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 14420 | __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq, |
| 14421 | enum lpfc_poll_mode poll_mode) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14422 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14423 | struct lpfc_hba *phba = cq->phba; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14424 | unsigned long delay; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14425 | bool workposted = false; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14426 | int ret = 0; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14427 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14428 | /* process and rearm the CQ */ |
| 14429 | workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 14430 | &delay, poll_mode); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14431 | |
| 14432 | if (delay) { |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14433 | if (is_kdump_kernel()) |
| 14434 | ret = queue_delayed_work(phba->wq, &cq->sched_irqwork, |
| 14435 | delay); |
| 14436 | else |
| 14437 | ret = queue_delayed_work_on(cq->chann, phba->wq, |
| 14438 | &cq->sched_irqwork, delay); |
| 14439 | if (!ret) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14440 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 14441 | "0367 Cannot schedule queue work " |
| 14442 | "for cqid=%d on CPU %d\n", |
| 14443 | cq->queue_id, cq->chann); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14444 | } |
| 14445 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14446 | /* wake up worker thread if there are works to be done */ |
| 14447 | if (workposted) |
| 14448 | lpfc_worker_wake_up(phba); |
| 14449 | } |
| 14450 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14451 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14452 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by |
| 14453 | * interrupt |
| 14454 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14455 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14456 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14457 | **/ |
| 14458 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14459 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14460 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14461 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14462 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 14463 | __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14464 | } |
| 14465 | |
| 14466 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14467 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer |
| 14468 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14469 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14470 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14471 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14472 | static void |
| 14473 | lpfc_sli4_dly_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14474 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14475 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14476 | struct lpfc_queue, sched_irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14477 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 14478 | __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14479 | } |
| 14480 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14481 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14482 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14483 | * @irq: Interrupt number. |
| 14484 | * @dev_id: The device context pointer. |
| 14485 | * |
| 14486 | * This function is directly called from the PCI layer as an interrupt |
| 14487 | * service routine when device with SLI-4 interface spec is enabled with |
| 14488 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14489 | * ring event in the HBA. However, when the device is enabled with either |
| 14490 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14491 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14492 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14493 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14494 | * the intrrupt context. This function is called without any lock held. |
| 14495 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14496 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14497 | * equal to that of FCP CQ index. |
| 14498 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14499 | * The link attention and ELS ring attention events are handled |
| 14500 | * by the worker thread. The interrupt handler signals the worker thread |
| 14501 | * and returns for these events. This function is called without any lock |
| 14502 | * held. It gets the hbalock to access and update SLI data structures. |
| 14503 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14504 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14505 | * returns IRQ_NONE. |
| 14506 | **/ |
| 14507 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14508 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14509 | { |
| 14510 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14511 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14512 | struct lpfc_queue *fpeq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14513 | unsigned long iflag; |
| 14514 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14515 | int hba_eqidx; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14516 | struct lpfc_eq_intr_info *eqi; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14517 | |
| 14518 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14519 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14520 | phba = hba_eq_hdl->phba; |
| 14521 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14522 | |
| 14523 | if (unlikely(!phba)) |
| 14524 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14525 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14526 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14527 | |
| 14528 | /* Get to the EQ struct associated with this vector */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14529 | fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14530 | if (unlikely(!fpeq)) |
| 14531 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14532 | |
| 14533 | /* Check device state for handling interrupt */ |
| 14534 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14535 | /* Check again for link_state with lock held */ |
| 14536 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14537 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14538 | /* Flush, clear interrupt, and rearm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 14539 | lpfc_sli4_eqcq_flush(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14540 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14541 | return IRQ_NONE; |
| 14542 | } |
| 14543 | |
Dick Kennedy | a7fc071 | 2020-05-01 14:43:08 -0700 | [diff] [blame] | 14544 | eqi = this_cpu_ptr(phba->sli4_hba.eq_info); |
| 14545 | eqi->icnt++; |
| 14546 | |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14547 | fpeq->last_cpu = raw_smp_processor_id(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14548 | |
Dick Kennedy | a7fc071 | 2020-05-01 14:43:08 -0700 | [diff] [blame] | 14549 | if (eqi->icnt > LPFC_EQD_ISR_TRIGGER && |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 14550 | fpeq->q_flag & HBA_EQ_DELAY_CHK && |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14551 | phba->cfg_auto_imax && |
| 14552 | fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY && |
| 14553 | phba->sli.sli_flag & LPFC_SLI_USE_EQDR) |
| 14554 | lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14555 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14556 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14557 | ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14558 | |
| 14559 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14560 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14561 | if (phba->intr_type == MSIX) |
| 14562 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14563 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14564 | "0358 MSI-X interrupt with no EQE\n"); |
| 14565 | else |
| 14566 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14567 | return IRQ_NONE; |
| 14568 | } |
| 14569 | |
| 14570 | return IRQ_HANDLED; |
| 14571 | } /* lpfc_sli4_fp_intr_handler */ |
| 14572 | |
| 14573 | /** |
| 14574 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14575 | * @irq: Interrupt number. |
| 14576 | * @dev_id: The device context pointer. |
| 14577 | * |
| 14578 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14579 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14580 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14581 | * driver attention. This function invokes the slow-path interrupt attention |
| 14582 | * handling function and fast-path interrupt attention handling function in |
| 14583 | * turn to process the relevant HBA attention events. This function is called |
| 14584 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14585 | * structures. |
| 14586 | * |
| 14587 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14588 | * returns IRQ_NONE. |
| 14589 | **/ |
| 14590 | irqreturn_t |
| 14591 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14592 | { |
| 14593 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14594 | irqreturn_t hba_irq_rc; |
| 14595 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14596 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14597 | |
| 14598 | /* Get the driver's phba structure from the dev_id */ |
| 14599 | phba = (struct lpfc_hba *)dev_id; |
| 14600 | |
| 14601 | if (unlikely(!phba)) |
| 14602 | return IRQ_NONE; |
| 14603 | |
| 14604 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14605 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14606 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14607 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14608 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14609 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14610 | if (hba_irq_rc == IRQ_HANDLED) |
| 14611 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14612 | } |
| 14613 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14614 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14615 | } /* lpfc_sli4_intr_handler */ |
| 14616 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14617 | void lpfc_sli4_poll_hbtimer(struct timer_list *t) |
| 14618 | { |
| 14619 | struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer); |
| 14620 | struct lpfc_queue *eq; |
| 14621 | int i = 0; |
| 14622 | |
| 14623 | rcu_read_lock(); |
| 14624 | |
| 14625 | list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list) |
| 14626 | i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH); |
| 14627 | if (!list_empty(&phba->poll_list)) |
| 14628 | mod_timer(&phba->cpuhp_poll_timer, |
| 14629 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
| 14630 | |
| 14631 | rcu_read_unlock(); |
| 14632 | } |
| 14633 | |
| 14634 | inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path) |
| 14635 | { |
| 14636 | struct lpfc_hba *phba = eq->phba; |
| 14637 | int i = 0; |
| 14638 | |
| 14639 | /* |
| 14640 | * Unlocking an irq is one of the entry point to check |
| 14641 | * for re-schedule, but we are good for io submission |
| 14642 | * path as midlayer does a get_cpu to glue us in. Flush |
| 14643 | * out the invalidate queue so we can see the updated |
| 14644 | * value for flag. |
| 14645 | */ |
| 14646 | smp_rmb(); |
| 14647 | |
| 14648 | if (READ_ONCE(eq->mode) == LPFC_EQ_POLL) |
| 14649 | /* We will not likely get the completion for the caller |
| 14650 | * during this iteration but i guess that's fine. |
| 14651 | * Future io's coming on this eq should be able to |
| 14652 | * pick it up. As for the case of single io's, they |
| 14653 | * will be handled through a sched from polling timer |
| 14654 | * function which is currently triggered every 1msec. |
| 14655 | */ |
| 14656 | i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM); |
| 14657 | |
| 14658 | return i; |
| 14659 | } |
| 14660 | |
| 14661 | static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq) |
| 14662 | { |
| 14663 | struct lpfc_hba *phba = eq->phba; |
| 14664 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 14665 | /* kickstart slowpath processing if needed */ |
| 14666 | if (list_empty(&phba->poll_list)) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14667 | mod_timer(&phba->cpuhp_poll_timer, |
| 14668 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14669 | |
| 14670 | list_add_rcu(&eq->_poll_list, &phba->poll_list); |
| 14671 | synchronize_rcu(); |
| 14672 | } |
| 14673 | |
| 14674 | static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq) |
| 14675 | { |
| 14676 | struct lpfc_hba *phba = eq->phba; |
| 14677 | |
| 14678 | /* Disable slowpath processing for this eq. Kick start the eq |
| 14679 | * by RE-ARMING the eq's ASAP |
| 14680 | */ |
| 14681 | list_del_rcu(&eq->_poll_list); |
| 14682 | synchronize_rcu(); |
| 14683 | |
| 14684 | if (list_empty(&phba->poll_list)) |
| 14685 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 14686 | } |
| 14687 | |
James Smart | d480e57 | 2019-11-11 15:03:58 -0800 | [diff] [blame] | 14688 | void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14689 | { |
| 14690 | struct lpfc_queue *eq, *next; |
| 14691 | |
| 14692 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) |
| 14693 | list_del(&eq->_poll_list); |
| 14694 | |
| 14695 | INIT_LIST_HEAD(&phba->poll_list); |
| 14696 | synchronize_rcu(); |
| 14697 | } |
| 14698 | |
| 14699 | static inline void |
| 14700 | __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode) |
| 14701 | { |
| 14702 | if (mode == eq->mode) |
| 14703 | return; |
| 14704 | /* |
| 14705 | * currently this function is only called during a hotplug |
| 14706 | * event and the cpu on which this function is executing |
| 14707 | * is going offline. By now the hotplug has instructed |
| 14708 | * the scheduler to remove this cpu from cpu active mask. |
| 14709 | * So we don't need to work about being put aside by the |
| 14710 | * scheduler for a high priority process. Yes, the inte- |
| 14711 | * rrupts could come but they are known to retire ASAP. |
| 14712 | */ |
| 14713 | |
| 14714 | /* Disable polling in the fastpath */ |
| 14715 | WRITE_ONCE(eq->mode, mode); |
| 14716 | /* flush out the store buffer */ |
| 14717 | smp_wmb(); |
| 14718 | |
| 14719 | /* |
| 14720 | * Add this eq to the polling list and start polling. For |
| 14721 | * a grace period both interrupt handler and poller will |
| 14722 | * try to process the eq _but_ that's fine. We have a |
| 14723 | * synchronization mechanism in place (queue_claimed) to |
| 14724 | * deal with it. This is just a draining phase for int- |
| 14725 | * errupt handler (not eq's) as we have guranteed through |
| 14726 | * barrier that all the CPUs have seen the new CQ_POLLED |
| 14727 | * state. which will effectively disable the REARMING of |
| 14728 | * the EQ. The whole idea is eq's die off eventually as |
| 14729 | * we are not rearming EQ's anymore. |
| 14730 | */ |
| 14731 | mode ? lpfc_sli4_add_to_poll_list(eq) : |
| 14732 | lpfc_sli4_remove_from_poll_list(eq); |
| 14733 | } |
| 14734 | |
| 14735 | void lpfc_sli4_start_polling(struct lpfc_queue *eq) |
| 14736 | { |
| 14737 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL); |
| 14738 | } |
| 14739 | |
| 14740 | void lpfc_sli4_stop_polling(struct lpfc_queue *eq) |
| 14741 | { |
| 14742 | struct lpfc_hba *phba = eq->phba; |
| 14743 | |
| 14744 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT); |
| 14745 | |
| 14746 | /* Kick start for the pending io's in h/w. |
| 14747 | * Once we switch back to interrupt processing on a eq |
| 14748 | * the io path completion will only arm eq's when it |
| 14749 | * receives a completion. But since eq's are in disa- |
| 14750 | * rmed state it doesn't receive a completion. This |
| 14751 | * creates a deadlock scenaro. |
| 14752 | */ |
| 14753 | phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM); |
| 14754 | } |
| 14755 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14756 | /** |
| 14757 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14758 | * @queue: The queue structure to free. |
| 14759 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14760 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14761 | * the host resident queue. This function must be called after destroying the |
| 14762 | * queue on the HBA. |
| 14763 | **/ |
| 14764 | void |
| 14765 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14766 | { |
| 14767 | struct lpfc_dmabuf *dmabuf; |
| 14768 | |
| 14769 | if (!queue) |
| 14770 | return; |
| 14771 | |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 14772 | if (!list_empty(&queue->wq_list)) |
| 14773 | list_del(&queue->wq_list); |
| 14774 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14775 | while (!list_empty(&queue->page_list)) { |
| 14776 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14777 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14778 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14779 | dmabuf->virt, dmabuf->phys); |
| 14780 | kfree(dmabuf); |
| 14781 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14782 | if (queue->rqbp) { |
| 14783 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14784 | kfree(queue->rqbp); |
| 14785 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14786 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14787 | if (!list_empty(&queue->cpu_list)) |
| 14788 | list_del(&queue->cpu_list); |
| 14789 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14790 | kfree(queue); |
| 14791 | return; |
| 14792 | } |
| 14793 | |
| 14794 | /** |
| 14795 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14796 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14797 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14798 | * @entry_size: The size of each queue entry for this queue. |
| 14799 | * @entry count: The number of entries that this queue will handle. |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14800 | * @cpu: The cpu that will primarily utilize this queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14801 | * |
| 14802 | * This function allocates a queue structure and the DMAable memory used for |
| 14803 | * the host resident queue. This function must be called before creating the |
| 14804 | * queue on the HBA. |
| 14805 | **/ |
| 14806 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14807 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14808 | uint32_t entry_size, uint32_t entry_count, int cpu) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14809 | { |
| 14810 | struct lpfc_queue *queue; |
| 14811 | struct lpfc_dmabuf *dmabuf; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14812 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14813 | uint16_t x, pgcnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14814 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14815 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14816 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14817 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14818 | pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14819 | |
| 14820 | /* If needed, Adjust page count to match the max the adapter supports */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14821 | if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 14822 | pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14823 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14824 | queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt), |
| 14825 | GFP_KERNEL, cpu_to_node(cpu)); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14826 | if (!queue) |
| 14827 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14828 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14829 | INIT_LIST_HEAD(&queue->list); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14830 | INIT_LIST_HEAD(&queue->_poll_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14831 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14832 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14833 | INIT_LIST_HEAD(&queue->page_list); |
| 14834 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14835 | INIT_LIST_HEAD(&queue->cpu_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14836 | |
| 14837 | /* Set queue parameters now. If the system cannot provide memory |
| 14838 | * resources, the free routine needs to know what was allocated. |
| 14839 | */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14840 | queue->page_count = pgcnt; |
| 14841 | queue->q_pgs = (void **)&queue[1]; |
| 14842 | queue->entry_cnt_per_pg = hw_page_size / entry_size; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14843 | queue->entry_size = entry_size; |
| 14844 | queue->entry_count = entry_count; |
| 14845 | queue->page_size = hw_page_size; |
| 14846 | queue->phba = phba; |
| 14847 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14848 | for (x = 0; x < queue->page_count; x++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14849 | dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL, |
| 14850 | dev_to_node(&phba->pcidev->dev)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14851 | if (!dmabuf) |
| 14852 | goto out_fail; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 14853 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 14854 | hw_page_size, &dmabuf->phys, |
| 14855 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14856 | if (!dmabuf->virt) { |
| 14857 | kfree(dmabuf); |
| 14858 | goto out_fail; |
| 14859 | } |
| 14860 | dmabuf->buffer_tag = x; |
| 14861 | list_add_tail(&dmabuf->list, &queue->page_list); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14862 | /* use lpfc_sli4_qe to index a paritcular entry in this page */ |
| 14863 | queue->q_pgs[x] = dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14864 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14865 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14866 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14867 | INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq); |
| 14868 | INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14869 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14870 | /* notify_interval will be set during q creation */ |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14871 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14872 | return queue; |
| 14873 | out_fail: |
| 14874 | lpfc_sli4_queue_free(queue); |
| 14875 | return NULL; |
| 14876 | } |
| 14877 | |
| 14878 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14879 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14880 | * @phba: HBA structure that indicates port to create a queue on. |
| 14881 | * @pci_barset: PCI BAR set flag. |
| 14882 | * |
| 14883 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14884 | * memory address if not already done so and return it. The returned host |
| 14885 | * memory address can be NULL. |
| 14886 | */ |
| 14887 | static void __iomem * |
| 14888 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14889 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14890 | if (!phba->pcidev) |
| 14891 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14892 | |
| 14893 | switch (pci_barset) { |
| 14894 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14895 | return phba->pci_bar0_memmap_p; |
| 14896 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14897 | return phba->pci_bar2_memmap_p; |
| 14898 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14899 | return phba->pci_bar4_memmap_p; |
| 14900 | default: |
| 14901 | break; |
| 14902 | } |
| 14903 | return NULL; |
| 14904 | } |
| 14905 | |
| 14906 | /** |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14907 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs |
| 14908 | * @phba: HBA structure that EQs are on. |
| 14909 | * @startq: The starting EQ index to modify |
| 14910 | * @numq: The number of EQs (consecutive indexes) to modify |
| 14911 | * @usdelay: amount of delay |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14912 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14913 | * This function revises the EQ delay on 1 or more EQs. The EQ delay |
| 14914 | * is set either by writing to a register (if supported by the SLI Port) |
| 14915 | * or by mailbox command. The mailbox command allows several EQs to be |
| 14916 | * updated at once. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14917 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14918 | * The @phba struct is used to send a mailbox command to HBA. The @startq |
| 14919 | * is used to get the starting EQ index to change. The @numq value is |
| 14920 | * used to specify how many consecutive EQ indexes, starting at EQ index, |
| 14921 | * are to be changed. This function is asynchronous and will wait for any |
| 14922 | * mailbox commands to finish before returning. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14923 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14924 | * On success this function will return a zero. If unable to allocate |
| 14925 | * enough memory this function will return -ENOMEM. If a mailbox command |
| 14926 | * fails this function will return -ENXIO. Note: on ENXIO, some EQs may |
| 14927 | * have had their delay multipler changed. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14928 | **/ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14929 | void |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14930 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14931 | uint32_t numq, uint32_t usdelay) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14932 | { |
| 14933 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14934 | LPFC_MBOXQ_t *mbox; |
| 14935 | struct lpfc_queue *eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14936 | int cnt = 0, rc, length; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14937 | uint32_t shdr_status, shdr_add_status; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14938 | uint32_t dmult; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14939 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14940 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14941 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14942 | if (startq >= phba->cfg_irq_chann) |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14943 | return; |
| 14944 | |
| 14945 | if (usdelay > 0xFFFF) { |
| 14946 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14947 | "6429 usdelay %d too large. Scaled down to " |
| 14948 | "0xFFFF.\n", usdelay); |
| 14949 | usdelay = 0xFFFF; |
| 14950 | } |
| 14951 | |
| 14952 | /* set values by EQ_DELAY register if supported */ |
| 14953 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14954 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14955 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14956 | if (!eq) |
| 14957 | continue; |
| 14958 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14959 | lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14960 | |
| 14961 | if (++cnt >= numq) |
| 14962 | break; |
| 14963 | } |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14964 | return; |
| 14965 | } |
| 14966 | |
| 14967 | /* Otherwise, set values by mailbox cmd */ |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14968 | |
| 14969 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14970 | if (!mbox) { |
| 14971 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14972 | "6428 Failed allocating mailbox cmd buffer." |
| 14973 | " EQ delay was not set.\n"); |
| 14974 | return; |
| 14975 | } |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14976 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14977 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14978 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14979 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14980 | length, LPFC_SLI4_MBX_EMBED); |
| 14981 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14982 | |
| 14983 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14984 | dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC; |
| 14985 | if (dmult) |
| 14986 | dmult--; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14987 | if (dmult > LPFC_DMULT_MAX) |
| 14988 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14989 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14990 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14991 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14992 | if (!eq) |
| 14993 | continue; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14994 | eq->q_mode = usdelay; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14995 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14996 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14997 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14998 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14999 | if (++cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15000 | break; |
| 15001 | } |
| 15002 | eq_delay->u.request.num_eq = cnt; |
| 15003 | |
| 15004 | mbox->vport = phba->pport; |
| 15005 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 15006 | mbox->ctx_buf = NULL; |
| 15007 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15008 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15009 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 15010 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15011 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15012 | if (shdr_status || shdr_add_status || rc) { |
| 15013 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15014 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 15015 | "status x%x add_status x%x, mbx status x%x\n", |
| 15016 | shdr_status, shdr_add_status, rc); |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15017 | } |
| 15018 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15019 | return; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15020 | } |
| 15021 | |
| 15022 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15023 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 15024 | * @phba: HBA structure that indicates port to create a queue on. |
| 15025 | * @eq: The queue structure to use to create the event queue. |
| 15026 | * @imax: The maximum interrupt per second limit. |
| 15027 | * |
| 15028 | * This function creates an event queue, as detailed in @eq, on a port, |
| 15029 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 15030 | * |
| 15031 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 15032 | * is used to get the entry count and entry size that are necessary to |
| 15033 | * determine the number of pages to allocate and use for this queue. This |
| 15034 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 15035 | * event queue. This function is asynchronous and will wait for the mailbox |
| 15036 | * command to finish before continuing. |
| 15037 | * |
| 15038 | * 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] | 15039 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15040 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15041 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15042 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 15043 | 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] | 15044 | { |
| 15045 | struct lpfc_mbx_eq_create *eq_create; |
| 15046 | LPFC_MBOXQ_t *mbox; |
| 15047 | int rc, length, status = 0; |
| 15048 | struct lpfc_dmabuf *dmabuf; |
| 15049 | uint32_t shdr_status, shdr_add_status; |
| 15050 | union lpfc_sli4_cfg_shdr *shdr; |
| 15051 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15052 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15053 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15054 | /* sanity check on queue memory */ |
| 15055 | if (!eq) |
| 15056 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15057 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15058 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15059 | |
| 15060 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15061 | if (!mbox) |
| 15062 | return -ENOMEM; |
| 15063 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 15064 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15065 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15066 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 15067 | length, LPFC_SLI4_MBX_EMBED); |
| 15068 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15069 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15070 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 15071 | eq->page_count); |
| 15072 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 15073 | LPFC_EQE_SIZE); |
| 15074 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15075 | |
| 15076 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 15077 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 15078 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15079 | LPFC_Q_CREATE_VERSION_2); |
| 15080 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 15081 | phba->sli4_hba.pc_sli4_params.eqav); |
| 15082 | } |
| 15083 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 15084 | /* don't setup delay multiplier using EQ_CREATE */ |
| 15085 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15086 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 15087 | dmult); |
| 15088 | switch (eq->entry_count) { |
| 15089 | default: |
| 15090 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15091 | "0360 Unsupported EQ count. (%d)\n", |
| 15092 | eq->entry_count); |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 15093 | if (eq->entry_count < 256) { |
| 15094 | status = -EINVAL; |
| 15095 | goto out; |
| 15096 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15097 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15098 | case 256: |
| 15099 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15100 | LPFC_EQ_CNT_256); |
| 15101 | break; |
| 15102 | case 512: |
| 15103 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15104 | LPFC_EQ_CNT_512); |
| 15105 | break; |
| 15106 | case 1024: |
| 15107 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15108 | LPFC_EQ_CNT_1024); |
| 15109 | break; |
| 15110 | case 2048: |
| 15111 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15112 | LPFC_EQ_CNT_2048); |
| 15113 | break; |
| 15114 | case 4096: |
| 15115 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15116 | LPFC_EQ_CNT_4096); |
| 15117 | break; |
| 15118 | } |
| 15119 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15120 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15121 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15122 | putPaddrLow(dmabuf->phys); |
| 15123 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15124 | putPaddrHigh(dmabuf->phys); |
| 15125 | } |
| 15126 | mbox->vport = phba->pport; |
| 15127 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 15128 | mbox->ctx_buf = NULL; |
| 15129 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15130 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15131 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15132 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15133 | if (shdr_status || shdr_add_status || rc) { |
| 15134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15135 | "2500 EQ_CREATE mailbox failed with " |
| 15136 | "status x%x add_status x%x, mbx status x%x\n", |
| 15137 | shdr_status, shdr_add_status, rc); |
| 15138 | status = -ENXIO; |
| 15139 | } |
| 15140 | eq->type = LPFC_EQ; |
| 15141 | eq->subtype = LPFC_NONE; |
| 15142 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 15143 | if (eq->queue_id == 0xFFFF) |
| 15144 | status = -ENXIO; |
| 15145 | eq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15146 | eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL; |
| 15147 | eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT; |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 15148 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15149 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15150 | return status; |
| 15151 | } |
| 15152 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 15153 | static int lpfc_cq_poll_hdler(struct irq_poll *iop, int budget) |
| 15154 | { |
| 15155 | struct lpfc_queue *cq = container_of(iop, struct lpfc_queue, iop); |
| 15156 | |
| 15157 | __lpfc_sli4_hba_process_cq(cq, LPFC_IRQ_POLL); |
| 15158 | |
| 15159 | return 1; |
| 15160 | } |
| 15161 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15162 | /** |
| 15163 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 15164 | * @phba: HBA structure that indicates port to create a queue on. |
| 15165 | * @cq: The queue structure to use to create the completion queue. |
| 15166 | * @eq: The event queue to bind this completion queue to. |
| 15167 | * |
| 15168 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 15169 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 15170 | * |
| 15171 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15172 | * is used to get the entry count and entry size that are necessary to |
| 15173 | * determine the number of pages to allocate and use for this queue. The @eq |
| 15174 | * is used to indicate which event queue to bind this completion queue to. This |
| 15175 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 15176 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 15177 | * command to finish before continuing. |
| 15178 | * |
| 15179 | * 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] | 15180 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15181 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15182 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15183 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15184 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 15185 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 15186 | { |
| 15187 | struct lpfc_mbx_cq_create *cq_create; |
| 15188 | struct lpfc_dmabuf *dmabuf; |
| 15189 | LPFC_MBOXQ_t *mbox; |
| 15190 | int rc, length, status = 0; |
| 15191 | uint32_t shdr_status, shdr_add_status; |
| 15192 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15193 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15194 | /* sanity check on queue memory */ |
| 15195 | if (!cq || !eq) |
| 15196 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15197 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15198 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15199 | if (!mbox) |
| 15200 | return -ENOMEM; |
| 15201 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 15202 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15203 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15204 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 15205 | length, LPFC_SLI4_MBX_EMBED); |
| 15206 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15207 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15208 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 15209 | cq->page_count); |
| 15210 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 15211 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15212 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15213 | phba->sli4_hba.pc_sli4_params.cqv); |
| 15214 | 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] | 15215 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 15216 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15217 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 15218 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15219 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 15220 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15221 | } else { |
| 15222 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 15223 | eq->queue_id); |
| 15224 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15225 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15226 | case 2048: |
| 15227 | case 4096: |
| 15228 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15229 | LPFC_Q_CREATE_VERSION_2) { |
| 15230 | cq_create->u.request.context.lpfc_cq_context_count = |
| 15231 | cq->entry_count; |
| 15232 | bf_set(lpfc_cq_context_count, |
| 15233 | &cq_create->u.request.context, |
| 15234 | LPFC_CQ_CNT_WORD7); |
| 15235 | break; |
| 15236 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15237 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15238 | default: |
| 15239 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15240 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15241 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15242 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15243 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15244 | if (cq->entry_count < 256) { |
| 15245 | status = -EINVAL; |
| 15246 | goto out; |
| 15247 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15248 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15249 | case 256: |
| 15250 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15251 | LPFC_CQ_CNT_256); |
| 15252 | break; |
| 15253 | case 512: |
| 15254 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15255 | LPFC_CQ_CNT_512); |
| 15256 | break; |
| 15257 | case 1024: |
| 15258 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15259 | LPFC_CQ_CNT_1024); |
| 15260 | break; |
| 15261 | } |
| 15262 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15263 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15264 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15265 | putPaddrLow(dmabuf->phys); |
| 15266 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15267 | putPaddrHigh(dmabuf->phys); |
| 15268 | } |
| 15269 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15270 | |
| 15271 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15272 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15273 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15274 | if (shdr_status || shdr_add_status || rc) { |
| 15275 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15276 | "2501 CQ_CREATE mailbox failed with " |
| 15277 | "status x%x add_status x%x, mbx status x%x\n", |
| 15278 | shdr_status, shdr_add_status, rc); |
| 15279 | status = -ENXIO; |
| 15280 | goto out; |
| 15281 | } |
| 15282 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 15283 | if (cq->queue_id == 0xFFFF) { |
| 15284 | status = -ENXIO; |
| 15285 | goto out; |
| 15286 | } |
| 15287 | /* link the cq onto the parent eq child list */ |
| 15288 | list_add_tail(&cq->list, &eq->child_list); |
| 15289 | /* Set up completion queue's type and subtype */ |
| 15290 | cq->type = type; |
| 15291 | cq->subtype = subtype; |
| 15292 | 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] | 15293 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15294 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15295 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15296 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15297 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15298 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15299 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15300 | phba->sli4_hba.cq_max = cq->queue_id; |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame^] | 15301 | |
| 15302 | irq_poll_init(&cq->iop, LPFC_IRQ_POLL_WEIGHT, lpfc_cq_poll_hdler); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15303 | out: |
| 15304 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15305 | return status; |
| 15306 | } |
| 15307 | |
| 15308 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15309 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 15310 | * @phba: HBA structure that indicates port to create a queue on. |
| 15311 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15312 | * @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] | 15313 | * |
| 15314 | * This function creates a set of completion queue, s to support MRQ |
| 15315 | * as detailed in @cqp, on a port, |
| 15316 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 15317 | * |
| 15318 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15319 | * is used to get the entry count and entry size that are necessary to |
| 15320 | * determine the number of pages to allocate and use for this queue. The @eq |
| 15321 | * is used to indicate which event queue to bind this completion queue to. This |
| 15322 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 15323 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 15324 | * command to finish before continuing. |
| 15325 | * |
| 15326 | * On success this function will return a zero. If unable to allocate enough |
| 15327 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15328 | * fails this function will return -ENXIO. |
| 15329 | **/ |
| 15330 | int |
| 15331 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15332 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 15333 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15334 | { |
| 15335 | struct lpfc_queue *cq; |
| 15336 | struct lpfc_queue *eq; |
| 15337 | struct lpfc_mbx_cq_create_set *cq_set; |
| 15338 | struct lpfc_dmabuf *dmabuf; |
| 15339 | LPFC_MBOXQ_t *mbox; |
| 15340 | int rc, length, alloclen, status = 0; |
| 15341 | int cnt, idx, numcq, page_idx = 0; |
| 15342 | uint32_t shdr_status, shdr_add_status; |
| 15343 | union lpfc_sli4_cfg_shdr *shdr; |
| 15344 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15345 | |
| 15346 | /* sanity check on queue memory */ |
| 15347 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15348 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15349 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15350 | |
| 15351 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15352 | if (!mbox) |
| 15353 | return -ENOMEM; |
| 15354 | |
| 15355 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 15356 | length += ((numcq * cqp[0]->page_count) * |
| 15357 | sizeof(struct dma_address)); |
| 15358 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15359 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 15360 | LPFC_SLI4_MBX_NEMBED); |
| 15361 | if (alloclen < length) { |
| 15362 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15363 | "3098 Allocated DMA memory size (%d) is " |
| 15364 | "less than the requested DMA memory size " |
| 15365 | "(%d)\n", alloclen, length); |
| 15366 | status = -ENOMEM; |
| 15367 | goto out; |
| 15368 | } |
| 15369 | cq_set = mbox->sge_array->addr[0]; |
| 15370 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 15371 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 15372 | |
| 15373 | for (idx = 0; idx < numcq; idx++) { |
| 15374 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15375 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15376 | if (!cq || !eq) { |
| 15377 | status = -ENOMEM; |
| 15378 | goto out; |
| 15379 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15380 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15381 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15382 | |
| 15383 | switch (idx) { |
| 15384 | case 0: |
| 15385 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 15386 | &cq_set->u.request, |
| 15387 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 15388 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 15389 | &cq_set->u.request, cq->page_count); |
| 15390 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 15391 | &cq_set->u.request, 1); |
| 15392 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 15393 | &cq_set->u.request, 1); |
| 15394 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 15395 | &cq_set->u.request, 0); |
| 15396 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 15397 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15398 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 15399 | &cq_set->u.request, |
| 15400 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15401 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15402 | case 2048: |
| 15403 | case 4096: |
| 15404 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15405 | LPFC_Q_CREATE_VERSION_2) { |
| 15406 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15407 | &cq_set->u.request, |
| 15408 | cq->entry_count); |
| 15409 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15410 | &cq_set->u.request, |
| 15411 | LPFC_CQ_CNT_WORD7); |
| 15412 | break; |
| 15413 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15414 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15415 | default: |
| 15416 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15417 | "3118 Bad CQ count. (%d)\n", |
| 15418 | cq->entry_count); |
| 15419 | if (cq->entry_count < 256) { |
| 15420 | status = -EINVAL; |
| 15421 | goto out; |
| 15422 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15423 | /* fall through - otherwise default to smallest */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15424 | case 256: |
| 15425 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15426 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 15427 | break; |
| 15428 | case 512: |
| 15429 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15430 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 15431 | break; |
| 15432 | case 1024: |
| 15433 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15434 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 15435 | break; |
| 15436 | } |
| 15437 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 15438 | &cq_set->u.request, eq->queue_id); |
| 15439 | break; |
| 15440 | case 1: |
| 15441 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 15442 | &cq_set->u.request, eq->queue_id); |
| 15443 | break; |
| 15444 | case 2: |
| 15445 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 15446 | &cq_set->u.request, eq->queue_id); |
| 15447 | break; |
| 15448 | case 3: |
| 15449 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 15450 | &cq_set->u.request, eq->queue_id); |
| 15451 | break; |
| 15452 | case 4: |
| 15453 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 15454 | &cq_set->u.request, eq->queue_id); |
| 15455 | break; |
| 15456 | case 5: |
| 15457 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 15458 | &cq_set->u.request, eq->queue_id); |
| 15459 | break; |
| 15460 | case 6: |
| 15461 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 15462 | &cq_set->u.request, eq->queue_id); |
| 15463 | break; |
| 15464 | case 7: |
| 15465 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 15466 | &cq_set->u.request, eq->queue_id); |
| 15467 | break; |
| 15468 | case 8: |
| 15469 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 15470 | &cq_set->u.request, eq->queue_id); |
| 15471 | break; |
| 15472 | case 9: |
| 15473 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 15474 | &cq_set->u.request, eq->queue_id); |
| 15475 | break; |
| 15476 | case 10: |
| 15477 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 15478 | &cq_set->u.request, eq->queue_id); |
| 15479 | break; |
| 15480 | case 11: |
| 15481 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 15482 | &cq_set->u.request, eq->queue_id); |
| 15483 | break; |
| 15484 | case 12: |
| 15485 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 15486 | &cq_set->u.request, eq->queue_id); |
| 15487 | break; |
| 15488 | case 13: |
| 15489 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 15490 | &cq_set->u.request, eq->queue_id); |
| 15491 | break; |
| 15492 | case 14: |
| 15493 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 15494 | &cq_set->u.request, eq->queue_id); |
| 15495 | break; |
| 15496 | case 15: |
| 15497 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 15498 | &cq_set->u.request, eq->queue_id); |
| 15499 | break; |
| 15500 | } |
| 15501 | |
| 15502 | /* link the cq onto the parent eq child list */ |
| 15503 | list_add_tail(&cq->list, &eq->child_list); |
| 15504 | /* Set up completion queue's type and subtype */ |
| 15505 | cq->type = type; |
| 15506 | cq->subtype = subtype; |
| 15507 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15508 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15509 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15510 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15511 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, |
| 15512 | cq->entry_count); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15513 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15514 | |
| 15515 | rc = 0; |
| 15516 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15517 | memset(dmabuf->virt, 0, hw_page_size); |
| 15518 | cnt = page_idx + dmabuf->buffer_tag; |
| 15519 | cq_set->u.request.page[cnt].addr_lo = |
| 15520 | putPaddrLow(dmabuf->phys); |
| 15521 | cq_set->u.request.page[cnt].addr_hi = |
| 15522 | putPaddrHigh(dmabuf->phys); |
| 15523 | rc++; |
| 15524 | } |
| 15525 | page_idx += rc; |
| 15526 | } |
| 15527 | |
| 15528 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15529 | |
| 15530 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15531 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15532 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15533 | if (shdr_status || shdr_add_status || rc) { |
| 15534 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15535 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15536 | "status x%x add_status x%x, mbx status x%x\n", |
| 15537 | shdr_status, shdr_add_status, rc); |
| 15538 | status = -ENXIO; |
| 15539 | goto out; |
| 15540 | } |
| 15541 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15542 | if (rc == 0xFFFF) { |
| 15543 | status = -ENXIO; |
| 15544 | goto out; |
| 15545 | } |
| 15546 | |
| 15547 | for (idx = 0; idx < numcq; idx++) { |
| 15548 | cq = cqp[idx]; |
| 15549 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15550 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15551 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15552 | } |
| 15553 | |
| 15554 | out: |
| 15555 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15556 | return status; |
| 15557 | } |
| 15558 | |
| 15559 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15560 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15561 | * @phba: HBA structure that indicates port to create a queue on. |
| 15562 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15563 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15564 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15565 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15566 | * This function provides failback (fb) functionality when the |
| 15567 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15568 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15569 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15570 | * This routine cannot fail as all attributes were previously accessed and |
| 15571 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15572 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15573 | static void |
| 15574 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15575 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15576 | { |
| 15577 | struct lpfc_mbx_mq_create *mq_create; |
| 15578 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15579 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15580 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15581 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15582 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15583 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15584 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15585 | length, LPFC_SLI4_MBX_EMBED); |
| 15586 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15587 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15588 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15589 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15590 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15591 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15592 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15593 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15594 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15595 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15596 | break; |
| 15597 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15598 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15599 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15600 | break; |
| 15601 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15602 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15603 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15604 | break; |
| 15605 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15606 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15607 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15608 | break; |
| 15609 | } |
| 15610 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15611 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15612 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15613 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15614 | putPaddrHigh(dmabuf->phys); |
| 15615 | } |
| 15616 | } |
| 15617 | |
| 15618 | /** |
| 15619 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15620 | * @phba: HBA structure that indicates port to create a queue on. |
| 15621 | * @mq: The queue structure to use to create the mailbox queue. |
| 15622 | * @cq: The completion queue to associate with this cq. |
| 15623 | * @subtype: The queue's subtype. |
| 15624 | * |
| 15625 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15626 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15627 | * |
| 15628 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15629 | * is used to get the entry count and entry size that are necessary to |
| 15630 | * determine the number of pages to allocate and use for this queue. This |
| 15631 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15632 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15633 | * command to finish before continuing. |
| 15634 | * |
| 15635 | * 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] | 15636 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15637 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15638 | **/ |
| 15639 | int32_t |
| 15640 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15641 | struct lpfc_queue *cq, uint32_t subtype) |
| 15642 | { |
| 15643 | struct lpfc_mbx_mq_create *mq_create; |
| 15644 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15645 | struct lpfc_dmabuf *dmabuf; |
| 15646 | LPFC_MBOXQ_t *mbox; |
| 15647 | int rc, length, status = 0; |
| 15648 | uint32_t shdr_status, shdr_add_status; |
| 15649 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15650 | 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] | 15651 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15652 | /* sanity check on queue memory */ |
| 15653 | if (!mq || !cq) |
| 15654 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15655 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15656 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15657 | |
| 15658 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15659 | if (!mbox) |
| 15660 | return -ENOMEM; |
| 15661 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15662 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15663 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15664 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15665 | length, LPFC_SLI4_MBX_EMBED); |
| 15666 | |
| 15667 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15668 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15669 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15670 | &mq_create_ext->u.request, mq->page_count); |
| 15671 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15672 | &mq_create_ext->u.request, 1); |
| 15673 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15674 | &mq_create_ext->u.request, 1); |
| 15675 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15676 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15677 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15678 | &mq_create_ext->u.request, 1); |
| 15679 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15680 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15681 | 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] | 15682 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15683 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15684 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15685 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15686 | cq->queue_id); |
| 15687 | else |
| 15688 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15689 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15690 | switch (mq->entry_count) { |
| 15691 | default: |
| 15692 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15693 | "0362 Unsupported MQ count. (%d)\n", |
| 15694 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15695 | if (mq->entry_count < 16) { |
| 15696 | status = -EINVAL; |
| 15697 | goto out; |
| 15698 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15699 | /* fall through - otherwise default to smallest count */ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15700 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15701 | bf_set(lpfc_mq_context_ring_size, |
| 15702 | &mq_create_ext->u.request.context, |
| 15703 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15704 | break; |
| 15705 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15706 | bf_set(lpfc_mq_context_ring_size, |
| 15707 | &mq_create_ext->u.request.context, |
| 15708 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15709 | break; |
| 15710 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15711 | bf_set(lpfc_mq_context_ring_size, |
| 15712 | &mq_create_ext->u.request.context, |
| 15713 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15714 | break; |
| 15715 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15716 | bf_set(lpfc_mq_context_ring_size, |
| 15717 | &mq_create_ext->u.request.context, |
| 15718 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15719 | break; |
| 15720 | } |
| 15721 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15722 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15723 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15724 | putPaddrLow(dmabuf->phys); |
| 15725 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15726 | putPaddrHigh(dmabuf->phys); |
| 15727 | } |
| 15728 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15729 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15730 | &mq_create_ext->u.response); |
| 15731 | if (rc != MBX_SUCCESS) { |
| 15732 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15733 | "2795 MQ_CREATE_EXT failed with " |
| 15734 | "status x%x. Failback to MQ_CREATE.\n", |
| 15735 | rc); |
| 15736 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15737 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15738 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15739 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15740 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15741 | &mq_create->u.response); |
| 15742 | } |
| 15743 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15744 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15745 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15746 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15747 | if (shdr_status || shdr_add_status || rc) { |
| 15748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15749 | "2502 MQ_CREATE mailbox failed with " |
| 15750 | "status x%x add_status x%x, mbx status x%x\n", |
| 15751 | shdr_status, shdr_add_status, rc); |
| 15752 | status = -ENXIO; |
| 15753 | goto out; |
| 15754 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15755 | if (mq->queue_id == 0xFFFF) { |
| 15756 | status = -ENXIO; |
| 15757 | goto out; |
| 15758 | } |
| 15759 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15760 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15761 | mq->subtype = subtype; |
| 15762 | mq->host_index = 0; |
| 15763 | mq->hba_index = 0; |
| 15764 | |
| 15765 | /* link the mq onto the parent cq child list */ |
| 15766 | list_add_tail(&mq->list, &cq->child_list); |
| 15767 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15768 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15769 | return status; |
| 15770 | } |
| 15771 | |
| 15772 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15773 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15774 | * @phba: HBA structure that indicates port to create a queue on. |
| 15775 | * @wq: The queue structure to use to create the work queue. |
| 15776 | * @cq: The completion queue to bind this work queue to. |
| 15777 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15778 | * |
| 15779 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15780 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15781 | * |
| 15782 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15783 | * is used to get the entry count and entry size that are necessary to |
| 15784 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15785 | * is used to indicate which completion queue to bind this work queue to. This |
| 15786 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15787 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15788 | * command to finish before continuing. |
| 15789 | * |
| 15790 | * 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] | 15791 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15792 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15793 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15794 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15795 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15796 | struct lpfc_queue *cq, uint32_t subtype) |
| 15797 | { |
| 15798 | struct lpfc_mbx_wq_create *wq_create; |
| 15799 | struct lpfc_dmabuf *dmabuf; |
| 15800 | LPFC_MBOXQ_t *mbox; |
| 15801 | int rc, length, status = 0; |
| 15802 | uint32_t shdr_status, shdr_add_status; |
| 15803 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15804 | 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] | 15805 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15806 | void __iomem *bar_memmap_p; |
| 15807 | uint32_t db_offset; |
| 15808 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15809 | uint8_t dpp_barset; |
| 15810 | uint32_t dpp_offset; |
| 15811 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15812 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15813 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15814 | /* sanity check on queue memory */ |
| 15815 | if (!wq || !cq) |
| 15816 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15817 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15818 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15819 | |
| 15820 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15821 | if (!mbox) |
| 15822 | return -ENOMEM; |
| 15823 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15824 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15825 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15826 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15827 | length, LPFC_SLI4_MBX_EMBED); |
| 15828 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15829 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15830 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15831 | wq->page_count); |
| 15832 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15833 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15834 | |
| 15835 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15836 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15837 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15838 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15839 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15840 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15841 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15842 | else |
| 15843 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15844 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15845 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15846 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15847 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15848 | else |
| 15849 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15850 | |
| 15851 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15852 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15853 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15854 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15855 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15856 | LPFC_Q_CREATE_VERSION_1); |
| 15857 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15858 | switch (wq->entry_size) { |
| 15859 | default: |
| 15860 | case 64: |
| 15861 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15862 | &wq_create->u.request_1, |
| 15863 | LPFC_WQ_WQE_SIZE_64); |
| 15864 | break; |
| 15865 | case 128: |
| 15866 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15867 | &wq_create->u.request_1, |
| 15868 | LPFC_WQ_WQE_SIZE_128); |
| 15869 | break; |
| 15870 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15871 | /* Request DPP by default */ |
| 15872 | 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] | 15873 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15874 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15875 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15876 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15877 | break; |
| 15878 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15879 | page = wq_create->u.request.page; |
| 15880 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15881 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15882 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15883 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15884 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15885 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15886 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15887 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15888 | |
| 15889 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15890 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15891 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15892 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15893 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15894 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15895 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15896 | if (shdr_status || shdr_add_status || rc) { |
| 15897 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15898 | "2503 WQ_CREATE mailbox failed with " |
| 15899 | "status x%x add_status x%x, mbx status x%x\n", |
| 15900 | shdr_status, shdr_add_status, rc); |
| 15901 | status = -ENXIO; |
| 15902 | goto out; |
| 15903 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15904 | |
| 15905 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15906 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15907 | &wq_create->u.response); |
| 15908 | else |
| 15909 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15910 | &wq_create->u.response_1); |
| 15911 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15912 | if (wq->queue_id == 0xFFFF) { |
| 15913 | status = -ENXIO; |
| 15914 | goto out; |
| 15915 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15916 | |
| 15917 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15918 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15919 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15920 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15921 | &wq_create->u.response); |
| 15922 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15923 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15924 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15925 | "3265 WQ[%d] doorbell format " |
| 15926 | "not supported: x%x\n", |
| 15927 | wq->queue_id, wq->db_format); |
| 15928 | status = -EINVAL; |
| 15929 | goto out; |
| 15930 | } |
| 15931 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15932 | &wq_create->u.response); |
| 15933 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15934 | pci_barset); |
| 15935 | if (!bar_memmap_p) { |
| 15936 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15937 | "3263 WQ[%d] failed to memmap " |
| 15938 | "pci barset:x%x\n", |
| 15939 | wq->queue_id, pci_barset); |
| 15940 | status = -ENOMEM; |
| 15941 | goto out; |
| 15942 | } |
| 15943 | db_offset = wq_create->u.response.doorbell_offset; |
| 15944 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15945 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15946 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15947 | "3252 WQ[%d] doorbell offset " |
| 15948 | "not supported: x%x\n", |
| 15949 | wq->queue_id, db_offset); |
| 15950 | status = -EINVAL; |
| 15951 | goto out; |
| 15952 | } |
| 15953 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15954 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15955 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15956 | "format:x%x\n", wq->queue_id, |
| 15957 | pci_barset, db_offset, wq->db_format); |
| 15958 | } else |
| 15959 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15960 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15961 | /* Check if DPP was honored by the firmware */ |
| 15962 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15963 | &wq_create->u.response_1); |
| 15964 | if (wq->dpp_enable) { |
| 15965 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15966 | &wq_create->u.response_1); |
| 15967 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15968 | pci_barset); |
| 15969 | if (!bar_memmap_p) { |
| 15970 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15971 | "3267 WQ[%d] failed to memmap " |
| 15972 | "pci barset:x%x\n", |
| 15973 | wq->queue_id, pci_barset); |
| 15974 | status = -ENOMEM; |
| 15975 | goto out; |
| 15976 | } |
| 15977 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15978 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15979 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15980 | &wq_create->u.response_1); |
| 15981 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15982 | &wq_create->u.response_1); |
| 15983 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15984 | dpp_barset); |
| 15985 | if (!bar_memmap_p) { |
| 15986 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15987 | "3268 WQ[%d] failed to memmap " |
| 15988 | "pci barset:x%x\n", |
| 15989 | wq->queue_id, dpp_barset); |
| 15990 | status = -ENOMEM; |
| 15991 | goto out; |
| 15992 | } |
| 15993 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15994 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15995 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15996 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15997 | "dpp_id:x%x dpp_barset:x%x " |
| 15998 | "dpp_offset:x%x\n", |
| 15999 | wq->queue_id, pci_barset, db_offset, |
| 16000 | wq->dpp_id, dpp_barset, dpp_offset); |
| 16001 | |
| 16002 | /* Enable combined writes for DPP aperture */ |
| 16003 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 16004 | #ifdef CONFIG_X86 |
| 16005 | rc = set_memory_wc(pg_addr, 1); |
| 16006 | if (rc) { |
| 16007 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16008 | "3272 Cannot setup Combined " |
| 16009 | "Write on WQ[%d] - disable DPP\n", |
| 16010 | wq->queue_id); |
| 16011 | phba->cfg_enable_dpp = 0; |
| 16012 | } |
| 16013 | #else |
| 16014 | phba->cfg_enable_dpp = 0; |
| 16015 | #endif |
| 16016 | } else |
| 16017 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16018 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16019 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 16020 | if (wq->pring == NULL) { |
| 16021 | status = -ENOMEM; |
| 16022 | goto out; |
| 16023 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16024 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16025 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16026 | wq->subtype = subtype; |
| 16027 | wq->host_index = 0; |
| 16028 | wq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16029 | wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16030 | |
| 16031 | /* link the wq onto the parent cq child list */ |
| 16032 | list_add_tail(&wq->list, &cq->child_list); |
| 16033 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16034 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16035 | return status; |
| 16036 | } |
| 16037 | |
| 16038 | /** |
| 16039 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 16040 | * @phba: HBA structure that indicates port to create a queue on. |
| 16041 | * @hrq: The queue structure to use to create the header receive queue. |
| 16042 | * @drq: The queue structure to use to create the data receive queue. |
| 16043 | * @cq: The completion queue to bind this work queue to. |
| 16044 | * |
| 16045 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 16046 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 16047 | * to the HBA. |
| 16048 | * |
| 16049 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 16050 | * struct is used to get the entry count that is necessary to determine the |
| 16051 | * number of pages to use for this queue. The @cq is used to indicate which |
| 16052 | * completion queue to bind received buffers that are posted to these queues to. |
| 16053 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 16054 | * receive queue pair. This function is asynchronous and will wait for the |
| 16055 | * mailbox command to finish before continuing. |
| 16056 | * |
| 16057 | * 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] | 16058 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16059 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16060 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16061 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16062 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16063 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 16064 | { |
| 16065 | struct lpfc_mbx_rq_create *rq_create; |
| 16066 | struct lpfc_dmabuf *dmabuf; |
| 16067 | LPFC_MBOXQ_t *mbox; |
| 16068 | int rc, length, status = 0; |
| 16069 | uint32_t shdr_status, shdr_add_status; |
| 16070 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16071 | 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] | 16072 | void __iomem *bar_memmap_p; |
| 16073 | uint32_t db_offset; |
| 16074 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16075 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16076 | /* sanity check on queue memory */ |
| 16077 | if (!hrq || !drq || !cq) |
| 16078 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16079 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16080 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16081 | |
| 16082 | if (hrq->entry_count != drq->entry_count) |
| 16083 | return -EINVAL; |
| 16084 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16085 | if (!mbox) |
| 16086 | return -ENOMEM; |
| 16087 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 16088 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16089 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16090 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 16091 | length, LPFC_SLI4_MBX_EMBED); |
| 16092 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16093 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 16094 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16095 | phba->sli4_hba.pc_sli4_params.rqv); |
| 16096 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 16097 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16098 | &rq_create->u.request.context, |
| 16099 | hrq->entry_count); |
| 16100 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16101 | bf_set(lpfc_rq_context_rqe_size, |
| 16102 | &rq_create->u.request.context, |
| 16103 | LPFC_RQE_SIZE_8); |
| 16104 | bf_set(lpfc_rq_context_page_size, |
| 16105 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 16106 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16107 | } else { |
| 16108 | switch (hrq->entry_count) { |
| 16109 | default: |
| 16110 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16111 | "2535 Unsupported RQ count. (%d)\n", |
| 16112 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16113 | if (hrq->entry_count < 512) { |
| 16114 | status = -EINVAL; |
| 16115 | goto out; |
| 16116 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 16117 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16118 | case 512: |
| 16119 | bf_set(lpfc_rq_context_rqe_count, |
| 16120 | &rq_create->u.request.context, |
| 16121 | LPFC_RQ_RING_SIZE_512); |
| 16122 | break; |
| 16123 | case 1024: |
| 16124 | bf_set(lpfc_rq_context_rqe_count, |
| 16125 | &rq_create->u.request.context, |
| 16126 | LPFC_RQ_RING_SIZE_1024); |
| 16127 | break; |
| 16128 | case 2048: |
| 16129 | bf_set(lpfc_rq_context_rqe_count, |
| 16130 | &rq_create->u.request.context, |
| 16131 | LPFC_RQ_RING_SIZE_2048); |
| 16132 | break; |
| 16133 | case 4096: |
| 16134 | bf_set(lpfc_rq_context_rqe_count, |
| 16135 | &rq_create->u.request.context, |
| 16136 | LPFC_RQ_RING_SIZE_4096); |
| 16137 | break; |
| 16138 | } |
| 16139 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 16140 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16141 | } |
| 16142 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 16143 | cq->queue_id); |
| 16144 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 16145 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16146 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16147 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16148 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16149 | putPaddrLow(dmabuf->phys); |
| 16150 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16151 | putPaddrHigh(dmabuf->phys); |
| 16152 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16153 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16154 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 16155 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16156 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16157 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16158 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16159 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16160 | if (shdr_status || shdr_add_status || rc) { |
| 16161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16162 | "2504 RQ_CREATE mailbox failed with " |
| 16163 | "status x%x add_status x%x, mbx status x%x\n", |
| 16164 | shdr_status, shdr_add_status, rc); |
| 16165 | status = -ENXIO; |
| 16166 | goto out; |
| 16167 | } |
| 16168 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16169 | if (hrq->queue_id == 0xFFFF) { |
| 16170 | status = -ENXIO; |
| 16171 | goto out; |
| 16172 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16173 | |
| 16174 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 16175 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 16176 | &rq_create->u.response); |
| 16177 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 16178 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 16179 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16180 | "3262 RQ [%d] doorbell format not " |
| 16181 | "supported: x%x\n", hrq->queue_id, |
| 16182 | hrq->db_format); |
| 16183 | status = -EINVAL; |
| 16184 | goto out; |
| 16185 | } |
| 16186 | |
| 16187 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 16188 | &rq_create->u.response); |
| 16189 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 16190 | if (!bar_memmap_p) { |
| 16191 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16192 | "3269 RQ[%d] failed to memmap pci " |
| 16193 | "barset:x%x\n", hrq->queue_id, |
| 16194 | pci_barset); |
| 16195 | status = -ENOMEM; |
| 16196 | goto out; |
| 16197 | } |
| 16198 | |
| 16199 | db_offset = rq_create->u.response.doorbell_offset; |
| 16200 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 16201 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 16202 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16203 | "3270 RQ[%d] doorbell offset not " |
| 16204 | "supported: x%x\n", hrq->queue_id, |
| 16205 | db_offset); |
| 16206 | status = -EINVAL; |
| 16207 | goto out; |
| 16208 | } |
| 16209 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 16210 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 16211 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 16212 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 16213 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16214 | } else { |
| 16215 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16216 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16217 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16218 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16219 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16220 | hrq->subtype = subtype; |
| 16221 | hrq->host_index = 0; |
| 16222 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16223 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16224 | |
| 16225 | /* now create the data queue */ |
| 16226 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16227 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 16228 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16229 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16230 | phba->sli4_hba.pc_sli4_params.rqv); |
| 16231 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 16232 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16233 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16234 | if (subtype == LPFC_NVMET) |
| 16235 | rq_create->u.request.context.buffer_size = |
| 16236 | LPFC_NVMET_DATA_BUF_SIZE; |
| 16237 | else |
| 16238 | rq_create->u.request.context.buffer_size = |
| 16239 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16240 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 16241 | LPFC_RQE_SIZE_8); |
| 16242 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 16243 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16244 | } else { |
| 16245 | switch (drq->entry_count) { |
| 16246 | default: |
| 16247 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16248 | "2536 Unsupported RQ count. (%d)\n", |
| 16249 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16250 | if (drq->entry_count < 512) { |
| 16251 | status = -EINVAL; |
| 16252 | goto out; |
| 16253 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 16254 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16255 | case 512: |
| 16256 | bf_set(lpfc_rq_context_rqe_count, |
| 16257 | &rq_create->u.request.context, |
| 16258 | LPFC_RQ_RING_SIZE_512); |
| 16259 | break; |
| 16260 | case 1024: |
| 16261 | bf_set(lpfc_rq_context_rqe_count, |
| 16262 | &rq_create->u.request.context, |
| 16263 | LPFC_RQ_RING_SIZE_1024); |
| 16264 | break; |
| 16265 | case 2048: |
| 16266 | bf_set(lpfc_rq_context_rqe_count, |
| 16267 | &rq_create->u.request.context, |
| 16268 | LPFC_RQ_RING_SIZE_2048); |
| 16269 | break; |
| 16270 | case 4096: |
| 16271 | bf_set(lpfc_rq_context_rqe_count, |
| 16272 | &rq_create->u.request.context, |
| 16273 | LPFC_RQ_RING_SIZE_4096); |
| 16274 | break; |
| 16275 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16276 | if (subtype == LPFC_NVMET) |
| 16277 | bf_set(lpfc_rq_context_buf_size, |
| 16278 | &rq_create->u.request.context, |
| 16279 | LPFC_NVMET_DATA_BUF_SIZE); |
| 16280 | else |
| 16281 | bf_set(lpfc_rq_context_buf_size, |
| 16282 | &rq_create->u.request.context, |
| 16283 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16284 | } |
| 16285 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 16286 | cq->queue_id); |
| 16287 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 16288 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16289 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16290 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16291 | putPaddrLow(dmabuf->phys); |
| 16292 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16293 | putPaddrHigh(dmabuf->phys); |
| 16294 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16295 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16296 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16297 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16298 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16299 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 16300 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16301 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16302 | if (shdr_status || shdr_add_status || rc) { |
| 16303 | status = -ENXIO; |
| 16304 | goto out; |
| 16305 | } |
| 16306 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16307 | if (drq->queue_id == 0xFFFF) { |
| 16308 | status = -ENXIO; |
| 16309 | goto out; |
| 16310 | } |
| 16311 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16312 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16313 | drq->subtype = subtype; |
| 16314 | drq->host_index = 0; |
| 16315 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16316 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16317 | |
| 16318 | /* link the header and data RQs onto the parent cq child list */ |
| 16319 | list_add_tail(&hrq->list, &cq->child_list); |
| 16320 | list_add_tail(&drq->list, &cq->child_list); |
| 16321 | |
| 16322 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16323 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16324 | return status; |
| 16325 | } |
| 16326 | |
| 16327 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16328 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 16329 | * @phba: HBA structure that indicates port to create a queue on. |
| 16330 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 16331 | * @drqp: The queue structure array to use to create the data receive queues. |
| 16332 | * @cqp: The completion queue array to bind these receive queues to. |
| 16333 | * |
| 16334 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 16335 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 16336 | * to the HBA. |
| 16337 | * |
| 16338 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 16339 | * struct is used to get the entry count that is necessary to determine the |
| 16340 | * number of pages to use for this queue. The @cq is used to indicate which |
| 16341 | * completion queue to bind received buffers that are posted to these queues to. |
| 16342 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 16343 | * receive queue pair. This function is asynchronous and will wait for the |
| 16344 | * mailbox command to finish before continuing. |
| 16345 | * |
| 16346 | * On success this function will return a zero. If unable to allocate enough |
| 16347 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16348 | * fails this function will return -ENXIO. |
| 16349 | **/ |
| 16350 | int |
| 16351 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 16352 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 16353 | uint32_t subtype) |
| 16354 | { |
| 16355 | struct lpfc_queue *hrq, *drq, *cq; |
| 16356 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 16357 | struct lpfc_dmabuf *dmabuf; |
| 16358 | LPFC_MBOXQ_t *mbox; |
| 16359 | int rc, length, alloclen, status = 0; |
| 16360 | int cnt, idx, numrq, page_idx = 0; |
| 16361 | uint32_t shdr_status, shdr_add_status; |
| 16362 | union lpfc_sli4_cfg_shdr *shdr; |
| 16363 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 16364 | |
| 16365 | numrq = phba->cfg_nvmet_mrq; |
| 16366 | /* sanity check on array memory */ |
| 16367 | if (!hrqp || !drqp || !cqp || !numrq) |
| 16368 | return -ENODEV; |
| 16369 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16370 | hw_page_size = SLI4_PAGE_SIZE; |
| 16371 | |
| 16372 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16373 | if (!mbox) |
| 16374 | return -ENOMEM; |
| 16375 | |
| 16376 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 16377 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 16378 | sizeof(struct dma_address)); |
| 16379 | |
| 16380 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16381 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 16382 | LPFC_SLI4_MBX_NEMBED); |
| 16383 | if (alloclen < length) { |
| 16384 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16385 | "3099 Allocated DMA memory size (%d) is " |
| 16386 | "less than the requested DMA memory size " |
| 16387 | "(%d)\n", alloclen, length); |
| 16388 | status = -ENOMEM; |
| 16389 | goto out; |
| 16390 | } |
| 16391 | |
| 16392 | |
| 16393 | |
| 16394 | rq_create = mbox->sge_array->addr[0]; |
| 16395 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 16396 | |
| 16397 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 16398 | cnt = 0; |
| 16399 | |
| 16400 | for (idx = 0; idx < numrq; idx++) { |
| 16401 | hrq = hrqp[idx]; |
| 16402 | drq = drqp[idx]; |
| 16403 | cq = cqp[idx]; |
| 16404 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16405 | /* sanity check on queue memory */ |
| 16406 | if (!hrq || !drq || !cq) { |
| 16407 | status = -ENODEV; |
| 16408 | goto out; |
| 16409 | } |
| 16410 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 16411 | if (hrq->entry_count != drq->entry_count) { |
| 16412 | status = -EINVAL; |
| 16413 | goto out; |
| 16414 | } |
| 16415 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16416 | if (idx == 0) { |
| 16417 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 16418 | &rq_create->u.request, |
| 16419 | hrq->page_count); |
| 16420 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 16421 | &rq_create->u.request, (numrq * 2)); |
| 16422 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 16423 | 1); |
| 16424 | bf_set(lpfc_rq_context_base_cq, |
| 16425 | &rq_create->u.request.context, |
| 16426 | cq->queue_id); |
| 16427 | bf_set(lpfc_rq_context_data_size, |
| 16428 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16429 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16430 | bf_set(lpfc_rq_context_hdr_size, |
| 16431 | &rq_create->u.request.context, |
| 16432 | LPFC_HDR_BUF_SIZE); |
| 16433 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16434 | &rq_create->u.request.context, |
| 16435 | hrq->entry_count); |
| 16436 | bf_set(lpfc_rq_context_rqe_size, |
| 16437 | &rq_create->u.request.context, |
| 16438 | LPFC_RQE_SIZE_8); |
| 16439 | bf_set(lpfc_rq_context_page_size, |
| 16440 | &rq_create->u.request.context, |
| 16441 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 16442 | } |
| 16443 | rc = 0; |
| 16444 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 16445 | memset(dmabuf->virt, 0, hw_page_size); |
| 16446 | cnt = page_idx + dmabuf->buffer_tag; |
| 16447 | rq_create->u.request.page[cnt].addr_lo = |
| 16448 | putPaddrLow(dmabuf->phys); |
| 16449 | rq_create->u.request.page[cnt].addr_hi = |
| 16450 | putPaddrHigh(dmabuf->phys); |
| 16451 | rc++; |
| 16452 | } |
| 16453 | page_idx += rc; |
| 16454 | |
| 16455 | rc = 0; |
| 16456 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16457 | memset(dmabuf->virt, 0, hw_page_size); |
| 16458 | cnt = page_idx + dmabuf->buffer_tag; |
| 16459 | rq_create->u.request.page[cnt].addr_lo = |
| 16460 | putPaddrLow(dmabuf->phys); |
| 16461 | rq_create->u.request.page[cnt].addr_hi = |
| 16462 | putPaddrHigh(dmabuf->phys); |
| 16463 | rc++; |
| 16464 | } |
| 16465 | page_idx += rc; |
| 16466 | |
| 16467 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16468 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16469 | hrq->type = LPFC_HRQ; |
| 16470 | hrq->assoc_qid = cq->queue_id; |
| 16471 | hrq->subtype = subtype; |
| 16472 | hrq->host_index = 0; |
| 16473 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16474 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16475 | |
| 16476 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 16477 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16478 | drq->type = LPFC_DRQ; |
| 16479 | drq->assoc_qid = cq->queue_id; |
| 16480 | drq->subtype = subtype; |
| 16481 | drq->host_index = 0; |
| 16482 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16483 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16484 | |
| 16485 | list_add_tail(&hrq->list, &cq->child_list); |
| 16486 | list_add_tail(&drq->list, &cq->child_list); |
| 16487 | } |
| 16488 | |
| 16489 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16490 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16491 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16492 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16493 | if (shdr_status || shdr_add_status || rc) { |
| 16494 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16495 | "3120 RQ_CREATE mailbox failed with " |
| 16496 | "status x%x add_status x%x, mbx status x%x\n", |
| 16497 | shdr_status, shdr_add_status, rc); |
| 16498 | status = -ENXIO; |
| 16499 | goto out; |
| 16500 | } |
| 16501 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16502 | if (rc == 0xFFFF) { |
| 16503 | status = -ENXIO; |
| 16504 | goto out; |
| 16505 | } |
| 16506 | |
| 16507 | /* Initialize all RQs with associated queue id */ |
| 16508 | for (idx = 0; idx < numrq; idx++) { |
| 16509 | hrq = hrqp[idx]; |
| 16510 | hrq->queue_id = rc + (2 * idx); |
| 16511 | drq = drqp[idx]; |
| 16512 | drq->queue_id = rc + (2 * idx) + 1; |
| 16513 | } |
| 16514 | |
| 16515 | out: |
| 16516 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16517 | return status; |
| 16518 | } |
| 16519 | |
| 16520 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16521 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 16522 | * @eq: The queue structure associated with the queue to destroy. |
| 16523 | * |
| 16524 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16525 | * command, specific to the type of queue, to the HBA. |
| 16526 | * |
| 16527 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16528 | * |
| 16529 | * 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] | 16530 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16531 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16532 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16533 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16534 | { |
| 16535 | LPFC_MBOXQ_t *mbox; |
| 16536 | int rc, length, status = 0; |
| 16537 | uint32_t shdr_status, shdr_add_status; |
| 16538 | union lpfc_sli4_cfg_shdr *shdr; |
| 16539 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16540 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16541 | if (!eq) |
| 16542 | return -ENODEV; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16543 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16544 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16545 | if (!mbox) |
| 16546 | return -ENOMEM; |
| 16547 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16548 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16549 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16550 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16551 | length, LPFC_SLI4_MBX_EMBED); |
| 16552 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16553 | eq->queue_id); |
| 16554 | mbox->vport = eq->phba->pport; |
| 16555 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16556 | |
| 16557 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16558 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16559 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16560 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16561 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16562 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16563 | if (shdr_status || shdr_add_status || rc) { |
| 16564 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16565 | "2505 EQ_DESTROY mailbox failed with " |
| 16566 | "status x%x add_status x%x, mbx status x%x\n", |
| 16567 | shdr_status, shdr_add_status, rc); |
| 16568 | status = -ENXIO; |
| 16569 | } |
| 16570 | |
| 16571 | /* Remove eq from any list */ |
| 16572 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16573 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16574 | return status; |
| 16575 | } |
| 16576 | |
| 16577 | /** |
| 16578 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 16579 | * @cq: The queue structure associated with the queue to destroy. |
| 16580 | * |
| 16581 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16582 | * command, specific to the type of queue, to the HBA. |
| 16583 | * |
| 16584 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16585 | * |
| 16586 | * 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] | 16587 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16588 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16589 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16590 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16591 | { |
| 16592 | LPFC_MBOXQ_t *mbox; |
| 16593 | int rc, length, status = 0; |
| 16594 | uint32_t shdr_status, shdr_add_status; |
| 16595 | union lpfc_sli4_cfg_shdr *shdr; |
| 16596 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16597 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16598 | if (!cq) |
| 16599 | return -ENODEV; |
| 16600 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16601 | if (!mbox) |
| 16602 | return -ENOMEM; |
| 16603 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16604 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16605 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16606 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16607 | length, LPFC_SLI4_MBX_EMBED); |
| 16608 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16609 | cq->queue_id); |
| 16610 | mbox->vport = cq->phba->pport; |
| 16611 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16612 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16613 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16614 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16615 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16616 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16617 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16618 | if (shdr_status || shdr_add_status || rc) { |
| 16619 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16620 | "2506 CQ_DESTROY mailbox failed with " |
| 16621 | "status x%x add_status x%x, mbx status x%x\n", |
| 16622 | shdr_status, shdr_add_status, rc); |
| 16623 | status = -ENXIO; |
| 16624 | } |
| 16625 | /* Remove cq from any list */ |
| 16626 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16627 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16628 | return status; |
| 16629 | } |
| 16630 | |
| 16631 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16632 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 16633 | * @qm: The queue structure associated with the queue to destroy. |
| 16634 | * |
| 16635 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16636 | * command, specific to the type of queue, to the HBA. |
| 16637 | * |
| 16638 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16639 | * |
| 16640 | * 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] | 16641 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16642 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16643 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16644 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16645 | { |
| 16646 | LPFC_MBOXQ_t *mbox; |
| 16647 | int rc, length, status = 0; |
| 16648 | uint32_t shdr_status, shdr_add_status; |
| 16649 | union lpfc_sli4_cfg_shdr *shdr; |
| 16650 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16651 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16652 | if (!mq) |
| 16653 | return -ENODEV; |
| 16654 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16655 | if (!mbox) |
| 16656 | return -ENOMEM; |
| 16657 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16658 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16659 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16660 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16661 | length, LPFC_SLI4_MBX_EMBED); |
| 16662 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16663 | mq->queue_id); |
| 16664 | mbox->vport = mq->phba->pport; |
| 16665 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16666 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16667 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16668 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16669 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16670 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16671 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16672 | if (shdr_status || shdr_add_status || rc) { |
| 16673 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16674 | "2507 MQ_DESTROY mailbox failed with " |
| 16675 | "status x%x add_status x%x, mbx status x%x\n", |
| 16676 | shdr_status, shdr_add_status, rc); |
| 16677 | status = -ENXIO; |
| 16678 | } |
| 16679 | /* Remove mq from any list */ |
| 16680 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16681 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16682 | return status; |
| 16683 | } |
| 16684 | |
| 16685 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16686 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16687 | * @wq: The queue structure associated with the queue to destroy. |
| 16688 | * |
| 16689 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16690 | * command, specific to the type of queue, to the HBA. |
| 16691 | * |
| 16692 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16693 | * |
| 16694 | * 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] | 16695 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16696 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16697 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16698 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16699 | { |
| 16700 | LPFC_MBOXQ_t *mbox; |
| 16701 | int rc, length, status = 0; |
| 16702 | uint32_t shdr_status, shdr_add_status; |
| 16703 | union lpfc_sli4_cfg_shdr *shdr; |
| 16704 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16705 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16706 | if (!wq) |
| 16707 | return -ENODEV; |
| 16708 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16709 | if (!mbox) |
| 16710 | return -ENOMEM; |
| 16711 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16712 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16713 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16714 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16715 | length, LPFC_SLI4_MBX_EMBED); |
| 16716 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16717 | wq->queue_id); |
| 16718 | mbox->vport = wq->phba->pport; |
| 16719 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16720 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16721 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16722 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16723 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16724 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16725 | if (shdr_status || shdr_add_status || rc) { |
| 16726 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16727 | "2508 WQ_DESTROY mailbox failed with " |
| 16728 | "status x%x add_status x%x, mbx status x%x\n", |
| 16729 | shdr_status, shdr_add_status, rc); |
| 16730 | status = -ENXIO; |
| 16731 | } |
| 16732 | /* Remove wq from any list */ |
| 16733 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16734 | kfree(wq->pring); |
| 16735 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16736 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16737 | return status; |
| 16738 | } |
| 16739 | |
| 16740 | /** |
| 16741 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16742 | * @rq: The queue structure associated with the queue to destroy. |
| 16743 | * |
| 16744 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16745 | * command, specific to the type of queue, to the HBA. |
| 16746 | * |
| 16747 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16748 | * |
| 16749 | * 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] | 16750 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16751 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16752 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16753 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16754 | struct lpfc_queue *drq) |
| 16755 | { |
| 16756 | LPFC_MBOXQ_t *mbox; |
| 16757 | int rc, length, status = 0; |
| 16758 | uint32_t shdr_status, shdr_add_status; |
| 16759 | union lpfc_sli4_cfg_shdr *shdr; |
| 16760 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16761 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16762 | if (!hrq || !drq) |
| 16763 | return -ENODEV; |
| 16764 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16765 | if (!mbox) |
| 16766 | return -ENOMEM; |
| 16767 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16768 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16769 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16770 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16771 | length, LPFC_SLI4_MBX_EMBED); |
| 16772 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16773 | hrq->queue_id); |
| 16774 | mbox->vport = hrq->phba->pport; |
| 16775 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16776 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16777 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16778 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16779 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16780 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16781 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16782 | if (shdr_status || shdr_add_status || rc) { |
| 16783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16784 | "2509 RQ_DESTROY mailbox failed with " |
| 16785 | "status x%x add_status x%x, mbx status x%x\n", |
| 16786 | shdr_status, shdr_add_status, rc); |
| 16787 | if (rc != MBX_TIMEOUT) |
| 16788 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16789 | return -ENXIO; |
| 16790 | } |
| 16791 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16792 | drq->queue_id); |
| 16793 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16794 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16795 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16796 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16797 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16798 | if (shdr_status || shdr_add_status || rc) { |
| 16799 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16800 | "2510 RQ_DESTROY mailbox failed with " |
| 16801 | "status x%x add_status x%x, mbx status x%x\n", |
| 16802 | shdr_status, shdr_add_status, rc); |
| 16803 | status = -ENXIO; |
| 16804 | } |
| 16805 | list_del_init(&hrq->list); |
| 16806 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16807 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16808 | return status; |
| 16809 | } |
| 16810 | |
| 16811 | /** |
| 16812 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16813 | * @phba: The virtual port for which this call being executed. |
| 16814 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16815 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16816 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16817 | * |
| 16818 | * This routine will post the sgl pages for the IO that has the xritag |
| 16819 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16820 | * creation and persists for as long as the driver is loaded. |
| 16821 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16822 | * pdma_phys_addr1 should be 0. |
| 16823 | * If the caller needs to map more than 256 scatter gather segment then |
| 16824 | * pdma_phys_addr1 should be a valid physical address. |
| 16825 | * physical address for SGLs must be 64 byte aligned. |
| 16826 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16827 | * the second sgl can have between 1 and 256 entries. |
| 16828 | * |
| 16829 | * Return codes: |
| 16830 | * 0 - Success |
| 16831 | * -ENXIO, -ENOMEM - Failure |
| 16832 | **/ |
| 16833 | int |
| 16834 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16835 | dma_addr_t pdma_phys_addr0, |
| 16836 | dma_addr_t pdma_phys_addr1, |
| 16837 | uint16_t xritag) |
| 16838 | { |
| 16839 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16840 | LPFC_MBOXQ_t *mbox; |
| 16841 | int rc; |
| 16842 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16843 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16844 | union lpfc_sli4_cfg_shdr *shdr; |
| 16845 | |
| 16846 | if (xritag == NO_XRI) { |
| 16847 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16848 | "0364 Invalid param:\n"); |
| 16849 | return -EINVAL; |
| 16850 | } |
| 16851 | |
| 16852 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16853 | if (!mbox) |
| 16854 | return -ENOMEM; |
| 16855 | |
| 16856 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16857 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16858 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16859 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16860 | |
| 16861 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16862 | &mbox->u.mqe.un.post_sgl_pages; |
| 16863 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16864 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16865 | |
| 16866 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16867 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16868 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16869 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16870 | |
| 16871 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16872 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16873 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16874 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16875 | if (!phba->sli4_hba.intr_enable) |
| 16876 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16877 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16878 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16879 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16880 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16881 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16882 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16883 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16884 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16885 | if (rc != MBX_TIMEOUT) |
| 16886 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16887 | if (shdr_status || shdr_add_status || rc) { |
| 16888 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16889 | "2511 POST_SGL mailbox failed with " |
| 16890 | "status x%x add_status x%x, mbx status x%x\n", |
| 16891 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16892 | } |
| 16893 | return 0; |
| 16894 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16895 | |
| 16896 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16897 | * 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] | 16898 | * @phba: pointer to lpfc hba data structure. |
| 16899 | * |
| 16900 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16901 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16902 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16903 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16904 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16905 | * Returns |
| 16906 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16907 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16908 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16909 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16910 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16911 | { |
| 16912 | unsigned long xri; |
| 16913 | |
| 16914 | /* |
| 16915 | * Fetch the next logical xri. Because this index is logical, |
| 16916 | * the driver starts at 0 each time. |
| 16917 | */ |
| 16918 | spin_lock_irq(&phba->hbalock); |
| 16919 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16920 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16921 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16922 | spin_unlock_irq(&phba->hbalock); |
| 16923 | return NO_XRI; |
| 16924 | } else { |
| 16925 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16926 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16927 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16928 | spin_unlock_irq(&phba->hbalock); |
| 16929 | return xri; |
| 16930 | } |
| 16931 | |
| 16932 | /** |
| 16933 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16934 | * @phba: pointer to lpfc hba data structure. |
| 16935 | * |
| 16936 | * This routine is invoked to release an xri to the pool of |
| 16937 | * available rpis maintained by the driver. |
| 16938 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16939 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16940 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16941 | { |
| 16942 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16943 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16944 | } |
| 16945 | } |
| 16946 | |
| 16947 | /** |
| 16948 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16949 | * @phba: pointer to lpfc hba data structure. |
| 16950 | * |
| 16951 | * This routine is invoked to release an xri to the pool of |
| 16952 | * available rpis maintained by the driver. |
| 16953 | **/ |
| 16954 | void |
| 16955 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16956 | { |
| 16957 | spin_lock_irq(&phba->hbalock); |
| 16958 | __lpfc_sli4_free_xri(phba, xri); |
| 16959 | spin_unlock_irq(&phba->hbalock); |
| 16960 | } |
| 16961 | |
| 16962 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16963 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16964 | * @phba: Pointer to HBA context object. |
| 16965 | * |
| 16966 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16967 | * it will return 0xffff. |
| 16968 | * The function returns the allocated xritag if successful, else returns zero. |
| 16969 | * Zero is not a valid xritag. |
| 16970 | * The caller is not required to hold any lock. |
| 16971 | **/ |
| 16972 | uint16_t |
| 16973 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16974 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16975 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16976 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16977 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16978 | if (xri_index == NO_XRI) |
| 16979 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16980 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16981 | " Max XRI is %d, Used XRI is %d\n", |
| 16982 | xri_index, |
| 16983 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16984 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16985 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16986 | } |
| 16987 | |
| 16988 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16989 | * 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] | 16990 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16991 | * @post_sgl_list: pointer to els sgl entry list. |
| 16992 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16993 | * |
| 16994 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16995 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16996 | * is only called when the driver is loading and after all IO has been |
| 16997 | * stopped. |
| 16998 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16999 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17000 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17001 | struct list_head *post_sgl_list, |
| 17002 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17003 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17004 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17005 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 17006 | struct sgl_page_pairs *sgl_pg_pairs; |
| 17007 | void *viraddr; |
| 17008 | LPFC_MBOXQ_t *mbox; |
| 17009 | uint32_t reqlen, alloclen, pg_pairs; |
| 17010 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17011 | uint16_t xritag_start = 0; |
| 17012 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17013 | uint32_t shdr_status, shdr_add_status; |
| 17014 | union lpfc_sli4_cfg_shdr *shdr; |
| 17015 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17016 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17017 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17018 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17019 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17020 | "2559 Block sgl registration required DMA " |
| 17021 | "size (%d) great than a page\n", reqlen); |
| 17022 | return -ENOMEM; |
| 17023 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17024 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17025 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17026 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17027 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17028 | |
| 17029 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 17030 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17031 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 17032 | LPFC_SLI4_MBX_NEMBED); |
| 17033 | |
| 17034 | if (alloclen < reqlen) { |
| 17035 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17036 | "0285 Allocated DMA memory size (%d) is " |
| 17037 | "less than the requested DMA memory " |
| 17038 | "size (%d)\n", alloclen, reqlen); |
| 17039 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17040 | return -ENOMEM; |
| 17041 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17042 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17043 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17044 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 17045 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 17046 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17047 | pg_pairs = 0; |
| 17048 | 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] | 17049 | /* Set up the sge entry */ |
| 17050 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 17051 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 17052 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 17053 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 17054 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 17055 | cpu_to_le32(putPaddrLow(0)); |
| 17056 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 17057 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17058 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17059 | /* Keep the first xritag on the list */ |
| 17060 | if (pg_pairs == 0) |
| 17061 | xritag_start = sglq_entry->sli4_xritag; |
| 17062 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17063 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17064 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17065 | |
| 17066 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17067 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17068 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17069 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17070 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17071 | if (!phba->sli4_hba.intr_enable) |
| 17072 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 17073 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17074 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17075 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17076 | } |
| 17077 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 17078 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17079 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17080 | if (rc != MBX_TIMEOUT) |
| 17081 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17082 | if (shdr_status || shdr_add_status || rc) { |
| 17083 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17084 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 17085 | "status x%x add_status x%x mbx status x%x\n", |
| 17086 | shdr_status, shdr_add_status, rc); |
| 17087 | rc = -ENXIO; |
| 17088 | } |
| 17089 | return rc; |
| 17090 | } |
| 17091 | |
| 17092 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17093 | * 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] | 17094 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17095 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17096 | * @count: number of scsi buffers on the list. |
| 17097 | * |
| 17098 | * 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] | 17099 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17100 | * No Lock is held. |
| 17101 | * |
| 17102 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17103 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17104 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 17105 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17106 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17107 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17108 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 17109 | struct sgl_page_pairs *sgl_pg_pairs; |
| 17110 | void *viraddr; |
| 17111 | LPFC_MBOXQ_t *mbox; |
| 17112 | uint32_t reqlen, alloclen, pg_pairs; |
| 17113 | uint32_t mbox_tmo; |
| 17114 | uint16_t xritag_start = 0; |
| 17115 | int rc = 0; |
| 17116 | uint32_t shdr_status, shdr_add_status; |
| 17117 | dma_addr_t pdma_phys_bpl1; |
| 17118 | union lpfc_sli4_cfg_shdr *shdr; |
| 17119 | |
| 17120 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17121 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17122 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17123 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17124 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17125 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17126 | "size (%d) great than a page\n", reqlen); |
| 17127 | return -ENOMEM; |
| 17128 | } |
| 17129 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17130 | if (!mbox) { |
| 17131 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17132 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17133 | return -ENOMEM; |
| 17134 | } |
| 17135 | |
| 17136 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 17137 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17138 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 17139 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17140 | |
| 17141 | if (alloclen < reqlen) { |
| 17142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17143 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17144 | "less than the requested DMA memory " |
| 17145 | "size (%d)\n", alloclen, reqlen); |
| 17146 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17147 | return -ENOMEM; |
| 17148 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17149 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17150 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17151 | viraddr = mbox->sge_array->addr[0]; |
| 17152 | |
| 17153 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 17154 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 17155 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 17156 | |
| 17157 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17158 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17159 | /* Set up the sge entry */ |
| 17160 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17161 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17162 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17163 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17164 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17165 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 17166 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17167 | else |
| 17168 | pdma_phys_bpl1 = 0; |
| 17169 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 17170 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 17171 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 17172 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 17173 | /* Keep the first xritag on the list */ |
| 17174 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17175 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17176 | sgl_pg_pairs++; |
| 17177 | pg_pairs++; |
| 17178 | } |
| 17179 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 17180 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 17181 | /* Perform endian conversion if necessary */ |
| 17182 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 17183 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17184 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17185 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17186 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17187 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17188 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17189 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17190 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17191 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17192 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17193 | if (rc != MBX_TIMEOUT) |
| 17194 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17195 | if (shdr_status || shdr_add_status || rc) { |
| 17196 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17197 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17198 | "status x%x add_status x%x mbx status x%x\n", |
| 17199 | shdr_status, shdr_add_status, rc); |
| 17200 | rc = -ENXIO; |
| 17201 | } |
| 17202 | return rc; |
| 17203 | } |
| 17204 | |
| 17205 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17206 | * 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] | 17207 | * @phba: pointer to lpfc hba data structure. |
| 17208 | * @post_nblist: pointer to the nvme buffer list. |
| 17209 | * |
| 17210 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 17211 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 17212 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 17213 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 17214 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 17215 | * must be local list, thus no lock is needed when manipulate the list. |
| 17216 | * |
| 17217 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 17218 | **/ |
| 17219 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17220 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 17221 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17222 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17223 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17224 | int status, sgl_size; |
| 17225 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 17226 | dma_addr_t pdma_phys_sgl1; |
| 17227 | int last_xritag = NO_XRI; |
| 17228 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17229 | LIST_HEAD(prep_nblist); |
| 17230 | LIST_HEAD(blck_nblist); |
| 17231 | LIST_HEAD(nvme_nblist); |
| 17232 | |
| 17233 | /* sanity check */ |
| 17234 | if (sb_count <= 0) |
| 17235 | return -EINVAL; |
| 17236 | |
| 17237 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 17238 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 17239 | list_del_init(&lpfc_ncmd->list); |
| 17240 | block_cnt++; |
| 17241 | if ((last_xritag != NO_XRI) && |
| 17242 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 17243 | /* a hole in xri block, form a sgl posting block */ |
| 17244 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17245 | post_cnt = block_cnt - 1; |
| 17246 | /* prepare list for next posting block */ |
| 17247 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 17248 | block_cnt = 1; |
| 17249 | } else { |
| 17250 | /* prepare list for next posting block */ |
| 17251 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 17252 | /* enough sgls for non-embed sgl mbox command */ |
| 17253 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 17254 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17255 | post_cnt = block_cnt; |
| 17256 | block_cnt = 0; |
| 17257 | } |
| 17258 | } |
| 17259 | num_posting++; |
| 17260 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 17261 | |
| 17262 | /* end of repost sgl list condition for NVME buffers */ |
| 17263 | if (num_posting == sb_count) { |
| 17264 | if (post_cnt == 0) { |
| 17265 | /* last sgl posting block */ |
| 17266 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17267 | post_cnt = block_cnt; |
| 17268 | } else if (block_cnt == 1) { |
| 17269 | /* last single sgl with non-contiguous xri */ |
| 17270 | if (sgl_size > SGL_PAGE_SIZE) |
| 17271 | pdma_phys_sgl1 = |
| 17272 | lpfc_ncmd->dma_phys_sgl + |
| 17273 | SGL_PAGE_SIZE; |
| 17274 | else |
| 17275 | pdma_phys_sgl1 = 0; |
| 17276 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 17277 | status = lpfc_sli4_post_sgl( |
| 17278 | phba, lpfc_ncmd->dma_phys_sgl, |
| 17279 | pdma_phys_sgl1, cur_xritag); |
| 17280 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17281 | /* Post error. Buffer unavailable. */ |
| 17282 | lpfc_ncmd->flags |= |
| 17283 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17284 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17285 | /* Post success. Bffer available. */ |
| 17286 | lpfc_ncmd->flags &= |
| 17287 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17288 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 17289 | num_posted++; |
| 17290 | } |
| 17291 | /* success, put on NVME buffer sgl list */ |
| 17292 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 17293 | } |
| 17294 | } |
| 17295 | |
| 17296 | /* continue until a nembed page worth of sgls */ |
| 17297 | if (post_cnt == 0) |
| 17298 | continue; |
| 17299 | |
| 17300 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17301 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 17302 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17303 | |
| 17304 | /* don't reset xirtag due to hole in xri block */ |
| 17305 | if (block_cnt == 0) |
| 17306 | last_xritag = NO_XRI; |
| 17307 | |
| 17308 | /* reset NVME buffer post count for next round of posting */ |
| 17309 | post_cnt = 0; |
| 17310 | |
| 17311 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 17312 | while (!list_empty(&blck_nblist)) { |
| 17313 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17314 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17315 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17316 | /* Post error. Mark buffer unavailable. */ |
| 17317 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17318 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17319 | /* Post success, Mark buffer available. */ |
| 17320 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17321 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 17322 | num_posted++; |
| 17323 | } |
| 17324 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 17325 | } |
| 17326 | } |
| 17327 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17328 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 17329 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17330 | return num_posted; |
| 17331 | } |
| 17332 | |
| 17333 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17334 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 17335 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 17336 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17337 | * |
| 17338 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 17339 | * valid type of frame that the LPFC driver will handle. This function will |
| 17340 | * return a zero if the frame is a valid frame or a non zero value when the |
| 17341 | * frame does not pass the check. |
| 17342 | **/ |
| 17343 | static int |
| 17344 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 17345 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 17346 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17347 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17348 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17349 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 17350 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 17351 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17352 | switch (fc_hdr->fh_r_ctl) { |
| 17353 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 17354 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 17355 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 17356 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 17357 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 17358 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 17359 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 17360 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 17361 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 17362 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 17363 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 17364 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 17365 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 17366 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 17367 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 17368 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 17369 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 17370 | case FC_RCTL_BA_PRMT: |
| 17371 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 17372 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 17373 | case FC_RCTL_P_RJT: /* port reject */ |
| 17374 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 17375 | case FC_RCTL_P_BSY: /* port busy */ |
| 17376 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 17377 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 17378 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17379 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17380 | case FC_RCTL_END: /* end */ |
| 17381 | break; |
| 17382 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 17383 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17384 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 17385 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 17386 | default: |
| 17387 | goto drop; |
| 17388 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17389 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17390 | switch (fc_hdr->fh_type) { |
| 17391 | case FC_TYPE_BLS: |
| 17392 | case FC_TYPE_ELS: |
| 17393 | case FC_TYPE_FCP: |
| 17394 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17395 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17396 | break; |
| 17397 | case FC_TYPE_IP: |
| 17398 | case FC_TYPE_ILS: |
| 17399 | default: |
| 17400 | goto drop; |
| 17401 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17402 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17403 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17404 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 17405 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17406 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 17407 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 17408 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 17409 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 17410 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17411 | return 0; |
| 17412 | drop: |
| 17413 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17414 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 17415 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17416 | return 1; |
| 17417 | } |
| 17418 | |
| 17419 | /** |
| 17420 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 17421 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17422 | * |
| 17423 | * This function processes the FC header to retrieve the VFI from the VF |
| 17424 | * header, if one exists. This function will return the VFI if one exists |
| 17425 | * or 0 if no VSAN Header exists. |
| 17426 | **/ |
| 17427 | static uint32_t |
| 17428 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 17429 | { |
| 17430 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17431 | |
| 17432 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 17433 | return 0; |
| 17434 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 17435 | } |
| 17436 | |
| 17437 | /** |
| 17438 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 17439 | * @phba: Pointer to the HBA structure to search for the vport on |
| 17440 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17441 | * @fcfi: The FC Fabric ID that the frame came from |
| 17442 | * |
| 17443 | * This function searches the @phba for a vport that matches the content of the |
| 17444 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 17445 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 17446 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 17447 | * vport. |
| 17448 | **/ |
| 17449 | static struct lpfc_vport * |
| 17450 | 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] | 17451 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17452 | { |
| 17453 | struct lpfc_vport **vports; |
| 17454 | struct lpfc_vport *vport = NULL; |
| 17455 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17456 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 17457 | if (did == Fabric_DID) |
| 17458 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17459 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 17460 | !(phba->link_state == LPFC_HBA_READY)) |
| 17461 | return phba->pport; |
| 17462 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17463 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17464 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17465 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 17466 | if (phba->fcf.fcfi == fcfi && |
| 17467 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 17468 | vports[i]->fc_myDID == did) { |
| 17469 | vport = vports[i]; |
| 17470 | break; |
| 17471 | } |
| 17472 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17473 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17474 | lpfc_destroy_vport_work_array(phba, vports); |
| 17475 | return vport; |
| 17476 | } |
| 17477 | |
| 17478 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17479 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 17480 | * @vport: The vport to work on. |
| 17481 | * |
| 17482 | * This function updates the receive sequence time stamp for this vport. The |
| 17483 | * receive sequence time stamp indicates the time that the last frame of the |
| 17484 | * the sequence that has been idle for the longest amount of time was received. |
| 17485 | * the driver uses this time stamp to indicate if any received sequences have |
| 17486 | * timed out. |
| 17487 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17488 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17489 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 17490 | { |
| 17491 | struct lpfc_dmabuf *h_buf; |
| 17492 | struct hbq_dmabuf *dmabuf = NULL; |
| 17493 | |
| 17494 | /* get the oldest sequence on the rcv list */ |
| 17495 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 17496 | struct lpfc_dmabuf, list); |
| 17497 | if (!h_buf) |
| 17498 | return; |
| 17499 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17500 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 17501 | } |
| 17502 | |
| 17503 | /** |
| 17504 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17505 | * @vport: The vport that the received sequences were sent to. |
| 17506 | * |
| 17507 | * This function cleans up all outstanding received sequences. This is called |
| 17508 | * by the driver when a link event or user action invalidates all the received |
| 17509 | * sequences. |
| 17510 | **/ |
| 17511 | void |
| 17512 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17513 | { |
| 17514 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17515 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17516 | struct hbq_dmabuf *dmabuf = NULL; |
| 17517 | |
| 17518 | /* start with the oldest sequence on the rcv list */ |
| 17519 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17520 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17521 | list_del_init(&dmabuf->hbuf.list); |
| 17522 | list_for_each_entry_safe(d_buf, dnext, |
| 17523 | &dmabuf->dbuf.list, list) { |
| 17524 | list_del_init(&d_buf->list); |
| 17525 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17526 | } |
| 17527 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17528 | } |
| 17529 | } |
| 17530 | |
| 17531 | /** |
| 17532 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17533 | * @vport: The vport that the received sequences were sent to. |
| 17534 | * |
| 17535 | * This function determines whether any received sequences have timed out by |
| 17536 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17537 | * indicates that there is at least one timed out sequence this routine will |
| 17538 | * go through the received sequences one at a time from most inactive to most |
| 17539 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17540 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17541 | * without sending an abort. |
| 17542 | **/ |
| 17543 | void |
| 17544 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17545 | { |
| 17546 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17547 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17548 | struct hbq_dmabuf *dmabuf = NULL; |
| 17549 | unsigned long timeout; |
| 17550 | int abort_count = 0; |
| 17551 | |
| 17552 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17553 | vport->rcv_buffer_time_stamp); |
| 17554 | if (list_empty(&vport->rcv_buffer_list) || |
| 17555 | time_before(jiffies, timeout)) |
| 17556 | return; |
| 17557 | /* start with the oldest sequence on the rcv list */ |
| 17558 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17559 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17560 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17561 | dmabuf->time_stamp); |
| 17562 | if (time_before(jiffies, timeout)) |
| 17563 | break; |
| 17564 | abort_count++; |
| 17565 | list_del_init(&dmabuf->hbuf.list); |
| 17566 | list_for_each_entry_safe(d_buf, dnext, |
| 17567 | &dmabuf->dbuf.list, list) { |
| 17568 | list_del_init(&d_buf->list); |
| 17569 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17570 | } |
| 17571 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17572 | } |
| 17573 | if (abort_count) |
| 17574 | lpfc_update_rcv_time_stamp(vport); |
| 17575 | } |
| 17576 | |
| 17577 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17578 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 17579 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17580 | * |
| 17581 | * This function searches through the existing incomplete sequences that have |
| 17582 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17583 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17584 | * make up that sequence. If no sequence is found that matches this frame then |
| 17585 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17586 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17587 | * the frame was linked to. |
| 17588 | **/ |
| 17589 | static struct hbq_dmabuf * |
| 17590 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17591 | { |
| 17592 | struct fc_frame_header *new_hdr; |
| 17593 | struct fc_frame_header *temp_hdr; |
| 17594 | struct lpfc_dmabuf *d_buf; |
| 17595 | struct lpfc_dmabuf *h_buf; |
| 17596 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17597 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17598 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17599 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17600 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17601 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17602 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17603 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17604 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17605 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17606 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17607 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17608 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17609 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17610 | continue; |
| 17611 | /* found a pending sequence that matches this frame */ |
| 17612 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17613 | break; |
| 17614 | } |
| 17615 | if (!seq_dmabuf) { |
| 17616 | /* |
| 17617 | * This indicates first frame received for this sequence. |
| 17618 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17619 | */ |
| 17620 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17621 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17622 | return dmabuf; |
| 17623 | } |
| 17624 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17625 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17626 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17627 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17628 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17629 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17630 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17631 | return dmabuf; |
| 17632 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17633 | /* move this sequence to the tail to indicate a young sequence */ |
| 17634 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17635 | seq_dmabuf->time_stamp = jiffies; |
| 17636 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17637 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 17638 | temp_hdr = dmabuf->hbuf.virt; |
| 17639 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17640 | return seq_dmabuf; |
| 17641 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17642 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17643 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17644 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17645 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17646 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17647 | /* |
| 17648 | * If the frame's sequence count is greater than the frame on |
| 17649 | * the list then insert the frame right after this frame |
| 17650 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17651 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17652 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17653 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17654 | found = 1; |
| 17655 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17656 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17657 | |
| 17658 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17659 | break; |
| 17660 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17661 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17662 | |
| 17663 | if (found) |
| 17664 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17665 | return NULL; |
| 17666 | } |
| 17667 | |
| 17668 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17669 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17670 | * @vport: pointer to a vitural port |
| 17671 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17672 | * |
| 17673 | * This function tries to abort from the partially assembed sequence, described |
| 17674 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17675 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17676 | * the frames from the partially assembled sequence. |
| 17677 | * |
| 17678 | * Return |
| 17679 | * true -- if there is matching partially assembled sequence present and all |
| 17680 | * the frames freed with the sequence; |
| 17681 | * false -- if there is no matching partially assembled sequence present so |
| 17682 | * nothing got aborted in the lower layer driver |
| 17683 | **/ |
| 17684 | static bool |
| 17685 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17686 | struct hbq_dmabuf *dmabuf) |
| 17687 | { |
| 17688 | struct fc_frame_header *new_hdr; |
| 17689 | struct fc_frame_header *temp_hdr; |
| 17690 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 17691 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17692 | |
| 17693 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 17694 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 17695 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 17696 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17697 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17698 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17699 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17700 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17701 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17702 | continue; |
| 17703 | /* found a pending sequence that matches this frame */ |
| 17704 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17705 | break; |
| 17706 | } |
| 17707 | |
| 17708 | /* Free up all the frames from the partially assembled sequence */ |
| 17709 | if (seq_dmabuf) { |
| 17710 | list_for_each_entry_safe(d_buf, n_buf, |
| 17711 | &seq_dmabuf->dbuf.list, list) { |
| 17712 | list_del_init(&d_buf->list); |
| 17713 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17714 | } |
| 17715 | return true; |
| 17716 | } |
| 17717 | return false; |
| 17718 | } |
| 17719 | |
| 17720 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17721 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 17722 | * @vport: pointer to a vitural port |
| 17723 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17724 | * |
| 17725 | * This function tries to abort from the assembed sequence from upper level |
| 17726 | * protocol, described by the information from basic abbort @dmabuf. It |
| 17727 | * checks to see whether such pending context exists at upper level protocol. |
| 17728 | * If so, it shall clean up the pending context. |
| 17729 | * |
| 17730 | * Return |
| 17731 | * true -- if there is matching pending context of the sequence cleaned |
| 17732 | * at ulp; |
| 17733 | * false -- if there is no matching pending context of the sequence present |
| 17734 | * at ulp. |
| 17735 | **/ |
| 17736 | static bool |
| 17737 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17738 | { |
| 17739 | struct lpfc_hba *phba = vport->phba; |
| 17740 | int handled; |
| 17741 | |
| 17742 | /* Accepting abort at ulp with SLI4 only */ |
| 17743 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 17744 | return false; |
| 17745 | |
| 17746 | /* Register all caring upper level protocols to attend abort */ |
| 17747 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 17748 | if (handled) |
| 17749 | return true; |
| 17750 | |
| 17751 | return false; |
| 17752 | } |
| 17753 | |
| 17754 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17755 | * 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] | 17756 | * @phba: Pointer to HBA context object. |
| 17757 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 17758 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 17759 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17760 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17761 | * event. It properly releases the memory allocated to the sequence abort |
| 17762 | * accept iocb. |
| 17763 | **/ |
| 17764 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17765 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17766 | struct lpfc_iocbq *cmd_iocbq, |
| 17767 | struct lpfc_iocbq *rsp_iocbq) |
| 17768 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17769 | struct lpfc_nodelist *ndlp; |
| 17770 | |
| 17771 | if (cmd_iocbq) { |
| 17772 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 17773 | lpfc_nlp_put(ndlp); |
| 17774 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17775 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17776 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17777 | |
| 17778 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 17779 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 17780 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17781 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17782 | rsp_iocbq->iocb.ulpStatus, |
| 17783 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17784 | } |
| 17785 | |
| 17786 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17787 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17788 | * @phba: Pointer to HBA context object. |
| 17789 | * @xri: xri id in transaction. |
| 17790 | * |
| 17791 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17792 | * used by the driver. |
| 17793 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17794 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17795 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17796 | uint16_t xri) |
| 17797 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17798 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17799 | |
| 17800 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17801 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17802 | return i; |
| 17803 | } |
| 17804 | return NO_XRI; |
| 17805 | } |
| 17806 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17807 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17808 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17809 | * @phba: Pointer to HBA context object. |
| 17810 | * @fc_hdr: pointer to a FC frame header. |
| 17811 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17812 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17813 | * event after aborting the sequence handling. |
| 17814 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17815 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17816 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17817 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17818 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17819 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17820 | struct lpfc_iocbq *ctiocb = NULL; |
| 17821 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17822 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17823 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17824 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17825 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17826 | |
| 17827 | if (!lpfc_is_link_up(phba)) |
| 17828 | return; |
| 17829 | |
| 17830 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17831 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17832 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17833 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17834 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17835 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17836 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17837 | if (!ndlp) { |
| 17838 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17839 | "1268 Failed to allocate ndlp for " |
| 17840 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17841 | return; |
| 17842 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17843 | /* Put ndlp onto pport node list */ |
| 17844 | lpfc_enqueue_node(vport, ndlp); |
| 17845 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17846 | /* re-setup ndlp without removing from node list */ |
| 17847 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17848 | if (!ndlp) { |
| 17849 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17850 | "3275 Failed to active ndlp found " |
| 17851 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17852 | return; |
| 17853 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17854 | } |
| 17855 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17856 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17857 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17858 | if (!ctiocb) |
| 17859 | return; |
| 17860 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17861 | /* Extract the F_CTL field from FC_HDR */ |
| 17862 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17863 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17864 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17865 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17866 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17867 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17868 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17869 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17870 | |
| 17871 | /* Fill in the rest of iocb fields */ |
| 17872 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17873 | icmd->ulpBdeCount = 0; |
| 17874 | icmd->ulpLe = 1; |
| 17875 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17876 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17877 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17878 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17879 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17880 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17881 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17882 | ctiocb->sli4_xritag = NO_XRI; |
| 17883 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17884 | if (fctl & FC_FC_EX_CTX) |
| 17885 | /* Exchange responder sent the abort so we |
| 17886 | * own the oxid. |
| 17887 | */ |
| 17888 | xri = oxid; |
| 17889 | else |
| 17890 | xri = rxid; |
| 17891 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17892 | if (lxri != NO_XRI) |
| 17893 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17894 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17895 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17896 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17897 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17898 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17899 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17900 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17901 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17902 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17903 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17904 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17905 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17906 | } |
| 17907 | |
| 17908 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17909 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17910 | * the IOCB for a BA_RJT. |
| 17911 | */ |
| 17912 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17913 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17914 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17915 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17916 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17917 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17918 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17919 | if (fctl & FC_FC_EX_CTX) { |
| 17920 | /* ABTS sent by responder to CT exchange, construction |
| 17921 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17922 | * field and RX_ID from ABTS for RX_ID field. |
| 17923 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17924 | 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] | 17925 | } else { |
| 17926 | /* ABTS sent by initiator to CT exchange, construction |
| 17927 | * 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] | 17928 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17929 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17930 | 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] | 17931 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17932 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17933 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17934 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17935 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17936 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17937 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17938 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17939 | |
| 17940 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17941 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17942 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17943 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17944 | "xri x%x, Data x%x\n", |
| 17945 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17946 | phba->link_state); |
| 17947 | lpfc_nlp_put(ndlp); |
| 17948 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17949 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17950 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17951 | } |
| 17952 | |
| 17953 | /** |
| 17954 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17955 | * @vport: Pointer to the vport on which this sequence was received |
| 17956 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17957 | * |
| 17958 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17959 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17960 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17961 | * unsolicited receive sequence has been completely assembled and passed to |
| 17962 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17963 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17964 | * accept to accept the abort. |
| 17965 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17966 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17967 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17968 | struct hbq_dmabuf *dmabuf) |
| 17969 | { |
| 17970 | struct lpfc_hba *phba = vport->phba; |
| 17971 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17972 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17973 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17974 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17975 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17976 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17977 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17978 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17979 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17980 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17981 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17982 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17983 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17984 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17985 | if (aborted == false) |
| 17986 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17987 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17988 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17989 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17990 | if (phba->nvmet_support) { |
| 17991 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17992 | return; |
| 17993 | } |
| 17994 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17995 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17996 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17997 | } |
| 17998 | |
| 17999 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18000 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 18001 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 18002 | * |
| 18003 | * This function checks the sequence, starting with the frame described by |
| 18004 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 18005 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 18006 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 18007 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 18008 | * set. 3) That there are no holes in the sequence count. The function will |
| 18009 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 18010 | **/ |
| 18011 | static int |
| 18012 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 18013 | { |
| 18014 | struct fc_frame_header *hdr; |
| 18015 | struct lpfc_dmabuf *d_buf; |
| 18016 | struct hbq_dmabuf *seq_dmabuf; |
| 18017 | uint32_t fctl; |
| 18018 | int seq_count = 0; |
| 18019 | |
| 18020 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 18021 | /* make sure first fame of sequence has a sequence count of zero */ |
| 18022 | if (hdr->fh_seq_cnt != seq_count) |
| 18023 | return 0; |
| 18024 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 18025 | hdr->fh_f_ctl[1] << 8 | |
| 18026 | hdr->fh_f_ctl[2]); |
| 18027 | /* If last frame of sequence we can return success. */ |
| 18028 | if (fctl & FC_FC_END_SEQ) |
| 18029 | return 1; |
| 18030 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 18031 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18032 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 18033 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 18034 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18035 | return 0; |
| 18036 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 18037 | hdr->fh_f_ctl[1] << 8 | |
| 18038 | hdr->fh_f_ctl[2]); |
| 18039 | /* If last frame of sequence we can return success. */ |
| 18040 | if (fctl & FC_FC_END_SEQ) |
| 18041 | return 1; |
| 18042 | } |
| 18043 | return 0; |
| 18044 | } |
| 18045 | |
| 18046 | /** |
| 18047 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 18048 | * @vport: Pointer to the vport on which this sequence was received |
| 18049 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 18050 | * |
| 18051 | * This function takes a sequence, described by a list of frames, and creates |
| 18052 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 18053 | * used to issue to the generic unsolicited sequence handler. This routine |
| 18054 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 18055 | * to allocate an iocbq then it throw out the received frames that were not |
| 18056 | * able to be described and return a pointer to the first iocbq. If unable to |
| 18057 | * allocate any iocbqs (including the first) this function will return NULL. |
| 18058 | **/ |
| 18059 | static struct lpfc_iocbq * |
| 18060 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 18061 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18062 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18063 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 18064 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 18065 | struct fc_frame_header *fc_hdr; |
| 18066 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18067 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 18068 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18069 | |
| 18070 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 18071 | /* remove from receive buffer list */ |
| 18072 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 18073 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18074 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18075 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18076 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18077 | /* Get an iocbq struct to fill in. */ |
| 18078 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 18079 | if (first_iocbq) { |
| 18080 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 18081 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18082 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18083 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18084 | |
| 18085 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 18086 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 18087 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 18088 | first_iocbq->iocb.un.rcvels.parmRo = |
| 18089 | sli4_did_from_fc_hdr(fc_hdr); |
| 18090 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 18091 | } else |
| 18092 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18093 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 18094 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 18095 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 18096 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 18097 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 18098 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18099 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18100 | tot_len = bf_get(lpfc_rcqe_length, |
| 18101 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18102 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18103 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 18104 | first_iocbq->context3 = NULL; |
| 18105 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18106 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 18107 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18108 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18109 | else |
| 18110 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 18111 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18112 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18113 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18114 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18115 | } |
| 18116 | iocbq = first_iocbq; |
| 18117 | /* |
| 18118 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 18119 | * of buffers for this sequence and save two buffers in each IOCBq |
| 18120 | */ |
| 18121 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 18122 | if (!iocbq) { |
| 18123 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18124 | continue; |
| 18125 | } |
| 18126 | if (!iocbq->context3) { |
| 18127 | iocbq->context3 = d_buf; |
| 18128 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18129 | /* We need to get the size out of the right CQE */ |
| 18130 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18131 | len = bf_get(lpfc_rcqe_length, |
| 18132 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18133 | pbde = (struct ulp_bde64 *) |
| 18134 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 18135 | if (len > LPFC_DATA_BUF_SIZE) |
| 18136 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 18137 | else |
| 18138 | pbde->tus.f.bdeSize = len; |
| 18139 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18140 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 18141 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18142 | } else { |
| 18143 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 18144 | if (!iocbq) { |
| 18145 | if (first_iocbq) { |
| 18146 | first_iocbq->iocb.ulpStatus = |
| 18147 | IOSTAT_FCP_RSP_ERROR; |
| 18148 | first_iocbq->iocb.un.ulpWord[4] = |
| 18149 | IOERR_NO_RESOURCES; |
| 18150 | } |
| 18151 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18152 | continue; |
| 18153 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18154 | /* We need to get the size out of the right CQE */ |
| 18155 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18156 | len = bf_get(lpfc_rcqe_length, |
| 18157 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18158 | iocbq->context2 = d_buf; |
| 18159 | iocbq->context3 = NULL; |
| 18160 | iocbq->iocb.ulpBdeCount = 1; |
| 18161 | if (len > LPFC_DATA_BUF_SIZE) |
| 18162 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 18163 | LPFC_DATA_BUF_SIZE; |
| 18164 | else |
| 18165 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 18166 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18167 | tot_len += len; |
| 18168 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 18169 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18170 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 18171 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 18172 | } |
| 18173 | } |
James Smart | 39c4f1a | 2020-01-27 16:23:01 -0800 | [diff] [blame] | 18174 | /* Free the sequence's header buffer */ |
| 18175 | if (!first_iocbq) |
| 18176 | lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf); |
| 18177 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18178 | return first_iocbq; |
| 18179 | } |
| 18180 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18181 | static void |
| 18182 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 18183 | struct hbq_dmabuf *seq_dmabuf) |
| 18184 | { |
| 18185 | struct fc_frame_header *fc_hdr; |
| 18186 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 18187 | struct lpfc_hba *phba = vport->phba; |
| 18188 | |
| 18189 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 18190 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 18191 | if (!iocbq) { |
| 18192 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18193 | "2707 Ring %d handler: Failed to allocate " |
| 18194 | "iocb Rctl x%x Type x%x received\n", |
| 18195 | LPFC_ELS_RING, |
| 18196 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 18197 | return; |
| 18198 | } |
| 18199 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18200 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18201 | iocbq, fc_hdr->fh_r_ctl, |
| 18202 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18203 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18204 | "2540 Ring %d handler: unexpected Rctl " |
| 18205 | "x%x Type x%x received\n", |
| 18206 | LPFC_ELS_RING, |
| 18207 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 18208 | |
| 18209 | /* Free iocb created in lpfc_prep_seq */ |
| 18210 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 18211 | &iocbq->list, list) { |
| 18212 | list_del_init(&curr_iocb->list); |
| 18213 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 18214 | } |
| 18215 | lpfc_sli_release_iocbq(phba, iocbq); |
| 18216 | } |
| 18217 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18218 | static void |
| 18219 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 18220 | struct lpfc_iocbq *rspiocb) |
| 18221 | { |
| 18222 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 18223 | |
| 18224 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18225 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18226 | kfree(pcmd); |
| 18227 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18228 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18229 | } |
| 18230 | |
| 18231 | static void |
| 18232 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 18233 | struct hbq_dmabuf *dmabuf) |
| 18234 | { |
| 18235 | struct fc_frame_header *fc_hdr; |
| 18236 | struct lpfc_hba *phba = vport->phba; |
| 18237 | struct lpfc_iocbq *iocbq = NULL; |
| 18238 | union lpfc_wqe *wqe; |
| 18239 | struct lpfc_dmabuf *pcmd = NULL; |
| 18240 | uint32_t frame_len; |
| 18241 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18242 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18243 | |
| 18244 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 18245 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18246 | |
| 18247 | /* Send the received frame back */ |
| 18248 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18249 | if (!iocbq) { |
| 18250 | /* Queue cq event and wakeup worker thread to process it */ |
| 18251 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 18252 | list_add_tail(&dmabuf->cq_event.list, |
| 18253 | &phba->sli4_hba.sp_queue_event); |
| 18254 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 18255 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 18256 | lpfc_worker_wake_up(phba); |
| 18257 | return; |
| 18258 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18259 | |
| 18260 | /* Allocate buffer for command payload */ |
| 18261 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 18262 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18263 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18264 | &pcmd->phys); |
| 18265 | if (!pcmd || !pcmd->virt) |
| 18266 | goto exit; |
| 18267 | |
| 18268 | INIT_LIST_HEAD(&pcmd->list); |
| 18269 | |
| 18270 | /* copyin the payload */ |
| 18271 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 18272 | |
| 18273 | /* fill in BDE's for command */ |
| 18274 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 18275 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 18276 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 18277 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 18278 | |
| 18279 | iocbq->context2 = pcmd; |
| 18280 | iocbq->vport = vport; |
| 18281 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 18282 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 18283 | |
| 18284 | /* |
| 18285 | * Setup rest of the iocb as though it were a WQE |
| 18286 | * Build the SEND_FRAME WQE |
| 18287 | */ |
| 18288 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 18289 | |
| 18290 | wqe->send_frame.frame_len = frame_len; |
| 18291 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 18292 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 18293 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 18294 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 18295 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 18296 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 18297 | |
| 18298 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 18299 | iocbq->iocb.ulpLe = 1; |
| 18300 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 18301 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 18302 | if (rc == IOCB_ERROR) |
| 18303 | goto exit; |
| 18304 | |
| 18305 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18306 | return; |
| 18307 | |
| 18308 | exit: |
| 18309 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 18310 | "2023 Unable to process MDS loopback frame\n"); |
| 18311 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18312 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18313 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 18314 | if (iocbq) |
| 18315 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18316 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18317 | } |
| 18318 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18319 | /** |
| 18320 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 18321 | * @phba: Pointer to HBA context object. |
| 18322 | * |
| 18323 | * This function is called with no lock held. This function processes all |
| 18324 | * the received buffers and gives it to upper layers when a received buffer |
| 18325 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18326 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18327 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 18328 | * appropriate receive function when the final frame in a sequence is received. |
| 18329 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18330 | void |
| 18331 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 18332 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18333 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18334 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18335 | struct fc_frame_header *fc_hdr; |
| 18336 | struct lpfc_vport *vport; |
| 18337 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18338 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18339 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18340 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18341 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 18342 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18343 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 18344 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 18345 | vport = phba->pport; |
| 18346 | /* Handle MDS Loopback frames */ |
| 18347 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 18348 | return; |
| 18349 | } |
| 18350 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18351 | /* check to see if this a valid type of frame */ |
| 18352 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 18353 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18354 | return; |
| 18355 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 18356 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18357 | if ((bf_get(lpfc_cqe_code, |
| 18358 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 18359 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 18360 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18361 | else |
| 18362 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 18363 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18364 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 18365 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 18366 | vport = phba->pport; |
| 18367 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 18368 | "2023 MDS Loopback %d bytes\n", |
| 18369 | bf_get(lpfc_rcqe_length, |
| 18370 | &dmabuf->cq_event.cqe.rcqe_cmpl)); |
| 18371 | /* Handle MDS Loopback frames */ |
| 18372 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 18373 | return; |
| 18374 | } |
| 18375 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18376 | /* d_id this frame is directed to */ |
| 18377 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 18378 | |
| 18379 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18380 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18381 | /* throw out the frame */ |
| 18382 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18383 | return; |
| 18384 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18385 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18386 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 18387 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 18388 | (did != Fabric_DID)) { |
| 18389 | /* |
| 18390 | * Throw out the frame if we are not pt2pt. |
| 18391 | * The pt2pt protocol allows for discovery frames |
| 18392 | * to be received without a registered VPI. |
| 18393 | */ |
| 18394 | if (!(vport->fc_flag & FC_PT2PT) || |
| 18395 | (phba->link_state == LPFC_HBA_READY)) { |
| 18396 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18397 | return; |
| 18398 | } |
| 18399 | } |
| 18400 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18401 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 18402 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 18403 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 18404 | return; |
| 18405 | } |
| 18406 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18407 | /* Link this frame */ |
| 18408 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 18409 | if (!seq_dmabuf) { |
| 18410 | /* unable to add frame to vport - throw it out */ |
| 18411 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18412 | return; |
| 18413 | } |
| 18414 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18415 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18416 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18417 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18418 | /* Send the complete sequence to the upper layer protocol */ |
| 18419 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18420 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18421 | |
| 18422 | /** |
| 18423 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 18424 | * @phba: pointer to lpfc hba data structure. |
| 18425 | * |
| 18426 | * This routine is invoked to post rpi header templates to the |
| 18427 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18428 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18429 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18430 | * |
| 18431 | * This routine does not require any locks. It's usage is expected |
| 18432 | * to be driver load or reset recovery when the driver is |
| 18433 | * sequential. |
| 18434 | * |
| 18435 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18436 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18437 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18438 | * When this error occurs, the driver is not guaranteed |
| 18439 | * to have any rpi regions posted to the device and |
| 18440 | * must either attempt to repost the regions or take a |
| 18441 | * fatal error. |
| 18442 | **/ |
| 18443 | int |
| 18444 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 18445 | { |
| 18446 | struct lpfc_rpi_hdr *rpi_page; |
| 18447 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18448 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18449 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18450 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18451 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18452 | goto exit; |
| 18453 | if (phba->sli4_hba.extents_in_use) |
| 18454 | return -EIO; |
| 18455 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18456 | 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] | 18457 | /* |
| 18458 | * Assign the rpi headers a physical rpi only if the driver |
| 18459 | * has not initialized those resources. A port reset only |
| 18460 | * needs the headers posted. |
| 18461 | */ |
| 18462 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 18463 | LPFC_RPI_RSRC_RDY) |
| 18464 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 18465 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18466 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 18467 | if (rc != MBX_SUCCESS) { |
| 18468 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18469 | "2008 Error %d posting all rpi " |
| 18470 | "headers\n", rc); |
| 18471 | rc = -EIO; |
| 18472 | break; |
| 18473 | } |
| 18474 | } |
| 18475 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18476 | exit: |
| 18477 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 18478 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18479 | return rc; |
| 18480 | } |
| 18481 | |
| 18482 | /** |
| 18483 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 18484 | * @phba: pointer to lpfc hba data structure. |
| 18485 | * @rpi_page: pointer to the rpi memory region. |
| 18486 | * |
| 18487 | * This routine is invoked to post a single rpi header to the |
| 18488 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 18489 | * maps up to 64 rpi context regions. |
| 18490 | * |
| 18491 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18492 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18493 | * -ENOMEM - No available memory |
| 18494 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18495 | **/ |
| 18496 | int |
| 18497 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 18498 | { |
| 18499 | LPFC_MBOXQ_t *mboxq; |
| 18500 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 18501 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18502 | uint32_t shdr_status, shdr_add_status; |
| 18503 | union lpfc_sli4_cfg_shdr *shdr; |
| 18504 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18505 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18506 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18507 | return rc; |
| 18508 | if (phba->sli4_hba.extents_in_use) |
| 18509 | return -EIO; |
| 18510 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18511 | /* The port is notified of the header region via a mailbox command. */ |
| 18512 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18513 | if (!mboxq) { |
| 18514 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18515 | "2001 Unable to allocate memory for issuing " |
| 18516 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 18517 | return -ENOMEM; |
| 18518 | } |
| 18519 | |
| 18520 | /* Post all rpi memory regions to the port. */ |
| 18521 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18522 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18523 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18524 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18525 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18526 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18527 | |
| 18528 | |
| 18529 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18530 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18531 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18532 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18533 | hdr_tmpl, rpi_page->page_count); |
| 18534 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18535 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18536 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18537 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18538 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18539 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18540 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18541 | if (rc != MBX_TIMEOUT) |
| 18542 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18543 | if (shdr_status || shdr_add_status || rc) { |
| 18544 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18545 | "2514 POST_RPI_HDR mailbox failed with " |
| 18546 | "status x%x add_status x%x, mbx status x%x\n", |
| 18547 | shdr_status, shdr_add_status, rc); |
| 18548 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18549 | } else { |
| 18550 | /* |
| 18551 | * The next_rpi stores the next logical module-64 rpi value used |
| 18552 | * to post physical rpis in subsequent rpi postings. |
| 18553 | */ |
| 18554 | spin_lock_irq(&phba->hbalock); |
| 18555 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18556 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18557 | } |
| 18558 | return rc; |
| 18559 | } |
| 18560 | |
| 18561 | /** |
| 18562 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18563 | * @phba: pointer to lpfc hba data structure. |
| 18564 | * |
| 18565 | * This routine is invoked to post rpi header templates to the |
| 18566 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18567 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18568 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18569 | * |
| 18570 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18571 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18572 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18573 | **/ |
| 18574 | int |
| 18575 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18576 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18577 | unsigned long rpi; |
| 18578 | uint16_t max_rpi, rpi_limit; |
| 18579 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18580 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18581 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18582 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18583 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18584 | * Fetch the next logical rpi. Because this index is logical, |
| 18585 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18586 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18587 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18588 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18589 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18590 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18591 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18592 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18593 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18594 | else { |
| 18595 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18596 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18597 | phba->sli4_hba.rpi_count++; |
| 18598 | } |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18599 | lpfc_printf_log(phba, KERN_INFO, |
| 18600 | LOG_NODE | LOG_DISCOVERY, |
| 18601 | "0001 Allocated rpi:x%x max:x%x lim:x%x\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18602 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18603 | |
| 18604 | /* |
| 18605 | * 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] | 18606 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18607 | */ |
| 18608 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18609 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18610 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18611 | return rpi; |
| 18612 | } |
| 18613 | |
| 18614 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18615 | * RPI header postings are not required for SLI4 ports capable of |
| 18616 | * extents. |
| 18617 | */ |
| 18618 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18619 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18620 | return rpi; |
| 18621 | } |
| 18622 | |
| 18623 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18624 | * If the driver is running low on rpi resources, allocate another |
| 18625 | * page now. Note that the next_rpi value is used because |
| 18626 | * it represents how many are actually in use whereas max_rpi notes |
| 18627 | * how many are supported max by the device. |
| 18628 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18629 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18630 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18631 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18632 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18633 | if (!rpi_hdr) { |
| 18634 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18635 | "2002 Error Could not grow rpi " |
| 18636 | "count\n"); |
| 18637 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18638 | lrpi = rpi_hdr->start_rpi; |
| 18639 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18640 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18641 | } |
| 18642 | } |
| 18643 | |
| 18644 | return rpi; |
| 18645 | } |
| 18646 | |
| 18647 | /** |
| 18648 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18649 | * @phba: pointer to lpfc hba data structure. |
| 18650 | * |
| 18651 | * This routine is invoked to release an rpi to the pool of |
| 18652 | * available rpis maintained by the driver. |
| 18653 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18654 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18655 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18656 | { |
James Smart | 7cfd563 | 2019-11-04 16:56:58 -0800 | [diff] [blame] | 18657 | /* |
| 18658 | * if the rpi value indicates a prior unreg has already |
| 18659 | * been done, skip the unreg. |
| 18660 | */ |
| 18661 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 18662 | return; |
| 18663 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18664 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18665 | phba->sli4_hba.rpi_count--; |
| 18666 | phba->sli4_hba.max_cfg_param.rpi_used--; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18667 | } else { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18668 | lpfc_printf_log(phba, KERN_INFO, |
| 18669 | LOG_NODE | LOG_DISCOVERY, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18670 | "2016 rpi %x not inuse\n", |
| 18671 | rpi); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18672 | } |
| 18673 | } |
| 18674 | |
| 18675 | /** |
| 18676 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18677 | * @phba: pointer to lpfc hba data structure. |
| 18678 | * |
| 18679 | * This routine is invoked to release an rpi to the pool of |
| 18680 | * available rpis maintained by the driver. |
| 18681 | **/ |
| 18682 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18683 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18684 | { |
| 18685 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18686 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18687 | spin_unlock_irq(&phba->hbalock); |
| 18688 | } |
| 18689 | |
| 18690 | /** |
| 18691 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 18692 | * @phba: pointer to lpfc hba data structure. |
| 18693 | * |
| 18694 | * This routine is invoked to remove the memory region that |
| 18695 | * provided rpi via a bitmask. |
| 18696 | **/ |
| 18697 | void |
| 18698 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 18699 | { |
| 18700 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18701 | kfree(phba->sli4_hba.rpi_ids); |
| 18702 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18703 | } |
| 18704 | |
| 18705 | /** |
| 18706 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 18707 | * @phba: pointer to lpfc hba data structure. |
| 18708 | * |
| 18709 | * This routine is invoked to remove the memory region that |
| 18710 | * provided rpi via a bitmask. |
| 18711 | **/ |
| 18712 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18713 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 18714 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18715 | { |
| 18716 | LPFC_MBOXQ_t *mboxq; |
| 18717 | struct lpfc_hba *phba = ndlp->phba; |
| 18718 | int rc; |
| 18719 | |
| 18720 | /* The port is notified of the header region via a mailbox command. */ |
| 18721 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18722 | if (!mboxq) |
| 18723 | return -ENOMEM; |
| 18724 | |
| 18725 | /* Post all rpi memory regions to the port. */ |
| 18726 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18727 | if (cmpl) { |
| 18728 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 18729 | mboxq->ctx_buf = arg; |
| 18730 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 18731 | } else |
| 18732 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18733 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18734 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18735 | if (rc == MBX_NOT_FINISHED) { |
| 18736 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18737 | "2010 Resume RPI Mailbox failed " |
| 18738 | "status %d, mbxStatus x%x\n", rc, |
| 18739 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 18740 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18741 | return -EIO; |
| 18742 | } |
| 18743 | return 0; |
| 18744 | } |
| 18745 | |
| 18746 | /** |
| 18747 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18748 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18749 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18750 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18751 | * |
| 18752 | * Returns: |
| 18753 | * 0 success |
| 18754 | * -Evalue otherwise |
| 18755 | **/ |
| 18756 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18757 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18758 | { |
| 18759 | LPFC_MBOXQ_t *mboxq; |
| 18760 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18761 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18762 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18763 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18764 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18765 | if (!mboxq) |
| 18766 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18767 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18768 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18769 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18770 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18771 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18772 | "2022 INIT VPI Mailbox failed " |
| 18773 | "status %d, mbxStatus x%x\n", rc, |
| 18774 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18775 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18776 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18777 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18778 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18779 | |
| 18780 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18781 | } |
| 18782 | |
| 18783 | /** |
| 18784 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 18785 | * @phba: pointer to lpfc hba data structure. |
| 18786 | * @mboxq: Pointer to mailbox object. |
| 18787 | * |
| 18788 | * This routine is invoked to manually add a single FCF record. The caller |
| 18789 | * must pass a completely initialized FCF_Record. This routine takes |
| 18790 | * care of the nonembedded mailbox operations. |
| 18791 | **/ |
| 18792 | static void |
| 18793 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 18794 | { |
| 18795 | void *virt_addr; |
| 18796 | union lpfc_sli4_cfg_shdr *shdr; |
| 18797 | uint32_t shdr_status, shdr_add_status; |
| 18798 | |
| 18799 | virt_addr = mboxq->sge_array->addr[0]; |
| 18800 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18801 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 18802 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18803 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18804 | |
| 18805 | if ((shdr_status || shdr_add_status) && |
| 18806 | (shdr_status != STATUS_FCF_IN_USE)) |
| 18807 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18808 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 18809 | "status x%x add_status x%x\n", |
| 18810 | shdr_status, shdr_add_status); |
| 18811 | |
| 18812 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18813 | } |
| 18814 | |
| 18815 | /** |
| 18816 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 18817 | * @phba: pointer to lpfc hba data structure. |
| 18818 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18819 | * |
| 18820 | * This routine is invoked to manually add a single FCF record. The caller |
| 18821 | * must pass a completely initialized FCF_Record. This routine takes |
| 18822 | * care of the nonembedded mailbox operations. |
| 18823 | **/ |
| 18824 | int |
| 18825 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18826 | { |
| 18827 | int rc = 0; |
| 18828 | LPFC_MBOXQ_t *mboxq; |
| 18829 | uint8_t *bytep; |
| 18830 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18831 | struct lpfc_mbx_sge sge; |
| 18832 | uint32_t alloc_len, req_len; |
| 18833 | uint32_t fcfindex; |
| 18834 | |
| 18835 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18836 | if (!mboxq) { |
| 18837 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18838 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18839 | return -ENOMEM; |
| 18840 | } |
| 18841 | |
| 18842 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18843 | sizeof(uint32_t); |
| 18844 | |
| 18845 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18846 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18847 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18848 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18849 | if (alloc_len < req_len) { |
| 18850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18851 | "2523 Allocated DMA memory size (x%x) is " |
| 18852 | "less than the requested DMA memory " |
| 18853 | "size (x%x)\n", alloc_len, req_len); |
| 18854 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18855 | return -ENOMEM; |
| 18856 | } |
| 18857 | |
| 18858 | /* |
| 18859 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18860 | * routine only uses a single SGE. |
| 18861 | */ |
| 18862 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18863 | virt_addr = mboxq->sge_array->addr[0]; |
| 18864 | /* |
| 18865 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18866 | * hardcoded default and gets used in nonFIP mode. |
| 18867 | */ |
| 18868 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18869 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18870 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18871 | |
| 18872 | /* |
| 18873 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18874 | * the FCoE header plus word10. The data copy needs to be endian |
| 18875 | * correct. |
| 18876 | */ |
| 18877 | bytep += sizeof(uint32_t); |
| 18878 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18879 | mboxq->vport = phba->pport; |
| 18880 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18881 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18882 | if (rc == MBX_NOT_FINISHED) { |
| 18883 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18884 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18885 | "status 0x%x\n", rc); |
| 18886 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18887 | rc = -EIO; |
| 18888 | } else |
| 18889 | rc = 0; |
| 18890 | |
| 18891 | return rc; |
| 18892 | } |
| 18893 | |
| 18894 | /** |
| 18895 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18896 | * @phba: pointer to lpfc hba data structure. |
| 18897 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18898 | * @fcf_index: FCF table entry index. |
| 18899 | * |
| 18900 | * This routine is invoked to build the driver's default FCF record. The |
| 18901 | * values used are hardcoded. This routine handles memory initialization. |
| 18902 | * |
| 18903 | **/ |
| 18904 | void |
| 18905 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18906 | struct fcf_record *fcf_record, |
| 18907 | uint16_t fcf_index) |
| 18908 | { |
| 18909 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18910 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18911 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18912 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18913 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18914 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18915 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18916 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18917 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18918 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18919 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18920 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18921 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18922 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18923 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18924 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18925 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18926 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18927 | /* Set the VLAN bit map */ |
| 18928 | if (phba->valid_vlan) { |
| 18929 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18930 | = 1 << (phba->vlan_id % 8); |
| 18931 | } |
| 18932 | } |
| 18933 | |
| 18934 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18935 | * 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] | 18936 | * @phba: pointer to lpfc hba data structure. |
| 18937 | * @fcf_index: FCF table entry offset. |
| 18938 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18939 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18940 | * record and processing it one at a time starting from the @fcf_index |
| 18941 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18942 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18943 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18944 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18945 | **/ |
| 18946 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18947 | 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] | 18948 | { |
| 18949 | int rc = 0, error; |
| 18950 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18951 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18952 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18953 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18954 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18955 | if (!mboxq) { |
| 18956 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18957 | "2000 Failed to allocate mbox for " |
| 18958 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18959 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18960 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18961 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18962 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18963 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18964 | if (rc) { |
| 18965 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18966 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18967 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18968 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18969 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18970 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18971 | |
| 18972 | spin_lock_irq(&phba->hbalock); |
| 18973 | phba->hba_flag |= FCF_TS_INPROG; |
| 18974 | spin_unlock_irq(&phba->hbalock); |
| 18975 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18976 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18977 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18978 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18979 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18980 | /* Reset eligible FCF count for new scan */ |
| 18981 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18982 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18983 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18984 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18985 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18986 | if (error) { |
| 18987 | if (mboxq) |
| 18988 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18989 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18990 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18991 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18992 | spin_unlock_irq(&phba->hbalock); |
| 18993 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18994 | return error; |
| 18995 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18996 | |
| 18997 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18998 | * 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] | 18999 | * @phba: pointer to lpfc hba data structure. |
| 19000 | * @fcf_index: FCF table entry offset. |
| 19001 | * |
| 19002 | * 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] | 19003 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19004 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 19005 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19006 | * otherwise. |
| 19007 | **/ |
| 19008 | int |
| 19009 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19010 | { |
| 19011 | int rc = 0, error; |
| 19012 | LPFC_MBOXQ_t *mboxq; |
| 19013 | |
| 19014 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19015 | if (!mboxq) { |
| 19016 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 19017 | "2763 Failed to allocate mbox for " |
| 19018 | "READ_FCF cmd\n"); |
| 19019 | error = -ENOMEM; |
| 19020 | goto fail_fcf_read; |
| 19021 | } |
| 19022 | /* Construct the read FCF record mailbox command */ |
| 19023 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 19024 | if (rc) { |
| 19025 | error = -EINVAL; |
| 19026 | goto fail_fcf_read; |
| 19027 | } |
| 19028 | /* Issue the mailbox command asynchronously */ |
| 19029 | mboxq->vport = phba->pport; |
| 19030 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 19031 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 19032 | if (rc == MBX_NOT_FINISHED) |
| 19033 | error = -EIO; |
| 19034 | else |
| 19035 | error = 0; |
| 19036 | |
| 19037 | fail_fcf_read: |
| 19038 | if (error && mboxq) |
| 19039 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19040 | return error; |
| 19041 | } |
| 19042 | |
| 19043 | /** |
| 19044 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 19045 | * @phba: pointer to lpfc hba data structure. |
| 19046 | * @fcf_index: FCF table entry offset. |
| 19047 | * |
| 19048 | * 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] | 19049 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19050 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 19051 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19052 | * otherwise. |
| 19053 | **/ |
| 19054 | int |
| 19055 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19056 | { |
| 19057 | int rc = 0, error; |
| 19058 | LPFC_MBOXQ_t *mboxq; |
| 19059 | |
| 19060 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19061 | if (!mboxq) { |
| 19062 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 19063 | "2758 Failed to allocate mbox for " |
| 19064 | "READ_FCF cmd\n"); |
| 19065 | error = -ENOMEM; |
| 19066 | goto fail_fcf_read; |
| 19067 | } |
| 19068 | /* Construct the read FCF record mailbox command */ |
| 19069 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 19070 | if (rc) { |
| 19071 | error = -EINVAL; |
| 19072 | goto fail_fcf_read; |
| 19073 | } |
| 19074 | /* Issue the mailbox command asynchronously */ |
| 19075 | mboxq->vport = phba->pport; |
| 19076 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 19077 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 19078 | if (rc == MBX_NOT_FINISHED) |
| 19079 | error = -EIO; |
| 19080 | else |
| 19081 | error = 0; |
| 19082 | |
| 19083 | fail_fcf_read: |
| 19084 | if (error && mboxq) |
| 19085 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19086 | return error; |
| 19087 | } |
| 19088 | |
| 19089 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19090 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19091 | * phba pointer to the lpfc_hba struct for this port. |
| 19092 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 19093 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 19094 | * rr_bmask based on their priority level. Starting from the highest priority |
| 19095 | * to the lowest. The most likely FCF candidate will be in the highest |
| 19096 | * priority group. When this routine is called it searches the fcf_pri list for |
| 19097 | * next lowest priority group and repopulates the rr_bmask with only those |
| 19098 | * fcf_indexes. |
| 19099 | * returns: |
| 19100 | * 1=success 0=failure |
| 19101 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 19102 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19103 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 19104 | { |
| 19105 | uint16_t next_fcf_pri; |
| 19106 | uint16_t last_index; |
| 19107 | struct lpfc_fcf_pri *fcf_pri; |
| 19108 | int rc; |
| 19109 | int ret = 0; |
| 19110 | |
| 19111 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 19112 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19113 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 19114 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 19115 | |
| 19116 | /* Verify the priority list has 2 or more entries */ |
| 19117 | spin_lock_irq(&phba->hbalock); |
| 19118 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 19119 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 19120 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19121 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 19122 | "3061 Last IDX %d\n", last_index); |
| 19123 | return 0; /* Empty rr list */ |
| 19124 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 19125 | spin_unlock_irq(&phba->hbalock); |
| 19126 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19127 | next_fcf_pri = 0; |
| 19128 | /* |
| 19129 | * Clear the rr_bmask and set all of the bits that are at this |
| 19130 | * priority. |
| 19131 | */ |
| 19132 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 19133 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 19134 | spin_lock_irq(&phba->hbalock); |
| 19135 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 19136 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 19137 | continue; |
| 19138 | /* |
| 19139 | * the 1st priority that has not FLOGI failed |
| 19140 | * will be the highest. |
| 19141 | */ |
| 19142 | if (!next_fcf_pri) |
| 19143 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 19144 | spin_unlock_irq(&phba->hbalock); |
| 19145 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 19146 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 19147 | fcf_pri->fcf_rec.fcf_index); |
| 19148 | if (rc) |
| 19149 | return 0; |
| 19150 | } |
| 19151 | spin_lock_irq(&phba->hbalock); |
| 19152 | } |
| 19153 | /* |
| 19154 | * if next_fcf_pri was not set above and the list is not empty then |
| 19155 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 19156 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19157 | */ |
| 19158 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 19159 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 19160 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 19161 | /* |
| 19162 | * the 1st priority that has not FLOGI failed |
| 19163 | * will be the highest. |
| 19164 | */ |
| 19165 | if (!next_fcf_pri) |
| 19166 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 19167 | spin_unlock_irq(&phba->hbalock); |
| 19168 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 19169 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 19170 | fcf_pri->fcf_rec.fcf_index); |
| 19171 | if (rc) |
| 19172 | return 0; |
| 19173 | } |
| 19174 | spin_lock_irq(&phba->hbalock); |
| 19175 | } |
| 19176 | } else |
| 19177 | ret = 1; |
| 19178 | spin_unlock_irq(&phba->hbalock); |
| 19179 | |
| 19180 | return ret; |
| 19181 | } |
| 19182 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19183 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 19184 | * @phba: pointer to lpfc hba data structure. |
| 19185 | * |
| 19186 | * This routine is to get the next eligible FCF record index in a round |
| 19187 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19188 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19189 | * shall be returned, otherwise, the next eligible FCF record's index |
| 19190 | * shall be returned. |
| 19191 | **/ |
| 19192 | uint16_t |
| 19193 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 19194 | { |
| 19195 | uint16_t next_fcf_index; |
| 19196 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19197 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19198 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19199 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 19200 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19201 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19202 | /* Determine the next fcf index to check */ |
| 19203 | 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] | 19204 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 19205 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19206 | next_fcf_index); |
| 19207 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19208 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19209 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19210 | /* |
| 19211 | * If we have wrapped then we need to clear the bits that |
| 19212 | * have been tested so that we can detect when we should |
| 19213 | * change the priority level. |
| 19214 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19215 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 19216 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19217 | } |
| 19218 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19219 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19220 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19221 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 19222 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 19223 | /* |
| 19224 | * If next fcf index is not found check if there are lower |
| 19225 | * Priority level fcf's in the fcf_priority list. |
| 19226 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 19227 | * at that level and continue the selection process. |
| 19228 | */ |
| 19229 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19230 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19231 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 19232 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 19233 | |
| 19234 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19235 | } |
| 19236 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19237 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 19238 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19239 | LPFC_FCF_FLOGI_FAILED) { |
| 19240 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 19241 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 19242 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19243 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19244 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19245 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19246 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19247 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 19248 | next_fcf_index); |
| 19249 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19250 | return next_fcf_index; |
| 19251 | } |
| 19252 | |
| 19253 | /** |
| 19254 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 19255 | * @phba: pointer to lpfc hba data structure. |
| 19256 | * |
| 19257 | * 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] | 19258 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19259 | * does not go beyond the range of the driver allocated bmask dimension |
| 19260 | * before setting the bit. |
| 19261 | * |
| 19262 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 19263 | * -EINVAL. |
| 19264 | **/ |
| 19265 | int |
| 19266 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19267 | { |
| 19268 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19269 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19270 | "2610 FCF (x%x) reached driver's book " |
| 19271 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19272 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19273 | return -EINVAL; |
| 19274 | } |
| 19275 | /* Set the eligible FCF record index bmask */ |
| 19276 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 19277 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19278 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19279 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19280 | "bmask\n", fcf_index); |
| 19281 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19282 | return 0; |
| 19283 | } |
| 19284 | |
| 19285 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19286 | * 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] | 19287 | * @phba: pointer to lpfc hba data structure. |
| 19288 | * |
| 19289 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19290 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19291 | * does not go beyond the range of the driver allocated bmask dimension |
| 19292 | * before clearing the bit. |
| 19293 | **/ |
| 19294 | void |
| 19295 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19296 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 19297 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19298 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19299 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19300 | "2762 FCF (x%x) reached driver's book " |
| 19301 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19302 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19303 | return; |
| 19304 | } |
| 19305 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19306 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 19307 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 19308 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19309 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 19310 | list_del_init(&fcf_pri->list); |
| 19311 | break; |
| 19312 | } |
| 19313 | } |
| 19314 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19315 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19316 | |
| 19317 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19318 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19319 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19320 | } |
| 19321 | |
| 19322 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19323 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 19324 | * @phba: pointer to lpfc hba data structure. |
| 19325 | * |
| 19326 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 19327 | * command. If the mailbox command returned failure, it will try to stop the |
| 19328 | * FCF rediscover wait timer. |
| 19329 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 19330 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19331 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 19332 | { |
| 19333 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 19334 | uint32_t shdr_status, shdr_add_status; |
| 19335 | |
| 19336 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19337 | |
| 19338 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19339 | &redisc_fcf->header.cfg_shdr.response); |
| 19340 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19341 | &redisc_fcf->header.cfg_shdr.response); |
| 19342 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19343 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19344 | "2746 Requesting for FCF rediscovery failed " |
| 19345 | "status x%x add_status x%x\n", |
| 19346 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19347 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19348 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19349 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19350 | spin_unlock_irq(&phba->hbalock); |
| 19351 | /* |
| 19352 | * CVL event triggered FCF rediscover request failed, |
| 19353 | * last resort to re-try current registered FCF entry. |
| 19354 | */ |
| 19355 | lpfc_retry_pport_discovery(phba); |
| 19356 | } else { |
| 19357 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19358 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19359 | spin_unlock_irq(&phba->hbalock); |
| 19360 | /* |
| 19361 | * DEAD FCF event triggered FCF rediscover request |
| 19362 | * failed, last resort to fail over as a link down |
| 19363 | * to FCF registration. |
| 19364 | */ |
| 19365 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 19366 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19367 | } else { |
| 19368 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19369 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19370 | /* |
| 19371 | * Start FCF rediscovery wait timer for pending FCF |
| 19372 | * before rescan FCF record table. |
| 19373 | */ |
| 19374 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19375 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19376 | |
| 19377 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19378 | } |
| 19379 | |
| 19380 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19381 | * 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] | 19382 | * @phba: pointer to lpfc hba data structure. |
| 19383 | * |
| 19384 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 19385 | * by the port. |
| 19386 | **/ |
| 19387 | int |
| 19388 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 19389 | { |
| 19390 | LPFC_MBOXQ_t *mbox; |
| 19391 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 19392 | int rc, length; |
| 19393 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19394 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 19395 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 19396 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19397 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19398 | if (!mbox) { |
| 19399 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19400 | "2745 Failed to allocate mbox for " |
| 19401 | "requesting FCF rediscover.\n"); |
| 19402 | return -ENOMEM; |
| 19403 | } |
| 19404 | |
| 19405 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 19406 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 19407 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 19408 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 19409 | length, LPFC_SLI4_MBX_EMBED); |
| 19410 | |
| 19411 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19412 | /* Set count to 0 for invalidating the entire FCF database */ |
| 19413 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 19414 | |
| 19415 | /* Issue the mailbox command asynchronously */ |
| 19416 | mbox->vport = phba->pport; |
| 19417 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 19418 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 19419 | |
| 19420 | if (rc == MBX_NOT_FINISHED) { |
| 19421 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19422 | return -EIO; |
| 19423 | } |
| 19424 | return 0; |
| 19425 | } |
| 19426 | |
| 19427 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19428 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 19429 | * @phba: pointer to lpfc hba data structure. |
| 19430 | * |
| 19431 | * This function is the failover routine as a last resort to the FCF DEAD |
| 19432 | * event when driver failed to perform fast FCF failover. |
| 19433 | **/ |
| 19434 | void |
| 19435 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 19436 | { |
| 19437 | uint32_t link_state; |
| 19438 | |
| 19439 | /* |
| 19440 | * Last resort as FCF DEAD event failover will treat this as |
| 19441 | * a link down, but save the link state because we don't want |
| 19442 | * it to be changed to Link Down unless it is already down. |
| 19443 | */ |
| 19444 | link_state = phba->link_state; |
| 19445 | lpfc_linkdown(phba); |
| 19446 | phba->link_state = link_state; |
| 19447 | |
| 19448 | /* Unregister FCF if no devices connected to it */ |
| 19449 | lpfc_unregister_unused_fcf(phba); |
| 19450 | } |
| 19451 | |
| 19452 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19453 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19454 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19455 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19456 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19457 | * This function gets SLI3 port configure region 23 data through memory dump |
| 19458 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19459 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19460 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19461 | static uint32_t |
| 19462 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19463 | { |
| 19464 | LPFC_MBOXQ_t *pmb = NULL; |
| 19465 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19466 | uint32_t offset = 0; |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 19467 | int i, rc; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19468 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19469 | if (!rgn23_data) |
| 19470 | return 0; |
| 19471 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19472 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19473 | if (!pmb) { |
| 19474 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19475 | "2600 failed to allocate mailbox memory\n"); |
| 19476 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19477 | } |
| 19478 | mb = &pmb->u.mb; |
| 19479 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19480 | do { |
| 19481 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 19482 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 19483 | |
| 19484 | if (rc != MBX_SUCCESS) { |
| 19485 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19486 | "2601 failed to read config " |
| 19487 | "region 23, rc 0x%x Status 0x%x\n", |
| 19488 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19489 | mb->un.varDmp.word_cnt = 0; |
| 19490 | } |
| 19491 | /* |
| 19492 | * dump mem may return a zero when finished or we got a |
| 19493 | * mailbox error, either way we are done. |
| 19494 | */ |
| 19495 | if (mb->un.varDmp.word_cnt == 0) |
| 19496 | break; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19497 | |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 19498 | i = mb->un.varDmp.word_cnt * sizeof(uint32_t); |
| 19499 | if (offset + i > DMP_RGN23_SIZE) |
| 19500 | i = DMP_RGN23_SIZE - offset; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19501 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 19502 | rgn23_data + offset, i); |
| 19503 | offset += i; |
| 19504 | } while (offset < DMP_RGN23_SIZE); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19505 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19506 | mempool_free(pmb, phba->mbox_mem_pool); |
| 19507 | return offset; |
| 19508 | } |
| 19509 | |
| 19510 | /** |
| 19511 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 19512 | * @phba: pointer to lpfc hba data structure. |
| 19513 | * @rgn23_data: pointer to configure region 23 data. |
| 19514 | * |
| 19515 | * This function gets SLI4 port configure region 23 data through memory dump |
| 19516 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19517 | * will be returned, otherwise, 0 will be returned. |
| 19518 | **/ |
| 19519 | static uint32_t |
| 19520 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 19521 | { |
| 19522 | LPFC_MBOXQ_t *mboxq = NULL; |
| 19523 | struct lpfc_dmabuf *mp = NULL; |
| 19524 | struct lpfc_mqe *mqe; |
| 19525 | uint32_t data_length = 0; |
| 19526 | int rc; |
| 19527 | |
| 19528 | if (!rgn23_data) |
| 19529 | return 0; |
| 19530 | |
| 19531 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19532 | if (!mboxq) { |
| 19533 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19534 | "3105 failed to allocate mailbox memory\n"); |
| 19535 | return 0; |
| 19536 | } |
| 19537 | |
| 19538 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19539 | goto out; |
| 19540 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19541 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19542 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19543 | if (rc) |
| 19544 | goto out; |
| 19545 | data_length = mqe->un.mb_words[5]; |
| 19546 | if (data_length == 0) |
| 19547 | goto out; |
| 19548 | if (data_length > DMP_RGN23_SIZE) { |
| 19549 | data_length = 0; |
| 19550 | goto out; |
| 19551 | } |
| 19552 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19553 | out: |
| 19554 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19555 | if (mp) { |
| 19556 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19557 | kfree(mp); |
| 19558 | } |
| 19559 | return data_length; |
| 19560 | } |
| 19561 | |
| 19562 | /** |
| 19563 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19564 | * @phba: pointer to lpfc hba data structure. |
| 19565 | * |
| 19566 | * This function read region 23 and parse TLV for port status to |
| 19567 | * decide if the user disaled the port. If the TLV indicates the |
| 19568 | * port is disabled, the hba_flag is set accordingly. |
| 19569 | **/ |
| 19570 | void |
| 19571 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19572 | { |
| 19573 | uint8_t *rgn23_data = NULL; |
| 19574 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19575 | uint32_t offset = 0; |
| 19576 | |
| 19577 | /* Get adapter Region 23 data */ |
| 19578 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19579 | if (!rgn23_data) |
| 19580 | goto out; |
| 19581 | |
| 19582 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19583 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19584 | else { |
| 19585 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19586 | &phba->sli4_hba.sli_intf); |
| 19587 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19588 | goto out; |
| 19589 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19590 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19591 | |
| 19592 | if (!data_size) |
| 19593 | goto out; |
| 19594 | |
| 19595 | /* Check the region signature first */ |
| 19596 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 19597 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19598 | "2619 Config region 23 has bad signature\n"); |
| 19599 | goto out; |
| 19600 | } |
| 19601 | offset += 4; |
| 19602 | |
| 19603 | /* Check the data structure version */ |
| 19604 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 19605 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19606 | "2620 Config region 23 has bad version\n"); |
| 19607 | goto out; |
| 19608 | } |
| 19609 | offset += 4; |
| 19610 | |
| 19611 | /* Parse TLV entries in the region */ |
| 19612 | while (offset < data_size) { |
| 19613 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19614 | break; |
| 19615 | /* |
| 19616 | * If the TLV is not driver specific TLV or driver id is |
| 19617 | * not linux driver id, skip the record. |
| 19618 | */ |
| 19619 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19620 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19621 | (rgn23_data[offset + 3] != 0)) { |
| 19622 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19623 | continue; |
| 19624 | } |
| 19625 | |
| 19626 | /* Driver found a driver specific TLV in the config region */ |
| 19627 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19628 | offset += 4; |
| 19629 | tlv_offset = 0; |
| 19630 | |
| 19631 | /* |
| 19632 | * Search for configured port state sub-TLV. |
| 19633 | */ |
| 19634 | while ((offset < data_size) && |
| 19635 | (tlv_offset < sub_tlv_len)) { |
| 19636 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19637 | offset += 4; |
| 19638 | tlv_offset += 4; |
| 19639 | break; |
| 19640 | } |
| 19641 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19642 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19643 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19644 | continue; |
| 19645 | } |
| 19646 | |
| 19647 | /* This HBA contains PORT_STE configured */ |
| 19648 | if (!rgn23_data[offset + 2]) |
| 19649 | phba->hba_flag |= LINK_DISABLED; |
| 19650 | |
| 19651 | goto out; |
| 19652 | } |
| 19653 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19654 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19655 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19656 | kfree(rgn23_data); |
| 19657 | return; |
| 19658 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19659 | |
| 19660 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19661 | * lpfc_wr_object - write an object to the firmware |
| 19662 | * @phba: HBA structure that indicates port to create a queue on. |
| 19663 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19664 | * @size: the total byte value of the objects to write to the port. |
| 19665 | * @offset: the current offset to be used to start the transfer. |
| 19666 | * |
| 19667 | * This routine will create a wr_object mailbox command to send to the port. |
| 19668 | * the mailbox command will be constructed using the dma buffers described in |
| 19669 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19670 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19671 | * used to indicate the starting offset of the transfer and will also return |
| 19672 | * the offset after the write object mailbox has completed. @size is used to |
| 19673 | * determine the end of the object and whether the eof bit should be set. |
| 19674 | * |
| 19675 | * Return 0 is successful and offset will contain the the new offset to use |
| 19676 | * for the next write. |
| 19677 | * Return negative value for error cases. |
| 19678 | **/ |
| 19679 | int |
| 19680 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 19681 | uint32_t size, uint32_t *offset) |
| 19682 | { |
| 19683 | struct lpfc_mbx_wr_object *wr_object; |
| 19684 | LPFC_MBOXQ_t *mbox; |
| 19685 | int rc = 0, i = 0; |
James Smart | f3d0a8a | 2019-12-18 15:58:01 -0800 | [diff] [blame] | 19686 | uint32_t shdr_status, shdr_add_status, shdr_change_status, shdr_csf; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19687 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19688 | struct lpfc_dmabuf *dmabuf; |
| 19689 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19690 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19691 | |
| 19692 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19693 | if (!mbox) |
| 19694 | return -ENOMEM; |
| 19695 | |
| 19696 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 19697 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 19698 | sizeof(struct lpfc_mbx_wr_object) - |
| 19699 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 19700 | |
| 19701 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 19702 | wr_object->u.request.write_offset = *offset; |
| 19703 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 19704 | wr_object->u.request.object_name[0] = |
| 19705 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 19706 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 19707 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 19708 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 19709 | break; |
| 19710 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 19711 | wr_object->u.request.bde[i].addrHigh = |
| 19712 | putPaddrHigh(dmabuf->phys); |
| 19713 | if (written + SLI4_PAGE_SIZE >= size) { |
| 19714 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19715 | (size - written); |
| 19716 | written += (size - written); |
| 19717 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19718 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 19719 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19720 | } else { |
| 19721 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19722 | SLI4_PAGE_SIZE; |
| 19723 | written += SLI4_PAGE_SIZE; |
| 19724 | } |
| 19725 | i++; |
| 19726 | } |
| 19727 | wr_object->u.request.bde_count = i; |
| 19728 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 19729 | if (!phba->sli4_hba.intr_enable) |
| 19730 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 19731 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19732 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19733 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 19734 | } |
| 19735 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19736 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19737 | &wr_object->header.cfg_shdr.response); |
| 19738 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19739 | &wr_object->header.cfg_shdr.response); |
| 19740 | if (check_change_status) { |
| 19741 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 19742 | &wr_object->u.response); |
James Smart | f3d0a8a | 2019-12-18 15:58:01 -0800 | [diff] [blame] | 19743 | |
| 19744 | if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET || |
| 19745 | shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) { |
| 19746 | shdr_csf = bf_get(lpfc_wr_object_csf, |
| 19747 | &wr_object->u.response); |
| 19748 | if (shdr_csf) |
| 19749 | shdr_change_status = |
| 19750 | LPFC_CHANGE_STATUS_PCI_RESET; |
| 19751 | } |
| 19752 | |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19753 | switch (shdr_change_status) { |
| 19754 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 19755 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19756 | "3198 Firmware write complete: System " |
| 19757 | "reboot required to instantiate\n"); |
| 19758 | break; |
| 19759 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 19760 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19761 | "3199 Firmware write complete: Firmware" |
| 19762 | " reset required to instantiate\n"); |
| 19763 | break; |
| 19764 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 19765 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19766 | "3200 Firmware write complete: Port " |
| 19767 | "Migration or PCI Reset required to " |
| 19768 | "instantiate\n"); |
| 19769 | break; |
| 19770 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 19771 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19772 | "3201 Firmware write complete: PCI " |
| 19773 | "Reset required to instantiate\n"); |
| 19774 | break; |
| 19775 | default: |
| 19776 | break; |
| 19777 | } |
| 19778 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19779 | if (rc != MBX_TIMEOUT) |
| 19780 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19781 | if (shdr_status || shdr_add_status || rc) { |
| 19782 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19783 | "3025 Write Object mailbox failed with " |
| 19784 | "status x%x add_status x%x, mbx status x%x\n", |
| 19785 | shdr_status, shdr_add_status, rc); |
| 19786 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 19787 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19788 | } else |
| 19789 | *offset += wr_object->u.response.actual_write_length; |
| 19790 | return rc; |
| 19791 | } |
| 19792 | |
| 19793 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19794 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 19795 | * @vport: pointer to vport data structure. |
| 19796 | * |
| 19797 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 19798 | * and REG_VPI mailbox commands associated with the vport. This function |
| 19799 | * is called when driver want to restart discovery of the vport due to |
| 19800 | * a Clear Virtual Link event. |
| 19801 | **/ |
| 19802 | void |
| 19803 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 19804 | { |
| 19805 | struct lpfc_hba *phba = vport->phba; |
| 19806 | LPFC_MBOXQ_t *mb, *nextmb; |
| 19807 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19808 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19809 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19810 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19811 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19812 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19813 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19814 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19815 | spin_lock_irq(&phba->hbalock); |
| 19816 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 19817 | if (mb->vport != vport) |
| 19818 | continue; |
| 19819 | |
| 19820 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19821 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19822 | continue; |
| 19823 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19824 | list_del(&mb->list); |
| 19825 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 19826 | } |
| 19827 | /* Clean up active mailbox command with the vport */ |
| 19828 | mb = phba->sli.mbox_active; |
| 19829 | if (mb && (mb->vport == vport)) { |
| 19830 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 19831 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 19832 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19833 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19834 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19835 | /* Put reference count for delayed processing */ |
| 19836 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 19837 | /* Unregister the RPI when mailbox complete */ |
| 19838 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19839 | } |
| 19840 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19841 | /* Cleanup any mailbox completions which are not yet processed */ |
| 19842 | do { |
| 19843 | restart_loop = 0; |
| 19844 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 19845 | /* |
| 19846 | * If this mailox is already processed or it is |
| 19847 | * for another vport ignore it. |
| 19848 | */ |
| 19849 | if ((mb->vport != vport) || |
| 19850 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 19851 | continue; |
| 19852 | |
| 19853 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19854 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19855 | continue; |
| 19856 | |
| 19857 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19858 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19859 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19860 | /* Unregister the RPI when mailbox complete */ |
| 19861 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19862 | restart_loop = 1; |
| 19863 | spin_unlock_irq(&phba->hbalock); |
| 19864 | spin_lock(shost->host_lock); |
| 19865 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19866 | spin_unlock(shost->host_lock); |
| 19867 | spin_lock_irq(&phba->hbalock); |
| 19868 | break; |
| 19869 | } |
| 19870 | } |
| 19871 | } while (restart_loop); |
| 19872 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19873 | spin_unlock_irq(&phba->hbalock); |
| 19874 | |
| 19875 | /* Release the cleaned-up mailbox commands */ |
| 19876 | while (!list_empty(&mbox_cmd_list)) { |
| 19877 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19878 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19879 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19880 | if (mp) { |
| 19881 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19882 | kfree(mp); |
| 19883 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19884 | mb->ctx_buf = NULL; |
| 19885 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 19886 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19887 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19888 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19889 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19890 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19891 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19892 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19893 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19894 | mempool_free(mb, phba->mbox_mem_pool); |
| 19895 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19896 | |
| 19897 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19898 | if (act_mbx_ndlp) { |
| 19899 | spin_lock(shost->host_lock); |
| 19900 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19901 | spin_unlock(shost->host_lock); |
| 19902 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19903 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19904 | } |
| 19905 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19906 | /** |
| 19907 | * lpfc_drain_txq - Drain the txq |
| 19908 | * @phba: Pointer to HBA context object. |
| 19909 | * |
| 19910 | * This function attempt to submit IOCBs on the txq |
| 19911 | * to the adapter. For SLI4 adapters, the txq contains |
| 19912 | * ELS IOCBs that have been deferred because the there |
| 19913 | * are no SGLs. This congestion can occur with large |
| 19914 | * vport counts during node discovery. |
| 19915 | **/ |
| 19916 | |
| 19917 | uint32_t |
| 19918 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19919 | { |
| 19920 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19921 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19922 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19923 | unsigned long iflags = 0; |
| 19924 | char *fail_msg = NULL; |
| 19925 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19926 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19927 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19928 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19929 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19930 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19931 | /* MDS WQE are posted only to first WQ*/ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19932 | wq = phba->sli4_hba.hdwq[0].io_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19933 | if (unlikely(!wq)) |
| 19934 | return 0; |
| 19935 | pring = wq->pring; |
| 19936 | } else { |
| 19937 | wq = phba->sli4_hba.els_wq; |
| 19938 | if (unlikely(!wq)) |
| 19939 | return 0; |
| 19940 | pring = lpfc_phba_elsring(phba); |
| 19941 | } |
| 19942 | |
| 19943 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19944 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19945 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19946 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19947 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19948 | txq_cnt++; |
| 19949 | } |
| 19950 | |
| 19951 | if (txq_cnt > pring->txq_max) |
| 19952 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19953 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19954 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19955 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19956 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19957 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19958 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19959 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19960 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19961 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19962 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19963 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19964 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19965 | break; |
| 19966 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19967 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19968 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19969 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19970 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19971 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19972 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19973 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19974 | |
| 19975 | /* The xri and iocb resources secured, |
| 19976 | * attempt to issue request |
| 19977 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19978 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19979 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19980 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19981 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19982 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19983 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19984 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19985 | fail_msg = " - Wq is full"; |
| 19986 | else |
| 19987 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19988 | |
| 19989 | if (fail_msg) { |
| 19990 | /* Failed means we can't issue and need to cancel */ |
| 19991 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19992 | "2822 IOCB failed %s iotag 0x%x " |
| 19993 | "xri 0x%x\n", |
| 19994 | fail_msg, |
| 19995 | piocbq->iotag, piocbq->sli4_xritag); |
| 19996 | list_add_tail(&piocbq->list, &completions); |
| 19997 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19998 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19999 | } |
| 20000 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20001 | /* Cancel all the IOCBs that cannot be issued */ |
| 20002 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 20003 | IOERR_SLI_ABORTED); |
| 20004 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 20005 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20006 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20007 | |
| 20008 | /** |
| 20009 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 20010 | * @phba: Pointer to HBA context object. |
| 20011 | * @pwqe: Pointer to command WQE. |
| 20012 | * @sglq: Pointer to the scatter gather queue object. |
| 20013 | * |
| 20014 | * This routine converts the bpl or bde that is in the WQE |
| 20015 | * to a sgl list for the sli4 hardware. The physical address |
| 20016 | * of the bpl/bde is converted back to a virtual address. |
| 20017 | * If the WQE contains a BPL then the list of BDE's is |
| 20018 | * converted to sli4_sge's. If the WQE contains a single |
| 20019 | * BDE then it is converted to a single sli_sge. |
| 20020 | * The WQE is still in cpu endianness so the contents of |
| 20021 | * the bpl can be used without byte swapping. |
| 20022 | * |
| 20023 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 20024 | */ |
| 20025 | static uint16_t |
| 20026 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 20027 | struct lpfc_sglq *sglq) |
| 20028 | { |
| 20029 | uint16_t xritag = NO_XRI; |
| 20030 | struct ulp_bde64 *bpl = NULL; |
| 20031 | struct ulp_bde64 bde; |
| 20032 | struct sli4_sge *sgl = NULL; |
| 20033 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 20034 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20035 | int numBdes = 0; |
| 20036 | int i = 0; |
| 20037 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 20038 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 20039 | uint32_t cmd; |
| 20040 | |
| 20041 | if (!pwqeq || !sglq) |
| 20042 | return xritag; |
| 20043 | |
| 20044 | sgl = (struct sli4_sge *)sglq->sgl; |
| 20045 | wqe = &pwqeq->wqe; |
| 20046 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 20047 | |
| 20048 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 20049 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 20050 | return sglq->sli4_xritag; |
| 20051 | numBdes = pwqeq->rsvd2; |
| 20052 | if (numBdes) { |
| 20053 | /* The addrHigh and addrLow fields within the WQE |
| 20054 | * have not been byteswapped yet so there is no |
| 20055 | * need to swap them back. |
| 20056 | */ |
| 20057 | if (pwqeq->context3) |
| 20058 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 20059 | else |
| 20060 | return xritag; |
| 20061 | |
| 20062 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 20063 | if (!bpl) |
| 20064 | return xritag; |
| 20065 | |
| 20066 | for (i = 0; i < numBdes; i++) { |
| 20067 | /* Should already be byte swapped. */ |
| 20068 | sgl->addr_hi = bpl->addrHigh; |
| 20069 | sgl->addr_lo = bpl->addrLow; |
| 20070 | |
| 20071 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 20072 | if ((i+1) == numBdes) |
| 20073 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 20074 | else |
| 20075 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 20076 | /* swap the size field back to the cpu so we |
| 20077 | * can assign it to the sgl. |
| 20078 | */ |
| 20079 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 20080 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 20081 | /* The offsets in the sgl need to be accumulated |
| 20082 | * separately for the request and reply lists. |
| 20083 | * The request is always first, the reply follows. |
| 20084 | */ |
| 20085 | switch (cmd) { |
| 20086 | case CMD_GEN_REQUEST64_WQE: |
| 20087 | /* add up the reply sg entries */ |
| 20088 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 20089 | inbound++; |
| 20090 | /* first inbound? reset the offset */ |
| 20091 | if (inbound == 1) |
| 20092 | offset = 0; |
| 20093 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 20094 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20095 | LPFC_SGE_TYPE_DATA); |
| 20096 | offset += bde.tus.f.bdeSize; |
| 20097 | break; |
| 20098 | case CMD_FCP_TRSP64_WQE: |
| 20099 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 20100 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20101 | LPFC_SGE_TYPE_DATA); |
| 20102 | break; |
| 20103 | case CMD_FCP_TSEND64_WQE: |
| 20104 | case CMD_FCP_TRECEIVE64_WQE: |
| 20105 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20106 | bpl->tus.f.bdeFlags); |
| 20107 | if (i < 3) |
| 20108 | offset = 0; |
| 20109 | else |
| 20110 | offset += bde.tus.f.bdeSize; |
| 20111 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 20112 | break; |
| 20113 | } |
| 20114 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 20115 | bpl++; |
| 20116 | sgl++; |
| 20117 | } |
| 20118 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 20119 | /* The addrHigh and addrLow fields of the BDE have not |
| 20120 | * been byteswapped yet so they need to be swapped |
| 20121 | * before putting them in the sgl. |
| 20122 | */ |
| 20123 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 20124 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 20125 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 20126 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 20127 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 20128 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 20129 | } |
| 20130 | return sglq->sli4_xritag; |
| 20131 | } |
| 20132 | |
| 20133 | /** |
| 20134 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 20135 | * @phba: Pointer to HBA context object. |
| 20136 | * @ring_number: Base sli ring number |
| 20137 | * @pwqe: Pointer to command WQE. |
| 20138 | **/ |
| 20139 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20140 | 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] | 20141 | struct lpfc_iocbq *pwqe) |
| 20142 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 20143 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | 7cacae2 | 2020-03-31 09:50:03 -0700 | [diff] [blame] | 20144 | struct lpfc_async_xchg_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20145 | struct lpfc_queue *wq; |
| 20146 | struct lpfc_sglq *sglq; |
| 20147 | struct lpfc_sli_ring *pring; |
| 20148 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20149 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20150 | |
| 20151 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 20152 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 20153 | pring = phba->sli4_hba.nvmels_wq->pring; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20154 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20155 | qp, wq_access); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20156 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 20157 | if (!sglq) { |
| 20158 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 20159 | return WQE_BUSY; |
| 20160 | } |
| 20161 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 20162 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 20163 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 20164 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 20165 | return WQE_ERROR; |
| 20166 | } |
| 20167 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 20168 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20169 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 20170 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20171 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20172 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20173 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20174 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20175 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20176 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20177 | |
| 20178 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20179 | return 0; |
| 20180 | } |
| 20181 | |
| 20182 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 20183 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 20184 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20185 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20186 | pring = wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20187 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20188 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20189 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20190 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20191 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20192 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 20193 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20194 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20195 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20196 | } |
| 20197 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20198 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20199 | |
| 20200 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20201 | return 0; |
| 20202 | } |
| 20203 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20204 | /* NVMET requests */ |
| 20205 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 20206 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20207 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20208 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20209 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20210 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 20211 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20212 | if (pwqe->sli4_xritag == NO_XRI) { |
| 20213 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 20214 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 20215 | } |
| 20216 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 20217 | pwqe->sli4_xritag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20218 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20219 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20220 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20221 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20222 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 20223 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20224 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20225 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20226 | } |
| 20227 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20228 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20229 | |
| 20230 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20231 | return 0; |
| 20232 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20233 | return WQE_ERROR; |
| 20234 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20235 | |
| 20236 | #ifdef LPFC_MXP_STAT |
| 20237 | /** |
| 20238 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 20239 | * @phba: pointer to lpfc hba data structure. |
| 20240 | * @hwqid: belong to which HWQ. |
| 20241 | * |
| 20242 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 20243 | * 15 seconds after a test case is running. |
| 20244 | * |
| 20245 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 20246 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 20247 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 20248 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 20249 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 20250 | **/ |
| 20251 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 20252 | { |
| 20253 | struct lpfc_sli4_hdw_queue *qp; |
| 20254 | struct lpfc_multixri_pool *multixri_pool; |
| 20255 | struct lpfc_pvt_pool *pvt_pool; |
| 20256 | struct lpfc_pbl_pool *pbl_pool; |
| 20257 | u32 txcmplq_cnt; |
| 20258 | |
| 20259 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20260 | multixri_pool = qp->p_multixri_pool; |
| 20261 | if (!multixri_pool) |
| 20262 | return; |
| 20263 | |
| 20264 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 20265 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20266 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20267 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20268 | |
| 20269 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 20270 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 20271 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 20272 | } |
| 20273 | |
| 20274 | multixri_pool->stat_snapshot_taken++; |
| 20275 | } |
| 20276 | #endif |
| 20277 | |
| 20278 | /** |
| 20279 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 20280 | * @phba: pointer to lpfc hba data structure. |
| 20281 | * @hwqid: belong to which HWQ. |
| 20282 | * |
| 20283 | * This routine moves some XRIs from private to public pool when private pool |
| 20284 | * is not busy. |
| 20285 | **/ |
| 20286 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 20287 | { |
| 20288 | struct lpfc_multixri_pool *multixri_pool; |
| 20289 | u32 io_req_count; |
| 20290 | u32 prev_io_req_count; |
| 20291 | |
| 20292 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20293 | if (!multixri_pool) |
| 20294 | return; |
| 20295 | io_req_count = multixri_pool->io_req_count; |
| 20296 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 20297 | |
| 20298 | if (prev_io_req_count != io_req_count) { |
| 20299 | /* Private pool is busy */ |
| 20300 | multixri_pool->prev_io_req_count = io_req_count; |
| 20301 | } else { |
| 20302 | /* Private pool is not busy. |
| 20303 | * Move XRIs from private to public pool. |
| 20304 | */ |
| 20305 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 20306 | } |
| 20307 | } |
| 20308 | |
| 20309 | /** |
| 20310 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 20311 | * @phba: pointer to lpfc hba data structure. |
| 20312 | * @hwqid: belong to which HWQ. |
| 20313 | * |
| 20314 | * This routine sets high watermark as number of outstanding XRIs, |
| 20315 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 20316 | **/ |
| 20317 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 20318 | { |
| 20319 | u32 new_watermark; |
| 20320 | u32 watermark_max; |
| 20321 | u32 watermark_min; |
| 20322 | u32 xri_limit; |
| 20323 | u32 txcmplq_cnt; |
| 20324 | u32 abts_io_bufs; |
| 20325 | struct lpfc_multixri_pool *multixri_pool; |
| 20326 | struct lpfc_sli4_hdw_queue *qp; |
| 20327 | |
| 20328 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20329 | multixri_pool = qp->p_multixri_pool; |
| 20330 | if (!multixri_pool) |
| 20331 | return; |
| 20332 | xri_limit = multixri_pool->xri_limit; |
| 20333 | |
| 20334 | watermark_max = xri_limit; |
| 20335 | watermark_min = xri_limit / 2; |
| 20336 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20337 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20338 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20339 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20340 | |
| 20341 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 20342 | new_watermark = min(watermark_max, new_watermark); |
| 20343 | new_watermark = max(watermark_min, new_watermark); |
| 20344 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 20345 | |
| 20346 | #ifdef LPFC_MXP_STAT |
| 20347 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 20348 | new_watermark); |
| 20349 | #endif |
| 20350 | } |
| 20351 | |
| 20352 | /** |
| 20353 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 20354 | * @phba: pointer to lpfc hba data structure. |
| 20355 | * @hwqid: belong to which HWQ. |
| 20356 | * |
| 20357 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 20358 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 20359 | * The first step moves (all - low_watermark) amount of XRIs. |
| 20360 | * The second step moves the rest of XRIs. |
| 20361 | **/ |
| 20362 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 20363 | { |
| 20364 | struct lpfc_pbl_pool *pbl_pool; |
| 20365 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20366 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20367 | struct lpfc_io_buf *lpfc_ncmd; |
| 20368 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20369 | unsigned long iflag; |
| 20370 | struct list_head tmp_list; |
| 20371 | u32 tmp_count; |
| 20372 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20373 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20374 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20375 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20376 | tmp_count = 0; |
| 20377 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20378 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 20379 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20380 | |
| 20381 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 20382 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 20383 | * to pbl_pool |
| 20384 | */ |
| 20385 | |
| 20386 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 20387 | INIT_LIST_HEAD(&tmp_list); |
| 20388 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20389 | &pvt_pool->list, list) { |
| 20390 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 20391 | tmp_count++; |
| 20392 | if (tmp_count >= pvt_pool->low_watermark) |
| 20393 | break; |
| 20394 | } |
| 20395 | |
| 20396 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 20397 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 20398 | |
| 20399 | /* Move all bufs from tmp_list to pvt_pool */ |
| 20400 | list_splice(&tmp_list, &pvt_pool->list); |
| 20401 | |
| 20402 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 20403 | pvt_pool->count = tmp_count; |
| 20404 | } else { |
| 20405 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 20406 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 20407 | pbl_pool->count += pvt_pool->count; |
| 20408 | pvt_pool->count = 0; |
| 20409 | } |
| 20410 | |
| 20411 | spin_unlock(&pvt_pool->lock); |
| 20412 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20413 | } |
| 20414 | |
| 20415 | /** |
| 20416 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20417 | * @phba: pointer to lpfc hba data structure |
| 20418 | * @pbl_pool: specified public free XRI pool |
| 20419 | * @pvt_pool: specified private free XRI pool |
| 20420 | * @count: number of XRIs to move |
| 20421 | * |
| 20422 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 20423 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 20424 | * enough in public pool. |
| 20425 | * |
| 20426 | * Return: |
| 20427 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 20428 | * specified pvt_pool |
| 20429 | * false - if the specified pbl_pool is empty or locked by someone else |
| 20430 | **/ |
| 20431 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20432 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 20433 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20434 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 20435 | { |
| 20436 | struct lpfc_io_buf *lpfc_ncmd; |
| 20437 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20438 | unsigned long iflag; |
| 20439 | int ret; |
| 20440 | |
| 20441 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 20442 | if (ret) { |
| 20443 | if (pbl_pool->count) { |
| 20444 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20445 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20446 | list_for_each_entry_safe(lpfc_ncmd, |
| 20447 | lpfc_ncmd_next, |
| 20448 | &pbl_pool->list, |
| 20449 | list) { |
| 20450 | list_move_tail(&lpfc_ncmd->list, |
| 20451 | &pvt_pool->list); |
| 20452 | pvt_pool->count++; |
| 20453 | pbl_pool->count--; |
| 20454 | count--; |
| 20455 | if (count == 0) |
| 20456 | break; |
| 20457 | } |
| 20458 | |
| 20459 | spin_unlock(&pvt_pool->lock); |
| 20460 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20461 | return true; |
| 20462 | } |
| 20463 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20464 | } |
| 20465 | |
| 20466 | return false; |
| 20467 | } |
| 20468 | |
| 20469 | /** |
| 20470 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20471 | * @phba: pointer to lpfc hba data structure. |
| 20472 | * @hwqid: belong to which HWQ. |
| 20473 | * @count: number of XRIs to move |
| 20474 | * |
| 20475 | * This routine tries to find some free common bufs in one of public pools with |
| 20476 | * Round Robin method. The search always starts from local hwqid, then the next |
| 20477 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 20478 | * a batch of free common bufs are moved to private pool on hwqid. |
| 20479 | * It might move less than count XRIs if there's not enough in public pool. |
| 20480 | **/ |
| 20481 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 20482 | { |
| 20483 | struct lpfc_multixri_pool *multixri_pool; |
| 20484 | struct lpfc_multixri_pool *next_multixri_pool; |
| 20485 | struct lpfc_pvt_pool *pvt_pool; |
| 20486 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20487 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20488 | u32 next_hwqid; |
| 20489 | u32 hwq_count; |
| 20490 | int ret; |
| 20491 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20492 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20493 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20494 | pvt_pool = &multixri_pool->pvt_pool; |
| 20495 | pbl_pool = &multixri_pool->pbl_pool; |
| 20496 | |
| 20497 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20498 | 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] | 20499 | if (ret) { |
| 20500 | #ifdef LPFC_MXP_STAT |
| 20501 | multixri_pool->local_pbl_hit_count++; |
| 20502 | #endif |
| 20503 | return; |
| 20504 | } |
| 20505 | |
| 20506 | hwq_count = phba->cfg_hdw_queue; |
| 20507 | |
| 20508 | /* Get the next hwqid which was found last time */ |
| 20509 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 20510 | |
| 20511 | do { |
| 20512 | /* Go to next hwq */ |
| 20513 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 20514 | |
| 20515 | next_multixri_pool = |
| 20516 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 20517 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 20518 | |
| 20519 | /* Check if the public free xri pool is available */ |
| 20520 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20521 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20522 | |
| 20523 | /* Exit while-loop if success or all hwqid are checked */ |
| 20524 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 20525 | |
| 20526 | /* Starting point for the next time */ |
| 20527 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 20528 | |
| 20529 | if (!ret) { |
| 20530 | /* stats: all public pools are empty*/ |
| 20531 | multixri_pool->pbl_empty_count++; |
| 20532 | } |
| 20533 | |
| 20534 | #ifdef LPFC_MXP_STAT |
| 20535 | if (ret) { |
| 20536 | if (next_hwqid == hwqid) |
| 20537 | multixri_pool->local_pbl_hit_count++; |
| 20538 | else |
| 20539 | multixri_pool->other_pbl_hit_count++; |
| 20540 | } |
| 20541 | #endif |
| 20542 | } |
| 20543 | |
| 20544 | /** |
| 20545 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 20546 | * @phba: pointer to lpfc hba data structure. |
| 20547 | * @qp: belong to which HWQ. |
| 20548 | * |
| 20549 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 20550 | * low watermark. |
| 20551 | **/ |
| 20552 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 20553 | { |
| 20554 | struct lpfc_multixri_pool *multixri_pool; |
| 20555 | struct lpfc_pvt_pool *pvt_pool; |
| 20556 | |
| 20557 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20558 | pvt_pool = &multixri_pool->pvt_pool; |
| 20559 | |
| 20560 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 20561 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20562 | } |
| 20563 | |
| 20564 | /** |
| 20565 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 20566 | * @phba: pointer to lpfc hba data structure. |
| 20567 | * @lpfc_ncmd: IO buf to be returned. |
| 20568 | * @qp: belong to which HWQ. |
| 20569 | * |
| 20570 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 20571 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 20572 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 20573 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 20574 | * lpfc_io_buf_list_put. |
| 20575 | **/ |
| 20576 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 20577 | struct lpfc_sli4_hdw_queue *qp) |
| 20578 | { |
| 20579 | unsigned long iflag; |
| 20580 | struct lpfc_pbl_pool *pbl_pool; |
| 20581 | struct lpfc_pvt_pool *pvt_pool; |
| 20582 | struct lpfc_epd_pool *epd_pool; |
| 20583 | u32 txcmplq_cnt; |
| 20584 | u32 xri_owned; |
| 20585 | u32 xri_limit; |
| 20586 | u32 abts_io_bufs; |
| 20587 | |
| 20588 | /* MUST zero fields if buffer is reused by another protocol */ |
| 20589 | lpfc_ncmd->nvmeCmd = NULL; |
| 20590 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 20591 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 20592 | |
James Smart | 35a635a | 2019-09-21 20:59:02 -0700 | [diff] [blame] | 20593 | if (phba->cfg_xpsgl && !phba->nvmet_support && |
| 20594 | !list_empty(&lpfc_ncmd->dma_sgl_xtra_list)) |
| 20595 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 20596 | |
| 20597 | if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list)) |
| 20598 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
| 20599 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20600 | if (phba->cfg_xri_rebalancing) { |
| 20601 | if (lpfc_ncmd->expedite) { |
| 20602 | /* Return to expedite pool */ |
| 20603 | epd_pool = &phba->epd_pool; |
| 20604 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20605 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 20606 | epd_pool->count++; |
| 20607 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20608 | return; |
| 20609 | } |
| 20610 | |
| 20611 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 20612 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 20613 | * Nothing much can be done at this point. |
| 20614 | */ |
| 20615 | if (!qp->p_multixri_pool) |
| 20616 | return; |
| 20617 | |
| 20618 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20619 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20620 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20621 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20622 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20623 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20624 | |
| 20625 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 20626 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 20627 | |
| 20628 | #ifdef LPFC_MXP_STAT |
| 20629 | if (xri_owned <= xri_limit) |
| 20630 | qp->p_multixri_pool->below_limit_count++; |
| 20631 | else |
| 20632 | qp->p_multixri_pool->above_limit_count++; |
| 20633 | #endif |
| 20634 | |
| 20635 | /* XRI goes to either public or private free xri pool |
| 20636 | * based on watermark and xri_limit |
| 20637 | */ |
| 20638 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 20639 | (xri_owned < xri_limit && |
| 20640 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20641 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 20642 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20643 | list_add_tail(&lpfc_ncmd->list, |
| 20644 | &pvt_pool->list); |
| 20645 | pvt_pool->count++; |
| 20646 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20647 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20648 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 20649 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20650 | list_add_tail(&lpfc_ncmd->list, |
| 20651 | &pbl_pool->list); |
| 20652 | pbl_pool->count++; |
| 20653 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20654 | } |
| 20655 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20656 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 20657 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20658 | list_add_tail(&lpfc_ncmd->list, |
| 20659 | &qp->lpfc_io_buf_list_put); |
| 20660 | qp->put_io_bufs++; |
| 20661 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 20662 | iflag); |
| 20663 | } |
| 20664 | } |
| 20665 | |
| 20666 | /** |
| 20667 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 20668 | * @phba: pointer to lpfc hba data structure. |
| 20669 | * @pvt_pool: pointer to private pool data structure. |
| 20670 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20671 | * |
| 20672 | * This routine tries to get one free IO buf from private pool. |
| 20673 | * |
| 20674 | * Return: |
| 20675 | * pointer to one free IO buf - if private pool is not empty |
| 20676 | * NULL - if private pool is empty |
| 20677 | **/ |
| 20678 | static struct lpfc_io_buf * |
| 20679 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20680 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20681 | struct lpfc_pvt_pool *pvt_pool, |
| 20682 | struct lpfc_nodelist *ndlp) |
| 20683 | { |
| 20684 | struct lpfc_io_buf *lpfc_ncmd; |
| 20685 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20686 | unsigned long iflag; |
| 20687 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20688 | 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] | 20689 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20690 | &pvt_pool->list, list) { |
| 20691 | if (lpfc_test_rrq_active( |
| 20692 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 20693 | continue; |
| 20694 | list_del(&lpfc_ncmd->list); |
| 20695 | pvt_pool->count--; |
| 20696 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20697 | return lpfc_ncmd; |
| 20698 | } |
| 20699 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20700 | |
| 20701 | return NULL; |
| 20702 | } |
| 20703 | |
| 20704 | /** |
| 20705 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 20706 | * @phba: pointer to lpfc hba data structure. |
| 20707 | * |
| 20708 | * This routine tries to get one free IO buf from expedite pool. |
| 20709 | * |
| 20710 | * Return: |
| 20711 | * pointer to one free IO buf - if expedite pool is not empty |
| 20712 | * NULL - if expedite pool is empty |
| 20713 | **/ |
| 20714 | static struct lpfc_io_buf * |
| 20715 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 20716 | { |
| 20717 | struct lpfc_io_buf *lpfc_ncmd; |
| 20718 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20719 | unsigned long iflag; |
| 20720 | struct lpfc_epd_pool *epd_pool; |
| 20721 | |
| 20722 | epd_pool = &phba->epd_pool; |
| 20723 | lpfc_ncmd = NULL; |
| 20724 | |
| 20725 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20726 | if (epd_pool->count > 0) { |
| 20727 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20728 | &epd_pool->list, list) { |
| 20729 | list_del(&lpfc_ncmd->list); |
| 20730 | epd_pool->count--; |
| 20731 | break; |
| 20732 | } |
| 20733 | } |
| 20734 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20735 | |
| 20736 | return lpfc_ncmd; |
| 20737 | } |
| 20738 | |
| 20739 | /** |
| 20740 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 20741 | * @phba: pointer to lpfc hba data structure. |
| 20742 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20743 | * @hwqid: belong to which HWQ |
| 20744 | * @expedite: 1 means this request is urgent. |
| 20745 | * |
| 20746 | * This routine will do the following actions and then return a pointer to |
| 20747 | * one free IO buf. |
| 20748 | * |
| 20749 | * 1. If private free xri count is empty, move some XRIs from public to |
| 20750 | * private pool. |
| 20751 | * 2. Get one XRI from private free xri pool. |
| 20752 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 20753 | * get one free xri from expedite pool. |
| 20754 | * |
| 20755 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20756 | * The caller should pass NULL for ndlp on NVME side. |
| 20757 | * |
| 20758 | * Return: |
| 20759 | * pointer to one free IO buf - if private pool is not empty |
| 20760 | * NULL - if private pool is empty |
| 20761 | **/ |
| 20762 | static struct lpfc_io_buf * |
| 20763 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 20764 | struct lpfc_nodelist *ndlp, |
| 20765 | int hwqid, int expedite) |
| 20766 | { |
| 20767 | struct lpfc_sli4_hdw_queue *qp; |
| 20768 | struct lpfc_multixri_pool *multixri_pool; |
| 20769 | struct lpfc_pvt_pool *pvt_pool; |
| 20770 | struct lpfc_io_buf *lpfc_ncmd; |
| 20771 | |
| 20772 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20773 | lpfc_ncmd = NULL; |
| 20774 | multixri_pool = qp->p_multixri_pool; |
| 20775 | pvt_pool = &multixri_pool->pvt_pool; |
| 20776 | multixri_pool->io_req_count++; |
| 20777 | |
| 20778 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 20779 | if (pvt_pool->count == 0) |
| 20780 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20781 | |
| 20782 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20783 | 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] | 20784 | |
| 20785 | if (lpfc_ncmd) { |
| 20786 | lpfc_ncmd->hdwq = qp; |
| 20787 | lpfc_ncmd->hdwq_no = hwqid; |
| 20788 | } else if (expedite) { |
| 20789 | /* If we fail to get one from pvt_pool and this is an expedite |
| 20790 | * request, get one free xri from expedite pool. |
| 20791 | */ |
| 20792 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 20793 | } |
| 20794 | |
| 20795 | return lpfc_ncmd; |
| 20796 | } |
| 20797 | |
| 20798 | static inline struct lpfc_io_buf * |
| 20799 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 20800 | { |
| 20801 | struct lpfc_sli4_hdw_queue *qp; |
| 20802 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 20803 | |
| 20804 | qp = &phba->sli4_hba.hdwq[idx]; |
| 20805 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 20806 | &qp->lpfc_io_buf_list_get, list) { |
| 20807 | if (lpfc_test_rrq_active(phba, ndlp, |
| 20808 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 20809 | continue; |
| 20810 | |
| 20811 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 20812 | continue; |
| 20813 | |
| 20814 | list_del_init(&lpfc_cmd->list); |
| 20815 | qp->get_io_bufs--; |
| 20816 | lpfc_cmd->hdwq = qp; |
| 20817 | lpfc_cmd->hdwq_no = idx; |
| 20818 | return lpfc_cmd; |
| 20819 | } |
| 20820 | return NULL; |
| 20821 | } |
| 20822 | |
| 20823 | /** |
| 20824 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 20825 | * @phba: The HBA for which this call is being executed. |
| 20826 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20827 | * @hwqid: belong to which HWQ |
| 20828 | * @expedite: 1 means this request is urgent. |
| 20829 | * |
| 20830 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 20831 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 20832 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 20833 | * |
| 20834 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20835 | * The caller should pass NULL for ndlp on NVME side. |
| 20836 | * |
| 20837 | * Return codes: |
| 20838 | * NULL - Error |
| 20839 | * Pointer to lpfc_io_buf - Success |
| 20840 | **/ |
| 20841 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 20842 | struct lpfc_nodelist *ndlp, |
| 20843 | u32 hwqid, int expedite) |
| 20844 | { |
| 20845 | struct lpfc_sli4_hdw_queue *qp; |
| 20846 | unsigned long iflag; |
| 20847 | struct lpfc_io_buf *lpfc_cmd; |
| 20848 | |
| 20849 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20850 | lpfc_cmd = NULL; |
| 20851 | |
| 20852 | if (phba->cfg_xri_rebalancing) |
| 20853 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 20854 | phba, ndlp, hwqid, expedite); |
| 20855 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20856 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 20857 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20858 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 20859 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20860 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20861 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 20862 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20863 | list_splice(&qp->lpfc_io_buf_list_put, |
| 20864 | &qp->lpfc_io_buf_list_get); |
| 20865 | qp->get_io_bufs += qp->put_io_bufs; |
| 20866 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 20867 | qp->put_io_bufs = 0; |
| 20868 | spin_unlock(&qp->io_buf_list_put_lock); |
| 20869 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 20870 | expedite) |
| 20871 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20872 | } |
| 20873 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 20874 | } |
| 20875 | |
| 20876 | return lpfc_cmd; |
| 20877 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20878 | |
| 20879 | /** |
| 20880 | * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool |
| 20881 | * @phba: The HBA for which this call is being executed. |
| 20882 | * @lpfc_buf: IO buf structure to append the SGL chunk |
| 20883 | * |
| 20884 | * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool, |
| 20885 | * and will allocate an SGL chunk if the pool is empty. |
| 20886 | * |
| 20887 | * Return codes: |
| 20888 | * NULL - Error |
| 20889 | * Pointer to sli4_hybrid_sgl - Success |
| 20890 | **/ |
| 20891 | struct sli4_hybrid_sgl * |
| 20892 | lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20893 | { |
| 20894 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20895 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20896 | struct sli4_hybrid_sgl *allocated_sgl = NULL; |
| 20897 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20898 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20899 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20900 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20901 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20902 | |
| 20903 | if (likely(!list_empty(buf_list))) { |
| 20904 | /* break off 1 chunk from the sgl_list */ |
| 20905 | list_for_each_entry_safe(list_entry, tmp, |
| 20906 | buf_list, list_node) { |
| 20907 | list_move_tail(&list_entry->list_node, |
| 20908 | &lpfc_buf->dma_sgl_xtra_list); |
| 20909 | break; |
| 20910 | } |
| 20911 | } else { |
| 20912 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20913 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20914 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 20915 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20916 | if (!tmp) { |
| 20917 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20918 | "8353 error kmalloc memory for HDWQ " |
| 20919 | "%d %s\n", |
| 20920 | lpfc_buf->hdwq_no, __func__); |
| 20921 | return NULL; |
| 20922 | } |
| 20923 | |
| 20924 | tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, |
| 20925 | GFP_ATOMIC, &tmp->dma_phys_sgl); |
| 20926 | if (!tmp->dma_sgl) { |
| 20927 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20928 | "8354 error pool_alloc memory for HDWQ " |
| 20929 | "%d %s\n", |
| 20930 | lpfc_buf->hdwq_no, __func__); |
| 20931 | kfree(tmp); |
| 20932 | return NULL; |
| 20933 | } |
| 20934 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20935 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20936 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list); |
| 20937 | } |
| 20938 | |
| 20939 | allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list, |
| 20940 | struct sli4_hybrid_sgl, |
| 20941 | list_node); |
| 20942 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20943 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20944 | |
| 20945 | return allocated_sgl; |
| 20946 | } |
| 20947 | |
| 20948 | /** |
| 20949 | * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool |
| 20950 | * @phba: The HBA for which this call is being executed. |
| 20951 | * @lpfc_buf: IO buf structure with the SGL chunk |
| 20952 | * |
| 20953 | * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool. |
| 20954 | * |
| 20955 | * Return codes: |
| 20956 | * 0 - Success |
| 20957 | * -EINVAL - Error |
| 20958 | **/ |
| 20959 | int |
| 20960 | lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20961 | { |
| 20962 | int rc = 0; |
| 20963 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20964 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20965 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20966 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20967 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20968 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20969 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20970 | |
| 20971 | if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) { |
| 20972 | list_for_each_entry_safe(list_entry, tmp, |
| 20973 | &lpfc_buf->dma_sgl_xtra_list, |
| 20974 | list_node) { |
| 20975 | list_move_tail(&list_entry->list_node, |
| 20976 | buf_list); |
| 20977 | } |
| 20978 | } else { |
| 20979 | rc = -EINVAL; |
| 20980 | } |
| 20981 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20982 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20983 | return rc; |
| 20984 | } |
| 20985 | |
| 20986 | /** |
| 20987 | * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool |
| 20988 | * @phba: phba object |
| 20989 | * @hdwq: hdwq to cleanup sgl buff resources on |
| 20990 | * |
| 20991 | * This routine frees all SGL chunks of hdwq SGL chunk pool. |
| 20992 | * |
| 20993 | * Return codes: |
| 20994 | * None |
| 20995 | **/ |
| 20996 | void |
| 20997 | lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba, |
| 20998 | struct lpfc_sli4_hdw_queue *hdwq) |
| 20999 | { |
| 21000 | struct list_head *buf_list = &hdwq->sgl_list; |
| 21001 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 21002 | struct sli4_hybrid_sgl *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21003 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21004 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21005 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21006 | |
| 21007 | /* Free sgl pool */ |
| 21008 | list_for_each_entry_safe(list_entry, tmp, |
| 21009 | buf_list, list_node) { |
| 21010 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 21011 | list_entry->dma_sgl, |
| 21012 | list_entry->dma_phys_sgl); |
| 21013 | list_del(&list_entry->list_node); |
| 21014 | kfree(list_entry); |
| 21015 | } |
| 21016 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21017 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21018 | } |
| 21019 | |
| 21020 | /** |
| 21021 | * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq |
| 21022 | * @phba: The HBA for which this call is being executed. |
| 21023 | * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer |
| 21024 | * |
| 21025 | * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool, |
| 21026 | * and will allocate an CMD/RSP buffer if the pool is empty. |
| 21027 | * |
| 21028 | * Return codes: |
| 21029 | * NULL - Error |
| 21030 | * Pointer to fcp_cmd_rsp_buf - Success |
| 21031 | **/ |
| 21032 | struct fcp_cmd_rsp_buf * |
| 21033 | lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 21034 | struct lpfc_io_buf *lpfc_buf) |
| 21035 | { |
| 21036 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 21037 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 21038 | struct fcp_cmd_rsp_buf *allocated_buf = NULL; |
| 21039 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 21040 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21041 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21042 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21043 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21044 | |
| 21045 | if (likely(!list_empty(buf_list))) { |
| 21046 | /* break off 1 chunk from the list */ |
| 21047 | list_for_each_entry_safe(list_entry, tmp, |
| 21048 | buf_list, |
| 21049 | list_node) { |
| 21050 | list_move_tail(&list_entry->list_node, |
| 21051 | &lpfc_buf->dma_cmd_rsp_list); |
| 21052 | break; |
| 21053 | } |
| 21054 | } else { |
| 21055 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21056 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21057 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 21058 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21059 | if (!tmp) { |
| 21060 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 21061 | "8355 error kmalloc memory for HDWQ " |
| 21062 | "%d %s\n", |
| 21063 | lpfc_buf->hdwq_no, __func__); |
| 21064 | return NULL; |
| 21065 | } |
| 21066 | |
| 21067 | tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool, |
| 21068 | GFP_ATOMIC, |
| 21069 | &tmp->fcp_cmd_rsp_dma_handle); |
| 21070 | |
| 21071 | if (!tmp->fcp_cmnd) { |
| 21072 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 21073 | "8356 error pool_alloc memory for HDWQ " |
| 21074 | "%d %s\n", |
| 21075 | lpfc_buf->hdwq_no, __func__); |
| 21076 | kfree(tmp); |
| 21077 | return NULL; |
| 21078 | } |
| 21079 | |
| 21080 | tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd + |
| 21081 | sizeof(struct fcp_cmnd)); |
| 21082 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21083 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21084 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list); |
| 21085 | } |
| 21086 | |
| 21087 | allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list, |
| 21088 | struct fcp_cmd_rsp_buf, |
| 21089 | list_node); |
| 21090 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21091 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21092 | |
| 21093 | return allocated_buf; |
| 21094 | } |
| 21095 | |
| 21096 | /** |
| 21097 | * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool |
| 21098 | * @phba: The HBA for which this call is being executed. |
| 21099 | * @lpfc_buf: IO buf structure with the CMD/RSP buf |
| 21100 | * |
| 21101 | * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool. |
| 21102 | * |
| 21103 | * Return codes: |
| 21104 | * 0 - Success |
| 21105 | * -EINVAL - Error |
| 21106 | **/ |
| 21107 | int |
| 21108 | lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 21109 | struct lpfc_io_buf *lpfc_buf) |
| 21110 | { |
| 21111 | int rc = 0; |
| 21112 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 21113 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 21114 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 21115 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21116 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21117 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21118 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21119 | |
| 21120 | if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) { |
| 21121 | list_for_each_entry_safe(list_entry, tmp, |
| 21122 | &lpfc_buf->dma_cmd_rsp_list, |
| 21123 | list_node) { |
| 21124 | list_move_tail(&list_entry->list_node, |
| 21125 | buf_list); |
| 21126 | } |
| 21127 | } else { |
| 21128 | rc = -EINVAL; |
| 21129 | } |
| 21130 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21131 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21132 | return rc; |
| 21133 | } |
| 21134 | |
| 21135 | /** |
| 21136 | * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool |
| 21137 | * @phba: phba object |
| 21138 | * @hdwq: hdwq to cleanup cmd rsp buff resources on |
| 21139 | * |
| 21140 | * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool. |
| 21141 | * |
| 21142 | * Return codes: |
| 21143 | * None |
| 21144 | **/ |
| 21145 | void |
| 21146 | lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 21147 | struct lpfc_sli4_hdw_queue *hdwq) |
| 21148 | { |
| 21149 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 21150 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 21151 | struct fcp_cmd_rsp_buf *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21152 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21153 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21154 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21155 | |
| 21156 | /* Free cmd_rsp buf pool */ |
| 21157 | list_for_each_entry_safe(list_entry, tmp, |
| 21158 | buf_list, |
| 21159 | list_node) { |
| 21160 | dma_pool_free(phba->lpfc_cmd_rsp_buf_pool, |
| 21161 | list_entry->fcp_cmnd, |
| 21162 | list_entry->fcp_cmd_rsp_dma_handle); |
| 21163 | list_del(&list_entry->list_node); |
| 21164 | kfree(list_entry); |
| 21165 | } |
| 21166 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21167 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21168 | } |