| 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 | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame^] | 7303 | static void lpfc_sli4_dip(struct lpfc_hba *phba) |
| 7304 | { |
| 7305 | uint32_t if_type; |
| 7306 | |
| 7307 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7308 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2 || |
| 7309 | if_type == LPFC_SLI_INTF_IF_TYPE_6) { |
| 7310 | struct lpfc_register reg_data; |
| 7311 | |
| 7312 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7313 | ®_data.word0)) |
| 7314 | return; |
| 7315 | |
| 7316 | if (bf_get(lpfc_sliport_status_dip, ®_data)) |
| 7317 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7318 | "2904 Firmware Dump Image Present" |
| 7319 | " on Adapter"); |
| 7320 | } |
| 7321 | } |
| 7322 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7323 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7324 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7325 | * @phba: Pointer to HBA context object. |
| 7326 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7327 | * This function is the main SLI4 device initialization PCI function. This |
| 7328 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7329 | * HBA error attention handler code. Caller is not required to hold any |
| 7330 | * locks. |
| 7331 | **/ |
| 7332 | int |
| 7333 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7334 | { |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7335 | int rc, i, cnt, len, dd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7336 | LPFC_MBOXQ_t *mboxq; |
| 7337 | struct lpfc_mqe *mqe; |
| 7338 | uint8_t *vpd; |
| 7339 | uint32_t vpd_size; |
| 7340 | uint32_t ftr_rsp = 0; |
| 7341 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7342 | struct lpfc_vport *vport = phba->pport; |
| 7343 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7344 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7345 | |
| 7346 | /* Perform a PCI function reset to start from clean */ |
| 7347 | rc = lpfc_pci_function_reset(phba); |
| 7348 | if (unlikely(rc)) |
| 7349 | return -ENODEV; |
| 7350 | |
| 7351 | /* Check the HBA Host Status Register for readyness */ |
| 7352 | rc = lpfc_sli4_post_status_check(phba); |
| 7353 | if (unlikely(rc)) |
| 7354 | return -ENODEV; |
| 7355 | else { |
| 7356 | spin_lock_irq(&phba->hbalock); |
| 7357 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7358 | spin_unlock_irq(&phba->hbalock); |
| 7359 | } |
| 7360 | |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame^] | 7361 | lpfc_sli4_dip(phba); |
| 7362 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7363 | /* |
| 7364 | * Allocate a single mailbox container for initializing the |
| 7365 | * port. |
| 7366 | */ |
| 7367 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7368 | if (!mboxq) |
| 7369 | return -ENOMEM; |
| 7370 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7371 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7372 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7373 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7374 | if (!vpd) { |
| 7375 | rc = -ENOMEM; |
| 7376 | goto out_free_mbox; |
| 7377 | } |
| 7378 | |
| 7379 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7380 | if (unlikely(rc)) { |
| 7381 | kfree(vpd); |
| 7382 | goto out_free_mbox; |
| 7383 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7384 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7385 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7386 | 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] | 7387 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7388 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7389 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7390 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7391 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7392 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7393 | |
| 7394 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7395 | LPFC_DCBX_CEE_MODE) |
| 7396 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7397 | else |
| 7398 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7399 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 7400 | phba->hba_flag &= ~HBA_IOQ_FLUSH; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7401 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7402 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7403 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7404 | "0376 READ_REV Error. SLI Level %d " |
| 7405 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7406 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7407 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7408 | kfree(vpd); |
| 7409 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7410 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7411 | |
| 7412 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7413 | * Continue initialization with default values even if driver failed |
| 7414 | * to read FCoE param config regions, only read parameters if the |
| 7415 | * board is FCoE |
| 7416 | */ |
| 7417 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7418 | lpfc_sli4_read_fcoe_params(phba)) |
| 7419 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7420 | "2570 Failed to read FCoE parameters\n"); |
| 7421 | |
| 7422 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7423 | * Retrieve sli4 device physical port name, failure of doing it |
| 7424 | * is considered as non-fatal. |
| 7425 | */ |
| 7426 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7427 | if (!rc) |
| 7428 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7429 | "3080 Successful retrieving SLI4 device " |
| 7430 | "physical port name: %s.\n", phba->Port); |
| 7431 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 7432 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 7433 | if (!rc) |
| 7434 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7435 | "8351 Successful retrieving SLI4 device " |
| 7436 | "CTL ATTR\n"); |
| 7437 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7438 | /* |
| 7439 | * Evaluate the read rev and vpd data. Populate the driver |
| 7440 | * state with the results. If this routine fails, the failure |
| 7441 | * is not fatal as the driver will use generic values. |
| 7442 | */ |
| 7443 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7444 | if (unlikely(!rc)) { |
| 7445 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7446 | "0377 Error %d parsing vpd. " |
| 7447 | "Using defaults.\n", rc); |
| 7448 | rc = 0; |
| 7449 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7450 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7451 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7452 | /* Save information as VPD data */ |
| 7453 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7454 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7455 | |
| 7456 | /* |
| 7457 | * This is because first G7 ASIC doesn't support the standard |
| 7458 | * 0x5a NVME cmd descriptor type/subtype |
| 7459 | */ |
| 7460 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7461 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7462 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7463 | (phba->vpd.rev.smRev == 0) && |
| 7464 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7465 | phba->cfg_nvme_embed_cmd = 0; |
| 7466 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7467 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7468 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7469 | &mqe->un.read_rev); |
| 7470 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7471 | &mqe->un.read_rev); |
| 7472 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7473 | &mqe->un.read_rev); |
| 7474 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7475 | &mqe->un.read_rev); |
| 7476 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7477 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7478 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7479 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7480 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7481 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7482 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7483 | "(%d):0380 READ_REV Status x%x " |
| 7484 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7485 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7486 | bf_get(lpfc_mqe_status, mqe), |
| 7487 | phba->vpd.rev.opFwName, |
| 7488 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7489 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7490 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7491 | 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] | 7492 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7493 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7494 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7495 | if (rc == MBX_SUCCESS) { |
| 7496 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7497 | /* Set 1Sec interval to detect UE */ |
| 7498 | phba->eratt_poll_interval = 1; |
| 7499 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7500 | lpfc_mbx_set_feature_UESR, |
| 7501 | &mboxq->u.mqe.un.set_feature); |
| 7502 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7503 | lpfc_mbx_set_feature_UERP, |
| 7504 | &mboxq->u.mqe.un.set_feature); |
| 7505 | } |
| 7506 | } |
| 7507 | |
| 7508 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7509 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7510 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7511 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7512 | if (rc != MBX_SUCCESS) |
| 7513 | phba->mds_diags_support = 0; |
| 7514 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7515 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7516 | /* |
| 7517 | * Discover the port's supported feature set and match it against the |
| 7518 | * hosts requests. |
| 7519 | */ |
| 7520 | lpfc_request_features(phba, mboxq); |
| 7521 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7522 | if (unlikely(rc)) { |
| 7523 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7524 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | /* |
| 7528 | * The port must support FCP initiator mode as this is the |
| 7529 | * only mode running in the host. |
| 7530 | */ |
| 7531 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7532 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7533 | "0378 No support for fcpi mode.\n"); |
| 7534 | ftr_rsp++; |
| 7535 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7536 | |
| 7537 | /* Performance Hints are ONLY for FCoE */ |
| 7538 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7539 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7540 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7541 | else |
| 7542 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7543 | } |
| 7544 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7545 | /* |
| 7546 | * If the port cannot support the host's requested features |
| 7547 | * then turn off the global config parameters to disable the |
| 7548 | * feature in the driver. This is not a fatal error. |
| 7549 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7550 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7551 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7552 | phba->cfg_enable_bg = 0; |
| 7553 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7554 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7555 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7556 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7557 | |
| 7558 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7559 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7560 | ftr_rsp++; |
| 7561 | |
| 7562 | if (ftr_rsp) { |
| 7563 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7564 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7565 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7566 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7567 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7568 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7569 | phba->cfg_enable_bg = 0; |
| 7570 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7571 | phba->cfg_enable_npiv = 0; |
| 7572 | } |
| 7573 | |
| 7574 | /* These SLI3 features are assumed in SLI4 */ |
| 7575 | spin_lock_irq(&phba->hbalock); |
| 7576 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7577 | spin_unlock_irq(&phba->hbalock); |
| 7578 | |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7579 | /* Always try to enable dual dump feature if we can */ |
| 7580 | lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP); |
| 7581 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7582 | dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature); |
| 7583 | if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP)) |
| 7584 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_INIT, |
| 7585 | "6448 Dual Dump is enabled\n"); |
| 7586 | else |
| 7587 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT, |
| 7588 | "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, " |
| 7589 | "rc:x%x dd:x%x\n", |
| 7590 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 7591 | lpfc_sli_config_mbox_subsys_get( |
| 7592 | phba, mboxq), |
| 7593 | lpfc_sli_config_mbox_opcode_get( |
| 7594 | phba, mboxq), |
| 7595 | rc, dd); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7596 | /* |
| 7597 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7598 | * calls depends on these resources to complete port setup. |
| 7599 | */ |
| 7600 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7601 | if (rc) { |
| 7602 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7603 | "2920 Failed to alloc Resource IDs " |
| 7604 | "rc = x%x\n", rc); |
| 7605 | goto out_free_mbox; |
| 7606 | } |
| 7607 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7608 | lpfc_set_host_data(phba, mboxq); |
| 7609 | |
| 7610 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7611 | if (rc) { |
| 7612 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7613 | "2134 Failed to set host os driver version %x", |
| 7614 | rc); |
| 7615 | } |
| 7616 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7617 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7618 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7619 | if (rc) { |
| 7620 | phba->link_state = LPFC_HBA_ERROR; |
| 7621 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7622 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7623 | } |
| 7624 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7625 | mboxq->vport = vport; |
| 7626 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7627 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7628 | if (rc == MBX_SUCCESS) { |
| 7629 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7630 | rc = 0; |
| 7631 | } |
| 7632 | |
| 7633 | /* |
| 7634 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7635 | * it to the mbuf pool. |
| 7636 | */ |
| 7637 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7638 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7639 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7640 | if (unlikely(rc)) { |
| 7641 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7642 | "0382 READ_SPARAM command failed " |
| 7643 | "status %d, mbxStatus x%x\n", |
| 7644 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7645 | phba->link_state = LPFC_HBA_ERROR; |
| 7646 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7647 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7648 | } |
| 7649 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7650 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7651 | |
| 7652 | /* Update the fc_host data structures with new wwn. */ |
| 7653 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7654 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7655 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7656 | /* Create all the SLI4 queues */ |
| 7657 | rc = lpfc_sli4_queue_create(phba); |
| 7658 | if (rc) { |
| 7659 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7660 | "3089 Failed to allocate queues\n"); |
| 7661 | rc = -ENODEV; |
| 7662 | goto out_free_mbox; |
| 7663 | } |
| 7664 | /* Set up all the queues to the device */ |
| 7665 | rc = lpfc_sli4_queue_setup(phba); |
| 7666 | if (unlikely(rc)) { |
| 7667 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7668 | "0381 Error %d during queue setup.\n ", rc); |
| 7669 | goto out_stop_timers; |
| 7670 | } |
| 7671 | /* Initialize the driver internal SLI layer lists. */ |
| 7672 | lpfc_sli4_setup(phba); |
| 7673 | lpfc_sli4_queue_init(phba); |
| 7674 | |
| 7675 | /* update host els xri-sgl sizes and mappings */ |
| 7676 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7677 | if (unlikely(rc)) { |
| 7678 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7679 | "1400 Failed to update xri-sgl size and " |
| 7680 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7681 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7682 | } |
| 7683 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7684 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7685 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7686 | phba->sli4_hba.els_xri_cnt); |
| 7687 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7688 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7689 | "0582 Error %d during els sgl post " |
| 7690 | "operation\n", rc); |
| 7691 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7692 | goto out_destroy_queue; |
| 7693 | } |
| 7694 | phba->sli4_hba.els_xri_cnt = rc; |
| 7695 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7696 | if (phba->nvmet_support) { |
| 7697 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7698 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7699 | if (unlikely(rc)) { |
| 7700 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7701 | "6308 Failed to update nvmet-sgl size " |
| 7702 | "and mapping: %d\n", rc); |
| 7703 | goto out_destroy_queue; |
| 7704 | } |
| 7705 | |
| 7706 | /* register the nvmet sgl pool to the port */ |
| 7707 | rc = lpfc_sli4_repost_sgl_list( |
| 7708 | phba, |
| 7709 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7710 | phba->sli4_hba.nvmet_xri_cnt); |
| 7711 | if (unlikely(rc < 0)) { |
| 7712 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7713 | "3117 Error %d during nvmet " |
| 7714 | "sgl post\n", rc); |
| 7715 | rc = -ENODEV; |
| 7716 | goto out_destroy_queue; |
| 7717 | } |
| 7718 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7719 | |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7720 | /* We allocate an iocbq for every receive context SGL. |
| 7721 | * The additional allocation is for abort and ls handling. |
| 7722 | */ |
| 7723 | cnt = phba->sli4_hba.nvmet_xri_cnt + |
| 7724 | phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7725 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7726 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7727 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7728 | if (unlikely(rc)) { |
| 7729 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7730 | "6082 Failed to update nvme-sgl size " |
| 7731 | "and mapping: %d\n", rc); |
| 7732 | goto out_destroy_queue; |
| 7733 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7734 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7735 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7736 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7737 | if (unlikely(rc)) { |
| 7738 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7739 | "6116 Error %d during nvme sgl post " |
| 7740 | "operation\n", rc); |
| 7741 | /* Some NVME buffers were moved to abort nvme list */ |
| 7742 | /* A pci function reset will repost them */ |
| 7743 | rc = -ENODEV; |
| 7744 | goto out_destroy_queue; |
| 7745 | } |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7746 | /* Each lpfc_io_buf job structure has an iocbq element. |
| 7747 | * This cnt provides for abort, els, ct and ls requests. |
| 7748 | */ |
| 7749 | cnt = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7750 | } |
| 7751 | |
| 7752 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7753 | /* Initialize and populate the iocb list per host */ |
| 7754 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7755 | "2821 initialize iocb list with %d entries\n", |
| 7756 | cnt); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7757 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7758 | if (rc) { |
| 7759 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7760 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7761 | goto out_destroy_queue; |
| 7762 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7763 | } |
| 7764 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7765 | if (phba->nvmet_support) |
| 7766 | lpfc_nvmet_create_targetport(phba); |
| 7767 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7768 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7769 | /* Post initial buffers to all RQs created */ |
| 7770 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7771 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7772 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7773 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7774 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7775 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7776 | rqbp->buffer_count = 0; |
| 7777 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7778 | lpfc_post_rq_buffer( |
| 7779 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7780 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7781 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7782 | } |
| 7783 | } |
| 7784 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7785 | /* Post the rpi header region to the device. */ |
| 7786 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7787 | if (unlikely(rc)) { |
| 7788 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7789 | "0393 Error %d during rpi post operation\n", |
| 7790 | rc); |
| 7791 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7792 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7793 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7794 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7795 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7796 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7797 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7798 | /* |
| 7799 | * The FC Port needs to register FCFI (index 0) |
| 7800 | */ |
| 7801 | lpfc_reg_fcfi(phba, mboxq); |
| 7802 | mboxq->vport = phba->pport; |
| 7803 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7804 | if (rc != MBX_SUCCESS) |
| 7805 | goto out_unset_queue; |
| 7806 | rc = 0; |
| 7807 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7808 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7809 | } else { |
| 7810 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7811 | |
| 7812 | /* First register the FCFI */ |
| 7813 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7814 | mboxq->vport = phba->pport; |
| 7815 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7816 | if (rc != MBX_SUCCESS) |
| 7817 | goto out_unset_queue; |
| 7818 | rc = 0; |
| 7819 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7820 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7821 | |
| 7822 | /* Next register the MRQs */ |
| 7823 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7824 | mboxq->vport = phba->pport; |
| 7825 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7826 | if (rc != MBX_SUCCESS) |
| 7827 | goto out_unset_queue; |
| 7828 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7829 | } |
| 7830 | /* Check if the port is configured to be disabled */ |
| 7831 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7832 | } |
| 7833 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7834 | /* Don't post more new bufs if repost already recovered |
| 7835 | * the nvme sgls. |
| 7836 | */ |
| 7837 | if (phba->nvmet_support == 0) { |
| 7838 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 7839 | len = lpfc_new_io_buf( |
| 7840 | phba, phba->sli4_hba.io_xri_max); |
| 7841 | if (len == 0) { |
| 7842 | rc = -ENOMEM; |
| 7843 | goto out_unset_queue; |
| 7844 | } |
| 7845 | |
| 7846 | if (phba->cfg_xri_rebalancing) |
| 7847 | lpfc_create_multixri_pools(phba); |
| 7848 | } |
| 7849 | } else { |
| 7850 | phba->cfg_xri_rebalancing = 0; |
| 7851 | } |
| 7852 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7853 | /* Allow asynchronous mailbox command to go through */ |
| 7854 | spin_lock_irq(&phba->hbalock); |
| 7855 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7856 | spin_unlock_irq(&phba->hbalock); |
| 7857 | |
| 7858 | /* Post receive buffers to the device */ |
| 7859 | lpfc_sli4_rb_setup(phba); |
| 7860 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7861 | /* Reset HBA FCF states after HBA reset */ |
| 7862 | phba->fcf.fcf_flag = 0; |
| 7863 | phba->fcf.current_rec.flag = 0; |
| 7864 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7865 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7866 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7867 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7868 | |
| 7869 | /* Start heart beat timer */ |
| 7870 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7871 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7872 | phba->hb_outstanding = 0; |
| 7873 | phba->last_completion_time = jiffies; |
| 7874 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7875 | /* start eq_delay heartbeat */ |
| 7876 | if (phba->cfg_auto_imax) |
| 7877 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 7878 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 7879 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7880 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7881 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7882 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7883 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7884 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7885 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7886 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7887 | if (!rc) { |
| 7888 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7889 | "2829 This device supports " |
| 7890 | "Advanced Error Reporting (AER)\n"); |
| 7891 | spin_lock_irq(&phba->hbalock); |
| 7892 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7893 | spin_unlock_irq(&phba->hbalock); |
| 7894 | } else { |
| 7895 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7896 | "2830 This device does not support " |
| 7897 | "Advanced Error Reporting (AER)\n"); |
| 7898 | phba->cfg_aer_support = 0; |
| 7899 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7900 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7901 | } |
| 7902 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7903 | /* |
| 7904 | * The port is ready, set the host's link state to LINK_DOWN |
| 7905 | * in preparation for link interrupts. |
| 7906 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7907 | spin_lock_irq(&phba->hbalock); |
| 7908 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7909 | |
| 7910 | /* Check if physical ports are trunked */ |
| 7911 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 7912 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 7913 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 7914 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 7915 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 7916 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 7917 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 7918 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7919 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7920 | |
James Smart | e8869f5 | 2019-03-12 16:30:18 -0700 | [diff] [blame] | 7921 | /* Arm the CQs and then EQs on device */ |
| 7922 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7923 | |
| 7924 | /* Indicate device interrupt mode */ |
| 7925 | phba->sli4_hba.intr_enable = 1; |
| 7926 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7927 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7928 | (phba->hba_flag & LINK_DISABLED)) { |
| 7929 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7930 | "3103 Adapter Link is disabled.\n"); |
| 7931 | lpfc_down_link(phba, mboxq); |
| 7932 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7933 | if (rc != MBX_SUCCESS) { |
| 7934 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7935 | "3104 Adapter failed to issue " |
| 7936 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7937 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7938 | } |
| 7939 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7940 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7941 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7942 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7943 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7944 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7945 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7946 | } |
| 7947 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7948 | return rc; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7949 | out_io_buff_free: |
| 7950 | /* Free allocated IO Buffers */ |
| 7951 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7952 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7953 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7954 | lpfc_sli4_queue_unset(phba); |
| 7955 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7956 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7957 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7958 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7959 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7960 | out_free_mbox: |
| 7961 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7962 | return rc; |
| 7963 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7964 | |
| 7965 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7966 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7967 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7968 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7969 | * This is the callback function for mailbox timer. The mailbox |
| 7970 | * timer is armed when a new mailbox command is issued and the timer |
| 7971 | * is deleted when the mailbox complete. The function is called by |
| 7972 | * the kernel timer code when a mailbox does not complete within |
| 7973 | * expected time. This function wakes up the worker thread to |
| 7974 | * process the mailbox timeout and returns. All the processing is |
| 7975 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7976 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7977 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7978 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7979 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7980 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7981 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7982 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7983 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7984 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7985 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7986 | if (!tmo_posted) |
| 7987 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7988 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7989 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7990 | if (!tmo_posted) |
| 7991 | lpfc_worker_wake_up(phba); |
| 7992 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7993 | } |
| 7994 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7995 | /** |
| 7996 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7997 | * are pending |
| 7998 | * @phba: Pointer to HBA context object. |
| 7999 | * |
| 8000 | * This function checks if any mailbox completions are present on the mailbox |
| 8001 | * completion queue. |
| 8002 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 8003 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8004 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 8005 | { |
| 8006 | |
| 8007 | uint32_t idx; |
| 8008 | struct lpfc_queue *mcq; |
| 8009 | struct lpfc_mcqe *mcqe; |
| 8010 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8011 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8012 | |
| 8013 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 8014 | return false; |
| 8015 | |
| 8016 | /* Check for completions on mailbox completion queue */ |
| 8017 | |
| 8018 | mcq = phba->sli4_hba.mbx_cq; |
| 8019 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8020 | qe_valid = mcq->qe_valid; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 8021 | while (bf_get_le32(lpfc_cqe_valid, |
| 8022 | (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) { |
| 8023 | mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx)); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8024 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 8025 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 8026 | pending_completions = true; |
| 8027 | break; |
| 8028 | } |
| 8029 | idx = (idx + 1) % mcq->entry_count; |
| 8030 | if (mcq->hba_index == idx) |
| 8031 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8032 | |
| 8033 | /* if the index wrapped around, toggle the valid bit */ |
| 8034 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 8035 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8036 | } |
| 8037 | return pending_completions; |
| 8038 | |
| 8039 | } |
| 8040 | |
| 8041 | /** |
| 8042 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 8043 | * that were missed. |
| 8044 | * @phba: Pointer to HBA context object. |
| 8045 | * |
| 8046 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 8047 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 8048 | * checks to see if mbox completions are on the mailbox completion queue |
| 8049 | * and will process all the completions associated with the eq for the |
| 8050 | * mailbox completion queue. |
| 8051 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 8052 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8053 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 8054 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 8055 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8056 | uint32_t eqidx; |
| 8057 | struct lpfc_queue *fpeq = NULL; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8058 | struct lpfc_queue *eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8059 | bool mbox_pending; |
| 8060 | |
| 8061 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 8062 | return false; |
| 8063 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8064 | /* Find the EQ associated with the mbox CQ */ |
| 8065 | if (sli4_hba->hdwq) { |
| 8066 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) { |
| 8067 | eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq; |
Daniel Wagner | 535fb49 | 2019-10-18 18:21:11 +0200 | [diff] [blame] | 8068 | if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8069 | fpeq = eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8070 | break; |
| 8071 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8072 | } |
| 8073 | } |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8074 | if (!fpeq) |
| 8075 | return false; |
| 8076 | |
| 8077 | /* Turn off interrupts from this EQ */ |
| 8078 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 8079 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8080 | |
| 8081 | /* Check to see if a mbox completion is pending */ |
| 8082 | |
| 8083 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 8084 | |
| 8085 | /* |
| 8086 | * If a mbox completion is pending, process all the events on EQ |
| 8087 | * associated with the mbox completion queue (this could include |
| 8088 | * mailbox commands, async events, els commands, receive queue data |
| 8089 | * and fcp commands) |
| 8090 | */ |
| 8091 | |
| 8092 | if (mbox_pending) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8093 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 8094 | lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8095 | else |
| 8096 | /* Always clear and re-arm the EQ */ |
| 8097 | sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8098 | |
| 8099 | return mbox_pending; |
| 8100 | |
| 8101 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8102 | |
| 8103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8104 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8105 | * @phba: Pointer to HBA context object. |
| 8106 | * |
| 8107 | * This function is called from worker thread when a mailbox command times out. |
| 8108 | * The caller is not required to hold any locks. This function will reset the |
| 8109 | * HBA and recover all the pending commands. |
| 8110 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8111 | void |
| 8112 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 8113 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8114 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8115 | MAILBOX_t *mb = NULL; |
| 8116 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8117 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8118 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8119 | /* If the mailbox completed, process the completion and return */ |
| 8120 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 8121 | return; |
| 8122 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8123 | if (pmbox != NULL) |
| 8124 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8125 | /* Check the pmbox pointer first. There is a race condition |
| 8126 | * between the mbox timeout handler getting executed in the |
| 8127 | * worklist and the mailbox actually completing. When this |
| 8128 | * race condition occurs, the mbox_active will be NULL. |
| 8129 | */ |
| 8130 | spin_lock_irq(&phba->hbalock); |
| 8131 | if (pmbox == NULL) { |
| 8132 | lpfc_printf_log(phba, KERN_WARNING, |
| 8133 | LOG_MBOX | LOG_SLI, |
| 8134 | "0353 Active Mailbox cleared - mailbox timeout " |
| 8135 | "exiting\n"); |
| 8136 | spin_unlock_irq(&phba->hbalock); |
| 8137 | return; |
| 8138 | } |
| 8139 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8140 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8141 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 8142 | "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] | 8143 | mb->mbxCommand, |
| 8144 | phba->pport->port_state, |
| 8145 | phba->sli.sli_flag, |
| 8146 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8147 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8148 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8149 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 8150 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8151 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8152 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8153 | spin_lock_irq(&phba->pport->work_port_lock); |
| 8154 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 8155 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 8156 | spin_lock_irq(&phba->hbalock); |
| 8157 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 8158 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8159 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8160 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 8161 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8162 | |
| 8163 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8164 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8165 | |
| 8166 | /* Reset the HBA device */ |
| 8167 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8168 | } |
| 8169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8170 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8171 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8172 | * @phba: Pointer to HBA context object. |
| 8173 | * @pmbox: Pointer to mailbox object. |
| 8174 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8175 | * |
| 8176 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8177 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 8178 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8179 | * The mailbox command can be submitted in polling mode, in which case |
| 8180 | * this function will wait in a polling loop for the completion of the |
| 8181 | * mailbox. |
| 8182 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 8183 | * function will submit the command and returns immediately without waiting |
| 8184 | * for the mailbox completion. The no_wait is supported only when HBA |
| 8185 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 8186 | * The SLI interface allows only one mailbox pending at a time. If the |
| 8187 | * mailbox is issued in polling mode and there is already a mailbox |
| 8188 | * pending, then the function will return an error. If the mailbox is issued |
| 8189 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 8190 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 8191 | * The sli layer owns the mailbox object until the completion of mailbox |
| 8192 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 8193 | * return codes the caller owns the mailbox command after the return of |
| 8194 | * the function. |
| 8195 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8196 | static int |
| 8197 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 8198 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8199 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8200 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8201 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8202 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8203 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8204 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8205 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8206 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8207 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8208 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8209 | int processing_queue = 0; |
| 8210 | |
| 8211 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8212 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8213 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8214 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8215 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8216 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8217 | return MBX_SUCCESS; |
| 8218 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8219 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8220 | pmbox = lpfc_mbox_get(phba); |
| 8221 | if (!pmbox) { |
| 8222 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8223 | return MBX_SUCCESS; |
| 8224 | } |
| 8225 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8226 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8227 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8228 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8229 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8230 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8231 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8232 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8233 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8234 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8235 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8236 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8237 | } |
| 8238 | } |
| 8239 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8240 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8241 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8242 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8243 | goto out_not_finished; |
| 8244 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8245 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8246 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8247 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8248 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8249 | goto out_not_finished; |
| 8250 | } |
| 8251 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8252 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8253 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8254 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8255 | status = MBX_SUCCESS; |
| 8256 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8257 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8258 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8259 | |
| 8260 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8261 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8262 | "(%d):0311 Mailbox command x%x cannot " |
| 8263 | "issue Data: x%x x%x\n", |
| 8264 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8265 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8266 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8267 | } |
| 8268 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8269 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8270 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8271 | !(hc_copy & HC_MBINT_ENA)) { |
| 8272 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8273 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8274 | "(%d):2528 Mailbox command x%x cannot " |
| 8275 | "issue Data: x%x x%x\n", |
| 8276 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8277 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8278 | goto out_not_finished; |
| 8279 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8280 | } |
| 8281 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8282 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8283 | /* Polling for a mbox command when another one is already active |
| 8284 | * is not allowed in SLI. Also, the driver must have established |
| 8285 | * SLI2 mode to queue and process multiple mbox commands. |
| 8286 | */ |
| 8287 | |
| 8288 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8289 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8290 | |
| 8291 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8292 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8293 | "(%d):2529 Mailbox command x%x " |
| 8294 | "cannot issue Data: x%x x%x\n", |
| 8295 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8296 | pmbox->u.mb.mbxCommand, |
| 8297 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8298 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8299 | } |
| 8300 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8301 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8302 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8303 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8304 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8305 | "(%d):2530 Mailbox command x%x " |
| 8306 | "cannot issue Data: x%x x%x\n", |
| 8307 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8308 | pmbox->u.mb.mbxCommand, |
| 8309 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8310 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8311 | } |
| 8312 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8313 | /* Another mailbox command is still being processed, queue this |
| 8314 | * command to be processed later. |
| 8315 | */ |
| 8316 | lpfc_mbox_put(phba, pmbox); |
| 8317 | |
| 8318 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8319 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8320 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8321 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8322 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8323 | mbx->mbxCommand, |
| 8324 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8325 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8326 | |
| 8327 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8328 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8329 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8330 | if (pmbox->vport) { |
| 8331 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8332 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8333 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8334 | (uint32_t)mbx->mbxCommand, |
| 8335 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8336 | } |
| 8337 | else { |
| 8338 | lpfc_debugfs_disc_trc(phba->pport, |
| 8339 | LPFC_DISC_TRC_MBOX, |
| 8340 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8341 | (uint32_t)mbx->mbxCommand, |
| 8342 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8343 | } |
| 8344 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8345 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8346 | } |
| 8347 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8348 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8349 | |
| 8350 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8351 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8352 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8353 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8354 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8355 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8356 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8357 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8358 | "(%d):2531 Mailbox command x%x " |
| 8359 | "cannot issue Data: x%x x%x\n", |
| 8360 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8361 | pmbox->u.mb.mbxCommand, |
| 8362 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8363 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8364 | } |
| 8365 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8366 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8367 | 1000); |
| 8368 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8369 | } |
| 8370 | |
| 8371 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8372 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8373 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8374 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8375 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8376 | mbx->mbxCommand, |
| 8377 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8378 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8379 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8380 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8381 | if (pmbox->vport) { |
| 8382 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8383 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8384 | "MBOX Send vport: 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 | else { |
| 8389 | lpfc_debugfs_disc_trc(phba->pport, |
| 8390 | LPFC_DISC_TRC_MBOX, |
| 8391 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8392 | (uint32_t)mbx->mbxCommand, |
| 8393 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8394 | } |
| 8395 | } |
| 8396 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8397 | psli->slistat.mbox_cmd++; |
| 8398 | evtctr = psli->slistat.mbox_event; |
| 8399 | |
| 8400 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8401 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8402 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8403 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8404 | /* Populate mbox extension offset word. */ |
| 8405 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8406 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8407 | = (uint8_t *)phba->mbox_ext |
| 8408 | - (uint8_t *)phba->mbox; |
| 8409 | } |
| 8410 | |
| 8411 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8412 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8413 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8414 | (uint8_t *)phba->mbox_ext, |
| 8415 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8416 | } |
| 8417 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8418 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8419 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8420 | /* Populate mbox extension offset word. */ |
| 8421 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8422 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8423 | = MAILBOX_HBA_EXT_OFFSET; |
| 8424 | |
| 8425 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8426 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8427 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8428 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8429 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8430 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8431 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8432 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8433 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8434 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8435 | |
| 8436 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8437 | word */ |
| 8438 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8439 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8440 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8441 | |
| 8442 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8443 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8444 | to_slim = phba->MBslimaddr; |
| 8445 | writel(ldata, to_slim); |
| 8446 | readl(to_slim); /* flush */ |
| 8447 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8448 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8449 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8450 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8451 | } |
| 8452 | |
| 8453 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8454 | |
| 8455 | switch (flag) { |
| 8456 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8457 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8458 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8459 | /* Interrupt board to do it */ |
| 8460 | writel(CA_MBATT, phba->CAregaddr); |
| 8461 | readl(phba->CAregaddr); /* flush */ |
| 8462 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8463 | break; |
| 8464 | |
| 8465 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8466 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8467 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8468 | /* Interrupt board to do it */ |
| 8469 | writel(CA_MBATT, phba->CAregaddr); |
| 8470 | readl(phba->CAregaddr); /* flush */ |
| 8471 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8472 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8473 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8474 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8475 | word0 = le32_to_cpu(word0); |
| 8476 | } else { |
| 8477 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8478 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8479 | spin_unlock_irqrestore(&phba->hbalock, |
| 8480 | drvr_flag); |
| 8481 | goto out_not_finished; |
| 8482 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8483 | } |
| 8484 | |
| 8485 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8486 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8487 | spin_unlock_irqrestore(&phba->hbalock, |
| 8488 | drvr_flag); |
| 8489 | goto out_not_finished; |
| 8490 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8491 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8492 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8493 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8494 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8495 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8496 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8497 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8498 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8499 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8500 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8501 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8502 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8503 | } |
| 8504 | |
| 8505 | /* Check if we took a mbox interrupt while we were |
| 8506 | polling */ |
| 8507 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8508 | && (evtctr != psli->slistat.mbox_event)) |
| 8509 | break; |
| 8510 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8511 | if (i++ > 10) { |
| 8512 | spin_unlock_irqrestore(&phba->hbalock, |
| 8513 | drvr_flag); |
| 8514 | msleep(1); |
| 8515 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8516 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8517 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8518 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8519 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8520 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8521 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8522 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8523 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8524 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8525 | /* Check real SLIM for any errors */ |
| 8526 | slimword0 = readl(phba->MBslimaddr); |
| 8527 | slimmb = (MAILBOX_t *) & slimword0; |
| 8528 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8529 | && slimmb->mbxStatus) { |
| 8530 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8531 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8532 | word0 = slimword0; |
| 8533 | } |
| 8534 | } |
| 8535 | } else { |
| 8536 | /* First copy command data */ |
| 8537 | word0 = readl(phba->MBslimaddr); |
| 8538 | } |
| 8539 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8540 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8541 | spin_unlock_irqrestore(&phba->hbalock, |
| 8542 | drvr_flag); |
| 8543 | goto out_not_finished; |
| 8544 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8545 | } |
| 8546 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8547 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8548 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8549 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8550 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8551 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8552 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8553 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8554 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8555 | pmbox->out_ext_byte_len); |
| 8556 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8557 | } else { |
| 8558 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8559 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8560 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8561 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8562 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8563 | lpfc_memcpy_from_slim( |
| 8564 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8565 | phba->MBslimaddr + |
| 8566 | MAILBOX_HBA_EXT_OFFSET, |
| 8567 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8568 | } |
| 8569 | } |
| 8570 | |
| 8571 | writel(HA_MBATT, phba->HAregaddr); |
| 8572 | readl(phba->HAregaddr); /* flush */ |
| 8573 | |
| 8574 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8575 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8576 | } |
| 8577 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8578 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8579 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8580 | |
| 8581 | out_not_finished: |
| 8582 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8583 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8584 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8585 | } |
| 8586 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8587 | } |
| 8588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8589 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8590 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8591 | * @phba: Pointer to HBA context object. |
| 8592 | * |
| 8593 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8594 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8595 | * possible outstanding mailbox command before return. |
| 8596 | * |
| 8597 | * Returns: |
| 8598 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8599 | * the outstanding mailbox command timed out. |
| 8600 | **/ |
| 8601 | static int |
| 8602 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8603 | { |
| 8604 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8605 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8606 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8607 | |
| 8608 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8609 | spin_lock_irq(&phba->hbalock); |
| 8610 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8611 | /* Determine how long we might wait for the active mailbox |
| 8612 | * command to be gracefully completed by firmware. |
| 8613 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8614 | if (phba->sli.mbox_active) |
| 8615 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8616 | phba->sli.mbox_active) * |
| 8617 | 1000) + jiffies; |
| 8618 | spin_unlock_irq(&phba->hbalock); |
| 8619 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8620 | /* Make sure the mailbox is really active */ |
| 8621 | if (timeout) |
| 8622 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8623 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8624 | /* Wait for the outstnading mailbox command to complete */ |
| 8625 | while (phba->sli.mbox_active) { |
| 8626 | /* Check active mailbox complete status every 2ms */ |
| 8627 | msleep(2); |
| 8628 | if (time_after(jiffies, timeout)) { |
| 8629 | /* Timeout, marked the outstanding cmd not complete */ |
| 8630 | rc = 1; |
| 8631 | break; |
| 8632 | } |
| 8633 | } |
| 8634 | |
| 8635 | /* Can not cleanly block async mailbox command, fails it */ |
| 8636 | if (rc) { |
| 8637 | spin_lock_irq(&phba->hbalock); |
| 8638 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8639 | spin_unlock_irq(&phba->hbalock); |
| 8640 | } |
| 8641 | return rc; |
| 8642 | } |
| 8643 | |
| 8644 | /** |
| 8645 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8646 | * @phba: Pointer to HBA context object. |
| 8647 | * |
| 8648 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8649 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8650 | * that there is no outstanding mailbox command before resuming posting |
| 8651 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8652 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8653 | * mailbox command posting. |
| 8654 | **/ |
| 8655 | static void |
| 8656 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8657 | { |
| 8658 | struct lpfc_sli *psli = &phba->sli; |
| 8659 | |
| 8660 | spin_lock_irq(&phba->hbalock); |
| 8661 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8662 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8663 | spin_unlock_irq(&phba->hbalock); |
| 8664 | return; |
| 8665 | } |
| 8666 | |
| 8667 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8668 | * successful or timeout, after timing-out the outstanding mailbox |
| 8669 | * command shall always be removed, so just unblock posting async |
| 8670 | * mailbox command and resume |
| 8671 | */ |
| 8672 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8673 | spin_unlock_irq(&phba->hbalock); |
| 8674 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 8675 | /* wake up worker thread to post asynchronous mailbox command */ |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8676 | lpfc_worker_wake_up(phba); |
| 8677 | } |
| 8678 | |
| 8679 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8680 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8681 | * @phba: Pointer to HBA context object. |
| 8682 | * @mboxq: Pointer to mailbox object. |
| 8683 | * |
| 8684 | * The function waits for the bootstrap mailbox register ready bit from |
| 8685 | * port for twice the regular mailbox command timeout value. |
| 8686 | * |
| 8687 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8688 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8689 | **/ |
| 8690 | static int |
| 8691 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8692 | { |
| 8693 | uint32_t db_ready; |
| 8694 | unsigned long timeout; |
| 8695 | struct lpfc_register bmbx_reg; |
| 8696 | |
| 8697 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8698 | * 1000) + jiffies; |
| 8699 | |
| 8700 | do { |
| 8701 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8702 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8703 | if (!db_ready) |
James Smart | e2ffe4d | 2019-03-12 16:30:15 -0700 | [diff] [blame] | 8704 | mdelay(2); |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8705 | |
| 8706 | if (time_after(jiffies, timeout)) |
| 8707 | return MBXERR_ERROR; |
| 8708 | } while (!db_ready); |
| 8709 | |
| 8710 | return 0; |
| 8711 | } |
| 8712 | |
| 8713 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8714 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8715 | * @phba: Pointer to HBA context object. |
| 8716 | * @mboxq: Pointer to mailbox object. |
| 8717 | * |
| 8718 | * The function posts a mailbox to the port. The mailbox is expected |
| 8719 | * to be comletely filled in and ready for the port to operate on it. |
| 8720 | * This routine executes a synchronous completion operation on the |
| 8721 | * mailbox by polling for its completion. |
| 8722 | * |
| 8723 | * The caller must not be holding any locks when calling this routine. |
| 8724 | * |
| 8725 | * Returns: |
| 8726 | * MBX_SUCCESS - mailbox posted successfully |
| 8727 | * Any of the MBX error values. |
| 8728 | **/ |
| 8729 | static int |
| 8730 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8731 | { |
| 8732 | int rc = MBX_SUCCESS; |
| 8733 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8734 | uint32_t mcqe_status; |
| 8735 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8736 | struct lpfc_sli *psli = &phba->sli; |
| 8737 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8738 | struct lpfc_bmbx_create *mbox_rgn; |
| 8739 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8740 | |
| 8741 | /* |
| 8742 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8743 | * at a time and there is no queueing provided. |
| 8744 | */ |
| 8745 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8746 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8747 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8748 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8749 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8750 | "cannot issue Data: x%x x%x\n", |
| 8751 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8752 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8753 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8754 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8755 | psli->sli_flag, MBX_POLL); |
| 8756 | return MBXERR_ERROR; |
| 8757 | } |
| 8758 | /* The server grabs the token and owns it until release */ |
| 8759 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8760 | phba->sli.mbox_active = mboxq; |
| 8761 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8762 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8763 | /* wait for bootstrap mbox register for readyness */ |
| 8764 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8765 | if (rc) |
| 8766 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8767 | /* |
| 8768 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8769 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8770 | * the bmbx mailbox region. |
| 8771 | */ |
| 8772 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8773 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8774 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8775 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8776 | |
| 8777 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8778 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8779 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8780 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8781 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8782 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8783 | if (rc) |
| 8784 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8785 | |
| 8786 | /* Post the low mailbox dma address to the port. */ |
| 8787 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8788 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8789 | /* wait for bootstrap mbox register for low address write done */ |
| 8790 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8791 | if (rc) |
| 8792 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8793 | |
| 8794 | /* |
| 8795 | * Read the CQ to ensure the mailbox has completed. |
| 8796 | * If so, update the mailbox status so that the upper layers |
| 8797 | * can complete the request normally. |
| 8798 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8799 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8800 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8801 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8802 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8803 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8804 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8805 | /* |
| 8806 | * When the CQE status indicates a failure and the mailbox status |
| 8807 | * indicates success then copy the CQE status into the mailbox status |
| 8808 | * (and prefix it with x4000). |
| 8809 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8810 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8811 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8812 | bf_set(lpfc_mqe_status, mb, |
| 8813 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8814 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8815 | } else |
| 8816 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8817 | |
| 8818 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8819 | "(%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] | 8820 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8821 | " 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] | 8822 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8823 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8824 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8825 | bf_get(lpfc_mqe_status, mb), |
| 8826 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8827 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8828 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8829 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8830 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8831 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8832 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8833 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8834 | mboxq->mcqe.trailer); |
| 8835 | exit: |
| 8836 | /* We are holding the token, no needed for lock when release */ |
| 8837 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8838 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8839 | phba->sli.mbox_active = NULL; |
| 8840 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8841 | return rc; |
| 8842 | } |
| 8843 | |
| 8844 | /** |
| 8845 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8846 | * @phba: Pointer to HBA context object. |
| 8847 | * @pmbox: Pointer to mailbox object. |
| 8848 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8849 | * |
| 8850 | * This function is called by discovery code and HBA management code to submit |
| 8851 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8852 | * |
| 8853 | * Return codes the caller owns the mailbox command after the return of the |
| 8854 | * function. |
| 8855 | **/ |
| 8856 | static int |
| 8857 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8858 | uint32_t flag) |
| 8859 | { |
| 8860 | struct lpfc_sli *psli = &phba->sli; |
| 8861 | unsigned long iflags; |
| 8862 | int rc; |
| 8863 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8864 | /* dump from issue mailbox command if setup */ |
| 8865 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8866 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8867 | rc = lpfc_mbox_dev_check(phba); |
| 8868 | if (unlikely(rc)) { |
| 8869 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8870 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8871 | "cannot issue Data: x%x x%x\n", |
| 8872 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8873 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8874 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8875 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8876 | psli->sli_flag, flag); |
| 8877 | goto out_not_finished; |
| 8878 | } |
| 8879 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8880 | /* Detect polling mode and jump to a handler */ |
| 8881 | if (!phba->sli4_hba.intr_enable) { |
| 8882 | if (flag == MBX_POLL) |
| 8883 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8884 | else |
| 8885 | rc = -EIO; |
| 8886 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8887 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8888 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8889 | "(x%x/x%x) failure: " |
| 8890 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8891 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8892 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8893 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8894 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8895 | mboxq), |
| 8896 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8897 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8898 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8899 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8900 | bf_get(lpfc_mcqe_ext_status, |
| 8901 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8902 | psli->sli_flag, flag); |
| 8903 | return rc; |
| 8904 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8905 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8906 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8907 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8908 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8909 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8910 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8911 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8912 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8913 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8914 | /* Try to block the asynchronous mailbox posting */ |
| 8915 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8916 | if (!rc) { |
| 8917 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8918 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8919 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8920 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8921 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8922 | "(%d):2597 Sync Mailbox command " |
| 8923 | "x%x (x%x/x%x) failure: " |
| 8924 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8925 | "Data: x%x x%x\n,", |
| 8926 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8927 | mboxq->u.mb.mbxCommand, |
| 8928 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8929 | mboxq), |
| 8930 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8931 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8932 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8933 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8934 | bf_get(lpfc_mcqe_ext_status, |
| 8935 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8936 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8937 | /* Unblock the async mailbox posting afterward */ |
| 8938 | lpfc_sli4_async_mbox_unblock(phba); |
| 8939 | } |
| 8940 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8941 | } |
| 8942 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 8943 | /* Now, interrupt mode asynchronous mailbox command */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8944 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8945 | if (rc) { |
| 8946 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8947 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8948 | "cannot issue Data: x%x x%x\n", |
| 8949 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8950 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8951 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8952 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8953 | psli->sli_flag, flag); |
| 8954 | goto out_not_finished; |
| 8955 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8956 | |
| 8957 | /* Put the mailbox command to the driver internal FIFO */ |
| 8958 | psli->slistat.mbox_busy++; |
| 8959 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8960 | lpfc_mbox_put(phba, mboxq); |
| 8961 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8962 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8963 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8964 | "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] | 8965 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8966 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8967 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8968 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8969 | phba->pport->port_state, |
| 8970 | psli->sli_flag, MBX_NOWAIT); |
| 8971 | /* Wake up worker thread to transport mailbox command from head */ |
| 8972 | lpfc_worker_wake_up(phba); |
| 8973 | |
| 8974 | return MBX_BUSY; |
| 8975 | |
| 8976 | out_not_finished: |
| 8977 | return MBX_NOT_FINISHED; |
| 8978 | } |
| 8979 | |
| 8980 | /** |
| 8981 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8982 | * @phba: Pointer to HBA context object. |
| 8983 | * |
| 8984 | * This function is called by worker thread to send a mailbox command to |
| 8985 | * SLI4 HBA firmware. |
| 8986 | * |
| 8987 | **/ |
| 8988 | int |
| 8989 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8990 | { |
| 8991 | struct lpfc_sli *psli = &phba->sli; |
| 8992 | LPFC_MBOXQ_t *mboxq; |
| 8993 | int rc = MBX_SUCCESS; |
| 8994 | unsigned long iflags; |
| 8995 | struct lpfc_mqe *mqe; |
| 8996 | uint32_t mbx_cmnd; |
| 8997 | |
| 8998 | /* Check interrupt mode before post async mailbox command */ |
| 8999 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 9000 | return MBX_NOT_FINISHED; |
| 9001 | |
| 9002 | /* Check for mailbox command service token */ |
| 9003 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9004 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 9005 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9006 | return MBX_NOT_FINISHED; |
| 9007 | } |
| 9008 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9009 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9010 | return MBX_NOT_FINISHED; |
| 9011 | } |
| 9012 | if (unlikely(phba->sli.mbox_active)) { |
| 9013 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9014 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 9015 | "0384 There is pending active mailbox cmd\n"); |
| 9016 | return MBX_NOT_FINISHED; |
| 9017 | } |
| 9018 | /* Take the mailbox command service token */ |
| 9019 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 9020 | |
| 9021 | /* Get the next mailbox command from head of queue */ |
| 9022 | mboxq = lpfc_mbox_get(phba); |
| 9023 | |
| 9024 | /* If no more mailbox command waiting for post, we're done */ |
| 9025 | if (!mboxq) { |
| 9026 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9027 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9028 | return MBX_SUCCESS; |
| 9029 | } |
| 9030 | phba->sli.mbox_active = mboxq; |
| 9031 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9032 | |
| 9033 | /* Check device readiness for posting mailbox command */ |
| 9034 | rc = lpfc_mbox_dev_check(phba); |
| 9035 | if (unlikely(rc)) |
| 9036 | /* Driver clean routine will clean up pending mailbox */ |
| 9037 | goto out_not_finished; |
| 9038 | |
| 9039 | /* Prepare the mbox command to be posted */ |
| 9040 | mqe = &mboxq->u.mqe; |
| 9041 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 9042 | |
| 9043 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 9044 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9045 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9046 | |
| 9047 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9048 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9049 | "x%x x%x\n", |
| 9050 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9051 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9052 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9053 | phba->pport->port_state, psli->sli_flag); |
| 9054 | |
| 9055 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 9056 | if (mboxq->vport) { |
| 9057 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 9058 | LPFC_DISC_TRC_MBOX_VPORT, |
| 9059 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 9060 | mbx_cmnd, mqe->un.mb_words[0], |
| 9061 | mqe->un.mb_words[1]); |
| 9062 | } else { |
| 9063 | lpfc_debugfs_disc_trc(phba->pport, |
| 9064 | LPFC_DISC_TRC_MBOX, |
| 9065 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 9066 | mbx_cmnd, mqe->un.mb_words[0], |
| 9067 | mqe->un.mb_words[1]); |
| 9068 | } |
| 9069 | } |
| 9070 | psli->slistat.mbox_cmd++; |
| 9071 | |
| 9072 | /* Post the mailbox command to the port */ |
| 9073 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 9074 | if (rc != MBX_SUCCESS) { |
| 9075 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9076 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9077 | "cannot issue Data: x%x x%x\n", |
| 9078 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9079 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9080 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9081 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9082 | psli->sli_flag, MBX_NOWAIT); |
| 9083 | goto out_not_finished; |
| 9084 | } |
| 9085 | |
| 9086 | return rc; |
| 9087 | |
| 9088 | out_not_finished: |
| 9089 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 9090 | if (phba->sli.mbox_active) { |
| 9091 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9092 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 9093 | /* Release the token */ |
| 9094 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9095 | phba->sli.mbox_active = NULL; |
| 9096 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9097 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9098 | |
| 9099 | return MBX_NOT_FINISHED; |
| 9100 | } |
| 9101 | |
| 9102 | /** |
| 9103 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 9104 | * @phba: Pointer to HBA context object. |
| 9105 | * @pmbox: Pointer to mailbox object. |
| 9106 | * @flag: Flag indicating how the mailbox need to be processed. |
| 9107 | * |
| 9108 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 9109 | * the API jump table function pointer from the lpfc_hba struct. |
| 9110 | * |
| 9111 | * Return codes the caller owns the mailbox command after the return of the |
| 9112 | * function. |
| 9113 | **/ |
| 9114 | int |
| 9115 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 9116 | { |
| 9117 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 9118 | } |
| 9119 | |
| 9120 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9121 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9122 | * @phba: The hba struct for which this call is being executed. |
| 9123 | * @dev_grp: The HBA PCI-Device group number. |
| 9124 | * |
| 9125 | * This routine sets up the mbox interface API function jump table in @phba |
| 9126 | * struct. |
| 9127 | * Returns: 0 - success, -ENODEV - failure. |
| 9128 | **/ |
| 9129 | int |
| 9130 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9131 | { |
| 9132 | |
| 9133 | switch (dev_grp) { |
| 9134 | case LPFC_PCI_DEV_LP: |
| 9135 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 9136 | phba->lpfc_sli_handle_slow_ring_event = |
| 9137 | lpfc_sli_handle_slow_ring_event_s3; |
| 9138 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 9139 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 9140 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 9141 | break; |
| 9142 | case LPFC_PCI_DEV_OC: |
| 9143 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 9144 | phba->lpfc_sli_handle_slow_ring_event = |
| 9145 | lpfc_sli_handle_slow_ring_event_s4; |
| 9146 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 9147 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 9148 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 9149 | break; |
| 9150 | default: |
| 9151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9152 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 9153 | dev_grp); |
| 9154 | return -ENODEV; |
| 9155 | break; |
| 9156 | } |
| 9157 | return 0; |
| 9158 | } |
| 9159 | |
| 9160 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9161 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9162 | * @phba: Pointer to HBA context object. |
| 9163 | * @pring: Pointer to driver SLI ring object. |
| 9164 | * @piocb: Pointer to address of newly added command iocb. |
| 9165 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9166 | * This function is called with hbalock held for SLI3 ports or |
| 9167 | * the ring lock held for SLI4 ports to add a command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9168 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 9169 | * to the ring. |
| 9170 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9171 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9172 | __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] | 9173 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9174 | { |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9175 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9176 | lockdep_assert_held(&pring->ring_lock); |
| 9177 | else |
| 9178 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9179 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 9180 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9181 | } |
| 9182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9183 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9184 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9185 | * @phba: Pointer to HBA context object. |
| 9186 | * @pring: Pointer to driver SLI ring object. |
| 9187 | * @piocb: Pointer to address of newly added command iocb. |
| 9188 | * |
| 9189 | * This function is called with hbalock held before a new |
| 9190 | * iocb is submitted to the firmware. This function checks |
| 9191 | * txq to flush the iocbs in txq to Firmware before |
| 9192 | * submitting new iocbs to the Firmware. |
| 9193 | * If there are iocbs in the txq which need to be submitted |
| 9194 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 9195 | * of the txq after dequeuing it from txq. |
| 9196 | * If there is no iocb in the txq then the function will return |
| 9197 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 9198 | * *piocb to find if there are more commands in the txq. |
| 9199 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9200 | static struct lpfc_iocbq * |
| 9201 | 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] | 9202 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9203 | { |
| 9204 | struct lpfc_iocbq * nextiocb; |
| 9205 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9206 | lockdep_assert_held(&phba->hbalock); |
| 9207 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9208 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9209 | if (!nextiocb) { |
| 9210 | nextiocb = *piocb; |
| 9211 | *piocb = NULL; |
| 9212 | } |
| 9213 | |
| 9214 | return nextiocb; |
| 9215 | } |
| 9216 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9217 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9218 | * __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] | 9219 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9220 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9221 | * @piocb: Pointer to command iocb. |
| 9222 | * @flag: Flag indicating if this command can be put into txq. |
| 9223 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9224 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9225 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9226 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9227 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9228 | * this function allows only iocbs for posting buffers. This function finds |
| 9229 | * next available slot in the command ring and posts the command to the |
| 9230 | * available slot and writes the port attention register to request HBA start |
| 9231 | * processing new iocb. If there is no slot available in the ring and |
| 9232 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9233 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9234 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9235 | * This function is called with hbalock held. The function will return success |
| 9236 | * after it successfully submit the iocb to firmware or after adding to the |
| 9237 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9238 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9239 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9240 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9241 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9242 | { |
| 9243 | struct lpfc_iocbq *nextiocb; |
| 9244 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9245 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9246 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9247 | lockdep_assert_held(&phba->hbalock); |
| 9248 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9249 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9250 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9251 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 9252 | lpfc_printf_log(phba, KERN_ERR, |
| 9253 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9254 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9255 | piocb->iocb.ulpCommand); |
| 9256 | dump_stack(); |
| 9257 | return IOCB_ERROR; |
| 9258 | } |
| 9259 | |
| 9260 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9261 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9262 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9263 | return IOCB_ERROR; |
| 9264 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9265 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9266 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9267 | return IOCB_ERROR; |
| 9268 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9269 | /* |
| 9270 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9271 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9272 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9273 | return IOCB_ERROR; |
| 9274 | |
| 9275 | /* |
| 9276 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9277 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9278 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9279 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9280 | goto iocb_busy; |
| 9281 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9282 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9283 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9284 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9285 | * can be issued if the link is not up. |
| 9286 | */ |
| 9287 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9288 | case CMD_GEN_REQUEST64_CR: |
| 9289 | case CMD_GEN_REQUEST64_CX: |
| 9290 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9291 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9292 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9293 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9294 | MENLO_TRANSPORT_TYPE)) |
| 9295 | |
| 9296 | goto iocb_busy; |
| 9297 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9298 | case CMD_QUE_RING_BUF_CN: |
| 9299 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9300 | /* |
| 9301 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9302 | * completion, iocb_cmpl MUST be 0. |
| 9303 | */ |
| 9304 | if (piocb->iocb_cmpl) |
| 9305 | piocb->iocb_cmpl = NULL; |
| 9306 | /*FALLTHROUGH*/ |
| 9307 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9308 | case CMD_CLOSE_XRI_CN: |
| 9309 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9310 | break; |
| 9311 | default: |
| 9312 | goto iocb_busy; |
| 9313 | } |
| 9314 | |
| 9315 | /* |
| 9316 | * For FCP commands, we must be in a state where we can process link |
| 9317 | * attention events. |
| 9318 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9319 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9320 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9321 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9322 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9323 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9324 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9325 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9326 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9327 | |
| 9328 | if (iocb) |
| 9329 | lpfc_sli_update_ring(phba, pring); |
| 9330 | else |
| 9331 | lpfc_sli_update_full_ring(phba, pring); |
| 9332 | |
| 9333 | if (!piocb) |
| 9334 | return IOCB_SUCCESS; |
| 9335 | |
| 9336 | goto out_busy; |
| 9337 | |
| 9338 | iocb_busy: |
| 9339 | pring->stats.iocb_cmd_delay++; |
| 9340 | |
| 9341 | out_busy: |
| 9342 | |
| 9343 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9344 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9345 | return IOCB_SUCCESS; |
| 9346 | } |
| 9347 | |
| 9348 | return IOCB_BUSY; |
| 9349 | } |
| 9350 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9351 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9352 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9353 | * @phba: Pointer to HBA context object. |
| 9354 | * @piocb: Pointer to command iocb. |
| 9355 | * @sglq: Pointer to the scatter gather queue object. |
| 9356 | * |
| 9357 | * This routine converts the bpl or bde that is in the IOCB |
| 9358 | * to a sgl list for the sli4 hardware. The physical address |
| 9359 | * of the bpl/bde is converted back to a virtual address. |
| 9360 | * If the IOCB contains a BPL then the list of BDE's is |
| 9361 | * converted to sli4_sge's. If the IOCB contains a single |
| 9362 | * BDE then it is converted to a single sli_sge. |
| 9363 | * The IOCB is still in cpu endianess so the contents of |
| 9364 | * the bpl can be used without byte swapping. |
| 9365 | * |
| 9366 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9367 | **/ |
| 9368 | static uint16_t |
| 9369 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9370 | struct lpfc_sglq *sglq) |
| 9371 | { |
| 9372 | uint16_t xritag = NO_XRI; |
| 9373 | struct ulp_bde64 *bpl = NULL; |
| 9374 | struct ulp_bde64 bde; |
| 9375 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9376 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9377 | IOCB_t *icmd; |
| 9378 | int numBdes = 0; |
| 9379 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9380 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9381 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9382 | |
| 9383 | if (!piocbq || !sglq) |
| 9384 | return xritag; |
| 9385 | |
| 9386 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9387 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9388 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9389 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9390 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9391 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9392 | sizeof(struct ulp_bde64); |
| 9393 | /* The addrHigh and addrLow fields within the IOCB |
| 9394 | * have not been byteswapped yet so there is no |
| 9395 | * need to swap them back. |
| 9396 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9397 | if (piocbq->context3) |
| 9398 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9399 | else |
| 9400 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9401 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9402 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9403 | if (!bpl) |
| 9404 | return xritag; |
| 9405 | |
| 9406 | for (i = 0; i < numBdes; i++) { |
| 9407 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9408 | sgl->addr_hi = bpl->addrHigh; |
| 9409 | sgl->addr_lo = bpl->addrLow; |
| 9410 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9411 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9412 | if ((i+1) == numBdes) |
| 9413 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9414 | else |
| 9415 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9416 | /* swap the size field back to the cpu so we |
| 9417 | * can assign it to the sgl. |
| 9418 | */ |
| 9419 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9420 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9421 | /* The offsets in the sgl need to be accumulated |
| 9422 | * separately for the request and reply lists. |
| 9423 | * The request is always first, the reply follows. |
| 9424 | */ |
| 9425 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9426 | /* add up the reply sg entries */ |
| 9427 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9428 | inbound++; |
| 9429 | /* first inbound? reset the offset */ |
| 9430 | if (inbound == 1) |
| 9431 | offset = 0; |
| 9432 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9433 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9434 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9435 | offset += bde.tus.f.bdeSize; |
| 9436 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9437 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9438 | bpl++; |
| 9439 | sgl++; |
| 9440 | } |
| 9441 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9442 | /* The addrHigh and addrLow fields of the BDE have not |
| 9443 | * been byteswapped yet so they need to be swapped |
| 9444 | * before putting them in the sgl. |
| 9445 | */ |
| 9446 | sgl->addr_hi = |
| 9447 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9448 | sgl->addr_lo = |
| 9449 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9450 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9451 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9452 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9453 | sgl->sge_len = |
| 9454 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9455 | } |
| 9456 | return sglq->sli4_xritag; |
| 9457 | } |
| 9458 | |
| 9459 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9460 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 9461 | * @phba: Pointer to HBA context object. |
| 9462 | * @piocb: Pointer to command iocb. |
| 9463 | * @wqe: Pointer to the work queue entry. |
| 9464 | * |
| 9465 | * This routine converts the iocb command to its Work Queue Entry |
| 9466 | * equivalent. The wqe pointer should not have any fields set when |
| 9467 | * this routine is called because it will memcpy over them. |
| 9468 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9469 | * wqe. |
| 9470 | * |
| 9471 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9472 | **/ |
| 9473 | static int |
| 9474 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9475 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9476 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9477 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9478 | uint8_t ct = 0; |
| 9479 | uint32_t fip; |
| 9480 | uint32_t abort_tag; |
| 9481 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9482 | uint8_t cmnd; |
| 9483 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9484 | uint16_t abrt_iotag; |
| 9485 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9486 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9487 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9488 | int numBdes, i; |
| 9489 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9490 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9491 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9492 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9493 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9494 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9495 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9496 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9497 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9498 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9499 | command_type = ELS_COMMAND_FIP; |
| 9500 | else |
| 9501 | command_type = ELS_COMMAND_NON_FIP; |
| 9502 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9503 | if (phba->fcp_embed_io) |
| 9504 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9505 | /* Some of the fields are in the right position already */ |
| 9506 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9507 | /* The ct field has moved so reset */ |
| 9508 | wqe->generic.wqe_com.word7 = 0; |
| 9509 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9510 | |
| 9511 | abort_tag = (uint32_t) iocbq->iotag; |
| 9512 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9513 | /* words0-2 bpl convert bde */ |
| 9514 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9515 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9516 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9517 | bpl = (struct ulp_bde64 *) |
| 9518 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9519 | if (!bpl) |
| 9520 | return IOCB_ERROR; |
| 9521 | |
| 9522 | /* Should already be byte swapped. */ |
| 9523 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9524 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9525 | /* swap the size field back to the cpu so we |
| 9526 | * can assign it to the sgl. |
| 9527 | */ |
| 9528 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9529 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9530 | total_len = 0; |
| 9531 | for (i = 0; i < numBdes; i++) { |
| 9532 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9533 | total_len += bde.tus.f.bdeSize; |
| 9534 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9535 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9536 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9537 | |
| 9538 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9539 | cmnd = iocbq->iocb.ulpCommand; |
| 9540 | |
| 9541 | switch (iocbq->iocb.ulpCommand) { |
| 9542 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9543 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9544 | ndlp = iocbq->context_un.ndlp; |
| 9545 | else |
| 9546 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9547 | if (!iocbq->iocb.ulpLe) { |
| 9548 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9549 | "2007 Only Limited Edition cmd Format" |
| 9550 | " supported 0x%x\n", |
| 9551 | iocbq->iocb.ulpCommand); |
| 9552 | return IOCB_ERROR; |
| 9553 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9554 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9555 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9556 | /* Els_reguest64 has a TMO */ |
| 9557 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9558 | iocbq->iocb.ulpTimeout); |
| 9559 | /* Need a VF for word 4 set the vf bit*/ |
| 9560 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9561 | /* And a VFID for word 12 */ |
| 9562 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9563 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9564 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9565 | iocbq->iocb.ulpContext); |
| 9566 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9567 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9568 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9569 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9570 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9571 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9572 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9573 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9574 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9575 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9576 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9577 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9578 | *pcmd == ELS_CMD_SCR || |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 9579 | *pcmd == ELS_CMD_RDF || |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 9580 | *pcmd == ELS_CMD_RSCN_XMT || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9581 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9582 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9583 | *pcmd == ELS_CMD_PLOGI)) { |
| 9584 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9585 | bf_set(els_req64_sid, &wqe->els_req, |
| 9586 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9587 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9588 | !(phba->fc_topology == |
| 9589 | LPFC_TOPOLOGY_LOOP)) |
| 9590 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9591 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9592 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9593 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9594 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9595 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9596 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9597 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9598 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9599 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9600 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9601 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9602 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9603 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9604 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9605 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9606 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9607 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9608 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9609 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9610 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9611 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9612 | iocbq->iocb.un.ulpWord[3]); |
| 9613 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9614 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9615 | /* The entire sequence is transmitted for this IOCB */ |
| 9616 | xmit_len = total_len; |
| 9617 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9618 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9619 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 9620 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9621 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9622 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9623 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9624 | /* word4 relative_offset memcpy */ |
| 9625 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9626 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9627 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9628 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9629 | LPFC_WQE_IOD_WRITE); |
| 9630 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9631 | LPFC_WQE_LENLOC_WORD12); |
| 9632 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9633 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9634 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9635 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9636 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9637 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9638 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9639 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9640 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9641 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9642 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9643 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9644 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9645 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9646 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9647 | LPFC_WQE_LENLOC_WORD3); |
| 9648 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9649 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9650 | case CMD_FCP_IWRITE64_CR: |
| 9651 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9652 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9653 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9654 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9655 | xmit_len + sizeof(struct fcp_rsp)); |
| 9656 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9657 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9658 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9659 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9660 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9661 | iocbq->iocb.ulpFCP2Rcvy); |
| 9662 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9663 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9664 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9665 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9666 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9667 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9668 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9669 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9670 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9671 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9672 | if (iocbq->priority) { |
| 9673 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9674 | (iocbq->priority << 1)); |
| 9675 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9676 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9677 | (phba->cfg_XLanePriority << 1)); |
| 9678 | } |
| 9679 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9680 | /* Note, word 10 is already initialized to 0 */ |
| 9681 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9682 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9683 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9684 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9685 | else |
| 9686 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9687 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9688 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9689 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9690 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9691 | struct fcp_cmnd *fcp_cmnd; |
| 9692 | uint32_t *ptr; |
| 9693 | |
| 9694 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9695 | |
| 9696 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9697 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9698 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9699 | |
| 9700 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9701 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9702 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9703 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9704 | wqe->generic.bde.addrHigh = 0; |
| 9705 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9706 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9707 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9708 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9709 | |
| 9710 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9711 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9712 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9713 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9714 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9715 | case CMD_FCP_IREAD64_CR: |
| 9716 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9717 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9718 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9719 | xmit_len + sizeof(struct fcp_rsp)); |
| 9720 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9721 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9722 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9723 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9724 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9725 | iocbq->iocb.ulpFCP2Rcvy); |
| 9726 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9727 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9728 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9729 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9730 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9731 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9732 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9733 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9734 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9735 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9736 | if (iocbq->priority) { |
| 9737 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9738 | (iocbq->priority << 1)); |
| 9739 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9740 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9741 | (phba->cfg_XLanePriority << 1)); |
| 9742 | } |
| 9743 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9744 | /* Note, word 10 is already initialized to 0 */ |
| 9745 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9746 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9747 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9748 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9749 | else |
| 9750 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9751 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9752 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9753 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9754 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9755 | struct fcp_cmnd *fcp_cmnd; |
| 9756 | uint32_t *ptr; |
| 9757 | |
| 9758 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9759 | |
| 9760 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9761 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9762 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9763 | |
| 9764 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9765 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9766 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9767 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9768 | wqe->generic.bde.addrHigh = 0; |
| 9769 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9770 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9771 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9772 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9773 | |
| 9774 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9775 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9776 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9777 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9778 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9779 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9780 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9781 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9782 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9783 | xmit_len + sizeof(struct fcp_rsp)); |
| 9784 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9785 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9786 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9787 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9788 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9789 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9790 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9791 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9792 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9793 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9794 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9795 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9796 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9797 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9798 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9799 | if (iocbq->priority) { |
| 9800 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9801 | (iocbq->priority << 1)); |
| 9802 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9803 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9804 | (phba->cfg_XLanePriority << 1)); |
| 9805 | } |
| 9806 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9807 | /* Note, word 10 is already initialized to 0 */ |
| 9808 | |
| 9809 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9810 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9811 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9812 | struct fcp_cmnd *fcp_cmnd; |
| 9813 | uint32_t *ptr; |
| 9814 | |
| 9815 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9816 | |
| 9817 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9818 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9819 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9820 | |
| 9821 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9822 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9823 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9824 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9825 | wqe->generic.bde.addrHigh = 0; |
| 9826 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9827 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9828 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9829 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9830 | |
| 9831 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9832 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9833 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9834 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9835 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9836 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9837 | /* For this command calculate the xmit length of the |
| 9838 | * request bde. |
| 9839 | */ |
| 9840 | xmit_len = 0; |
| 9841 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9842 | sizeof(struct ulp_bde64); |
| 9843 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9844 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9845 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9846 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9847 | xmit_len += bde.tus.f.bdeSize; |
| 9848 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9849 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9850 | wqe->gen_req.request_payload_len = xmit_len; |
| 9851 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9852 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9853 | /* word6 context tag copied in memcpy */ |
| 9854 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9855 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9856 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9857 | "2015 Invalid CT %x command 0x%x\n", |
| 9858 | ct, iocbq->iocb.ulpCommand); |
| 9859 | return IOCB_ERROR; |
| 9860 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9861 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9862 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9863 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9864 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9865 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9866 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9867 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9868 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9869 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9870 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9871 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9872 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9873 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9874 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9875 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9876 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9877 | /* word4 */ |
| 9878 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9879 | /* word5 iocb=rsvd wge=did */ |
| 9880 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9881 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9882 | |
| 9883 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9884 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9885 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9886 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9887 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9888 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9889 | iocbq->vport->fc_myDID); |
| 9890 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9891 | bf_set(wqe_els_did, |
| 9892 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9893 | } |
| 9894 | } |
| 9895 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9896 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9897 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9898 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9899 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9900 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9901 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9902 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9903 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9904 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9905 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9906 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9907 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9908 | LPFC_WQE_LENLOC_WORD3); |
| 9909 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9910 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9911 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9912 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9913 | iocbq->context2)->virt); |
| 9914 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9915 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9916 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9917 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9918 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9919 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9920 | phba->vpi_ids[phba->pport->vpi]); |
| 9921 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9922 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9923 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9924 | case CMD_CLOSE_XRI_CN: |
| 9925 | case CMD_ABORT_XRI_CN: |
| 9926 | case CMD_ABORT_XRI_CX: |
| 9927 | /* words 0-2 memcpy should be 0 rserved */ |
| 9928 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9929 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9930 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9931 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9932 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9933 | } else |
| 9934 | fip = 0; |
| 9935 | |
| 9936 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9937 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9938 | * The link is down, or the command was ELS_FIP |
| 9939 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9940 | * on the wire. |
| 9941 | */ |
| 9942 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9943 | else |
| 9944 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9945 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9946 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9947 | wqe->abort_cmd.rsrvd5 = 0; |
| 9948 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9949 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9950 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9951 | /* |
| 9952 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9953 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9954 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9955 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9956 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9957 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9958 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9959 | cmnd = CMD_ABORT_XRI_CX; |
| 9960 | command_type = OTHER_COMMAND; |
| 9961 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9962 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9963 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9964 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9965 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9966 | * we re-construct this WQE here based on information in |
| 9967 | * iocbq from scratch. |
| 9968 | */ |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 9969 | memset(wqe, 0, sizeof(*wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9970 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9971 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9972 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9973 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9974 | LPFC_ABTS_UNSOL_INT) { |
| 9975 | /* ABTS sent by initiator to CT exchange, the |
| 9976 | * RX_ID field will be filled with the newly |
| 9977 | * allocated responder XRI. |
| 9978 | */ |
| 9979 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9980 | iocbq->sli4_xritag); |
| 9981 | } else { |
| 9982 | /* ABTS sent by responder to CT exchange, the |
| 9983 | * RX_ID field will be filled with the responder |
| 9984 | * RX_ID from ABTS. |
| 9985 | */ |
| 9986 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9987 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9988 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9989 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9990 | 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] | 9991 | |
| 9992 | /* Use CT=VPI */ |
| 9993 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9994 | ndlp->nlp_DID); |
| 9995 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9996 | iocbq->iocb.ulpContext); |
| 9997 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9998 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9999 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10000 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 10001 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 10002 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10003 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 10004 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10005 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 10006 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 10007 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 10008 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 10009 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 10010 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 10011 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 10012 | } |
| 10013 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10014 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 10015 | case CMD_SEND_FRAME: |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 10016 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME); |
| 10017 | bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */ |
| 10018 | bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */ |
| 10019 | bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1); |
| 10020 | bf_set(wqe_xbl, &wqe->generic.wqe_com, 1); |
| 10021 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 10022 | bf_set(wqe_xc, &wqe->generic.wqe_com, 1); |
| 10023 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA); |
| 10024 | 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] | 10025 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 10026 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 10027 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10028 | case CMD_XRI_ABORTED_CX: |
| 10029 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10030 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 10031 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 10032 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 10033 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 10034 | default: |
| 10035 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 10036 | "2014 Invalid command 0x%x\n", |
| 10037 | iocbq->iocb.ulpCommand); |
| 10038 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10039 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10040 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10041 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 10042 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 10043 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 10044 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 10045 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 10046 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 10047 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 10048 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 10049 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10050 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 10051 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 10052 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 10053 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 10054 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 10055 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 10056 | 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] | 10057 | return 0; |
| 10058 | } |
| 10059 | |
| 10060 | /** |
| 10061 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 10062 | * @phba: Pointer to HBA context object. |
| 10063 | * @ring_number: SLI ring number to issue iocb on. |
| 10064 | * @piocb: Pointer to command iocb. |
| 10065 | * @flag: Flag indicating if this command can be put into txq. |
| 10066 | * |
| 10067 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 10068 | * an iocb command to an HBA with SLI-4 interface spec. |
| 10069 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 10070 | * This function is called with ringlock held. The function will return success |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10071 | * after it successfully submit the iocb to firmware or after adding to the |
| 10072 | * txq. |
| 10073 | **/ |
| 10074 | static int |
| 10075 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 10076 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10077 | { |
| 10078 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10079 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10080 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10081 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10082 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10083 | /* Get the WQ */ |
| 10084 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 10085 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10086 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10087 | } else { |
| 10088 | wq = phba->sli4_hba.els_wq; |
| 10089 | } |
| 10090 | |
| 10091 | /* Get corresponding ring */ |
| 10092 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10093 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10094 | /* |
| 10095 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10096 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10097 | |
James Smart | cda7fa18 | 2019-03-04 15:15:43 -0800 | [diff] [blame] | 10098 | lockdep_assert_held(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10099 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10100 | if (piocb->sli4_xritag == NO_XRI) { |
| 10101 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10102 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10103 | sglq = NULL; |
| 10104 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10105 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10106 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 10107 | __lpfc_sli_ringtx_put(phba, |
| 10108 | pring, piocb); |
| 10109 | return IOCB_SUCCESS; |
| 10110 | } else { |
| 10111 | return IOCB_BUSY; |
| 10112 | } |
| 10113 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10114 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10115 | if (!sglq) { |
| 10116 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 10117 | __lpfc_sli_ringtx_put(phba, |
| 10118 | pring, |
| 10119 | piocb); |
| 10120 | return IOCB_SUCCESS; |
| 10121 | } else |
| 10122 | return IOCB_BUSY; |
| 10123 | } |
| 10124 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10125 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 10126 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10127 | /* These IO's already have an XRI and a mapped sgl. */ |
| 10128 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 10129 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10130 | /* |
| 10131 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10132 | * sglq is on the active list |
| 10133 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 10134 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10135 | if (!sglq) |
| 10136 | return IOCB_ERROR; |
| 10137 | } |
| 10138 | |
| 10139 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10140 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10141 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10142 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10143 | return IOCB_ERROR; |
| 10144 | } |
| 10145 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10146 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10147 | return IOCB_ERROR; |
| 10148 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10149 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10150 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10151 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 10152 | |
| 10153 | return 0; |
| 10154 | } |
| 10155 | |
| 10156 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10157 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 10158 | * |
| 10159 | * This routine wraps the actual lockless version for issusing IOCB function |
| 10160 | * pointer from the lpfc_hba struct. |
| 10161 | * |
| 10162 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10163 | * IOCB_ERROR - Error |
| 10164 | * IOCB_SUCCESS - Success |
| 10165 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10166 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10167 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10168 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 10169 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10170 | { |
| 10171 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10172 | } |
| 10173 | |
| 10174 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10175 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10176 | * @phba: The hba struct for which this call is being executed. |
| 10177 | * @dev_grp: The HBA PCI-Device group number. |
| 10178 | * |
| 10179 | * This routine sets up the SLI interface API function jump table in @phba |
| 10180 | * struct. |
| 10181 | * Returns: 0 - success, -ENODEV - failure. |
| 10182 | **/ |
| 10183 | int |
| 10184 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 10185 | { |
| 10186 | |
| 10187 | switch (dev_grp) { |
| 10188 | case LPFC_PCI_DEV_LP: |
| 10189 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 10190 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 10191 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10192 | case LPFC_PCI_DEV_OC: |
| 10193 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 10194 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 10195 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10196 | default: |
| 10197 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10198 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 10199 | dev_grp); |
| 10200 | return -ENODEV; |
| 10201 | break; |
| 10202 | } |
| 10203 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 10204 | return 0; |
| 10205 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10206 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10207 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10208 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10209 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10210 | * @piocb: Pointer to command iocb. |
| 10211 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10212 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 10213 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10214 | * 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] | 10215 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10216 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10217 | struct lpfc_sli_ring * |
| 10218 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10219 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10220 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10221 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10222 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10223 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 10224 | return NULL; |
| 10225 | /* |
| 10226 | * for abort iocb hba_wqidx should already |
| 10227 | * be setup based on what work queue we used. |
| 10228 | */ |
| 10229 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10230 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 10231 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10232 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10233 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10234 | } else { |
| 10235 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10236 | return NULL; |
| 10237 | piocb->hba_wqidx = 0; |
| 10238 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10239 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10240 | } |
| 10241 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10242 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10243 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10244 | * @phba: Pointer to HBA context object. |
| 10245 | * @pring: Pointer to driver SLI ring object. |
| 10246 | * @piocb: Pointer to command iocb. |
| 10247 | * @flag: Flag indicating if this command can be put into txq. |
| 10248 | * |
| 10249 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10250 | * function. This function gets the hbalock and calls |
| 10251 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10252 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10253 | * functions which do not hold hbalock. |
| 10254 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10255 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10256 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10257 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10258 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10259 | struct lpfc_sli_ring *pring; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10260 | struct lpfc_queue *eq; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10261 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10262 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10263 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10264 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10265 | eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq; |
| 10266 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10267 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10268 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10269 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10270 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10271 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10272 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10273 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10274 | |
| 10275 | lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10276 | } else { |
| 10277 | /* For now, SLI2/3 will still use hbalock */ |
| 10278 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10279 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10280 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10281 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10282 | return rc; |
| 10283 | } |
| 10284 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10285 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10286 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10287 | * @phba: Pointer to HBA context object. |
| 10288 | * |
| 10289 | * This function is called while driver attaches with the |
| 10290 | * HBA to setup the extra ring. The extra ring is used |
| 10291 | * only when driver needs to support target mode functionality |
| 10292 | * or IP over FC functionalities. |
| 10293 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10294 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10295 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10296 | static int |
| 10297 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10298 | { |
| 10299 | struct lpfc_sli *psli; |
| 10300 | struct lpfc_sli_ring *pring; |
| 10301 | |
| 10302 | psli = &phba->sli; |
| 10303 | |
| 10304 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10305 | |
| 10306 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10307 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10308 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10309 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10310 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10311 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10312 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10313 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10314 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10315 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10316 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10317 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10318 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10319 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10320 | |
| 10321 | /* Setup default profile for this ring */ |
| 10322 | pring->iotag_max = 4096; |
| 10323 | pring->num_mask = 1; |
| 10324 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10325 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10326 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10327 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10328 | return 0; |
| 10329 | } |
| 10330 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10331 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10332 | * @phba: Pointer to HBA context object. |
| 10333 | * @iocbq: Pointer to iocb object. |
| 10334 | * |
| 10335 | * The async_event handler calls this routine when it receives |
| 10336 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10337 | * this event when an Abort Sequence request to an rport fails |
| 10338 | * twice in succession. The abort could be originated by the |
| 10339 | * driver or by the port. The ABTS could have been for an ELS |
| 10340 | * or FCP IO. The port only generates this event when an ABTS |
| 10341 | * fails to complete after one retry. |
| 10342 | */ |
| 10343 | static void |
| 10344 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10345 | struct lpfc_iocbq *iocbq) |
| 10346 | { |
| 10347 | struct lpfc_nodelist *ndlp = NULL; |
| 10348 | uint16_t rpi = 0, vpi = 0; |
| 10349 | struct lpfc_vport *vport = NULL; |
| 10350 | |
| 10351 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10352 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10353 | rpi = iocbq->iocb.ulpContext; |
| 10354 | |
| 10355 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10356 | "3092 Port generated ABTS async event " |
| 10357 | "on vpi %d rpi %d status 0x%x\n", |
| 10358 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10359 | |
| 10360 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10361 | if (!vport) |
| 10362 | goto err_exit; |
| 10363 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 10364 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 10365 | goto err_exit; |
| 10366 | |
| 10367 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10368 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10369 | return; |
| 10370 | |
| 10371 | err_exit: |
| 10372 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10373 | "3095 Event Context not found, no " |
| 10374 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10375 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10376 | vpi, rpi); |
| 10377 | } |
| 10378 | |
| 10379 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10380 | * @phba: pointer to HBA context object. |
| 10381 | * @ndlp: nodelist pointer for the impacted rport. |
| 10382 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10383 | * |
| 10384 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10385 | * port. The port generates this event when an abort exchange request to an |
| 10386 | * rport fails twice in succession with no reply. The abort could be originated |
| 10387 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10388 | */ |
| 10389 | void |
| 10390 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10391 | struct lpfc_nodelist *ndlp, |
| 10392 | struct sli4_wcqe_xri_aborted *axri) |
| 10393 | { |
| 10394 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10395 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10396 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10397 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10398 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10399 | "3115 Node Context not found, driver " |
| 10400 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10401 | return; |
| 10402 | } |
| 10403 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10404 | vport = ndlp->vport; |
| 10405 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10406 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10407 | "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] | 10408 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10409 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10410 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10411 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10412 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10413 | /* |
| 10414 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10415 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10416 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10417 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10418 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10419 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10420 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10421 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10422 | } |
| 10423 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10424 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10425 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10426 | * @phba: Pointer to HBA context object. |
| 10427 | * @pring: Pointer to driver SLI ring object. |
| 10428 | * @iocbq: Pointer to iocb object. |
| 10429 | * |
| 10430 | * This function is called by the slow ring event handler |
| 10431 | * function when there is an ASYNC event iocb in the ring. |
| 10432 | * This function is called with no lock held. |
| 10433 | * Currently this function handles only temperature related |
| 10434 | * ASYNC events. The function decodes the temperature sensor |
| 10435 | * event message and posts events for the management applications. |
| 10436 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10437 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10438 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10439 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10440 | { |
| 10441 | IOCB_t *icmd; |
| 10442 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10443 | struct temp_event temp_event_data; |
| 10444 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10445 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10446 | |
| 10447 | icmd = &iocbq->iocb; |
| 10448 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10449 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10450 | switch (evt_code) { |
| 10451 | case ASYNC_TEMP_WARN: |
| 10452 | case ASYNC_TEMP_SAFE: |
| 10453 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10454 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10455 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10456 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 10457 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10458 | "0347 Adapter is very hot, please take " |
| 10459 | "corrective action. temperature : %d Celsius\n", |
| 10460 | (uint32_t) icmd->ulpContext); |
| 10461 | } else { |
| 10462 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 10463 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10464 | "0340 Adapter temperature is OK now. " |
| 10465 | "temperature : %d Celsius\n", |
| 10466 | (uint32_t) icmd->ulpContext); |
| 10467 | } |
| 10468 | |
| 10469 | /* Send temperature change event to applications */ |
| 10470 | shost = lpfc_shost_from_vport(phba->pport); |
| 10471 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10472 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10473 | LPFC_NL_VENDOR_ID); |
| 10474 | break; |
| 10475 | case ASYNC_STATUS_CN: |
| 10476 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10477 | break; |
| 10478 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10479 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10480 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10481 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10482 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10483 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10484 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10485 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10486 | "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] | 10487 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10488 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10489 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10490 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10491 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10492 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10493 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10494 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10495 | } |
| 10496 | |
| 10497 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10498 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10499 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10500 | * @phba: Pointer to HBA context object. |
| 10501 | * |
| 10502 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10503 | * number of iocbs per ring and iotags. This function is |
| 10504 | * called while driver attach to the HBA and before the |
| 10505 | * interrupts are enabled. So there is no need for locking. |
| 10506 | * |
| 10507 | * This function always returns 0. |
| 10508 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10509 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10510 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10511 | { |
| 10512 | struct lpfc_sli_ring *pring; |
| 10513 | |
| 10514 | pring = phba->sli4_hba.els_wq->pring; |
| 10515 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10516 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10517 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10518 | pring->prt[0].type = FC_TYPE_ELS; |
| 10519 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10520 | lpfc_els_unsol_event; |
| 10521 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10522 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10523 | pring->prt[1].type = FC_TYPE_ELS; |
| 10524 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10525 | lpfc_els_unsol_event; |
| 10526 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10527 | /* NameServer Inquiry */ |
| 10528 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10529 | /* NameServer */ |
| 10530 | pring->prt[2].type = FC_TYPE_CT; |
| 10531 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10532 | lpfc_ct_unsol_event; |
| 10533 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10534 | /* NameServer response */ |
| 10535 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10536 | /* NameServer */ |
| 10537 | pring->prt[3].type = FC_TYPE_CT; |
| 10538 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10539 | lpfc_ct_unsol_event; |
| 10540 | return 0; |
| 10541 | } |
| 10542 | |
| 10543 | /** |
| 10544 | * lpfc_sli_setup - SLI ring setup function |
| 10545 | * @phba: Pointer to HBA context object. |
| 10546 | * |
| 10547 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10548 | * number of iocbs per ring and iotags. This function is |
| 10549 | * called while driver attach to the HBA and before the |
| 10550 | * interrupts are enabled. So there is no need for locking. |
| 10551 | * |
| 10552 | * This function always returns 0. SLI3 only. |
| 10553 | **/ |
| 10554 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10555 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10556 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10557 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10558 | struct lpfc_sli *psli = &phba->sli; |
| 10559 | struct lpfc_sli_ring *pring; |
| 10560 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10561 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10562 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10563 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10564 | psli->iocbq_lookup = NULL; |
| 10565 | psli->iocbq_lookup_len = 0; |
| 10566 | psli->last_iotag = 0; |
| 10567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10568 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10569 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10570 | switch (i) { |
| 10571 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10572 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10573 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10574 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10575 | pring->sli.sli3.numCiocb += |
| 10576 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10577 | pring->sli.sli3.numRiocb += |
| 10578 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10579 | pring->sli.sli3.numCiocb += |
| 10580 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10581 | pring->sli.sli3.numRiocb += |
| 10582 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10583 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10584 | SLI3_IOCB_CMD_SIZE : |
| 10585 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10586 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10587 | SLI3_IOCB_RSP_SIZE : |
| 10588 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10589 | pring->iotag_ctr = 0; |
| 10590 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10591 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10592 | pring->fast_iotag = pring->iotag_max; |
| 10593 | pring->num_mask = 0; |
| 10594 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10595 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10596 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10597 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10598 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10599 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10600 | SLI3_IOCB_CMD_SIZE : |
| 10601 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10602 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10603 | SLI3_IOCB_RSP_SIZE : |
| 10604 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10605 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10606 | pring->num_mask = 0; |
| 10607 | break; |
| 10608 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10609 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10610 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10611 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10612 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10613 | SLI3_IOCB_CMD_SIZE : |
| 10614 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10615 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10616 | SLI3_IOCB_RSP_SIZE : |
| 10617 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10618 | pring->fast_iotag = 0; |
| 10619 | pring->iotag_ctr = 0; |
| 10620 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10621 | pring->lpfc_sli_rcv_async_status = |
| 10622 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10623 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10624 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10625 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10626 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10627 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10628 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10629 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10630 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10631 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10632 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10633 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10634 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10635 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10636 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10637 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10638 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10639 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10640 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10641 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10642 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10643 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10644 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10645 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10646 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10647 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10648 | break; |
| 10649 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10650 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10651 | pring->sli.sli3.sizeCiocb) + |
| 10652 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10653 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10654 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10655 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10656 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10657 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10658 | phba->brd_no, totiocbsize, |
| 10659 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10660 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10661 | if (phba->cfg_multi_ring_support == 2) |
| 10662 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10663 | |
| 10664 | return 0; |
| 10665 | } |
| 10666 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10667 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10668 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10669 | * @phba: Pointer to HBA context object. |
| 10670 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10671 | * 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] | 10672 | * ring. This function also initializes ring indices of each ring. |
| 10673 | * This function is called during the initialization of the SLI |
| 10674 | * interface of an HBA. |
| 10675 | * This function is called with no lock held and always returns |
| 10676 | * 1. |
| 10677 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10678 | void |
| 10679 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10680 | { |
| 10681 | struct lpfc_sli *psli; |
| 10682 | struct lpfc_sli_ring *pring; |
| 10683 | int i; |
| 10684 | |
| 10685 | psli = &phba->sli; |
| 10686 | spin_lock_irq(&phba->hbalock); |
| 10687 | INIT_LIST_HEAD(&psli->mboxq); |
| 10688 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10689 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10690 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10691 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10692 | pring->flag = 0; |
| 10693 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10694 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10695 | INIT_LIST_HEAD(&pring->txq); |
| 10696 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10697 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10698 | spin_lock_init(&pring->ring_lock); |
| 10699 | } |
| 10700 | pring = phba->sli4_hba.els_wq->pring; |
| 10701 | pring->flag = 0; |
| 10702 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10703 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10704 | INIT_LIST_HEAD(&pring->txq); |
| 10705 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10706 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10707 | spin_lock_init(&pring->ring_lock); |
| 10708 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10709 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10710 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10711 | pring->flag = 0; |
| 10712 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10713 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10714 | INIT_LIST_HEAD(&pring->txq); |
| 10715 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10716 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10717 | spin_lock_init(&pring->ring_lock); |
| 10718 | } |
| 10719 | |
| 10720 | spin_unlock_irq(&phba->hbalock); |
| 10721 | } |
| 10722 | |
| 10723 | /** |
| 10724 | * lpfc_sli_queue_init - Queue initialization function |
| 10725 | * @phba: Pointer to HBA context object. |
| 10726 | * |
| 10727 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10728 | * ring. This function also initializes ring indices of each ring. |
| 10729 | * This function is called during the initialization of the SLI |
| 10730 | * interface of an HBA. |
| 10731 | * This function is called with no lock held and always returns |
| 10732 | * 1. |
| 10733 | **/ |
| 10734 | void |
| 10735 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10736 | { |
| 10737 | struct lpfc_sli *psli; |
| 10738 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10739 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10740 | |
| 10741 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10742 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10743 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10744 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10745 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10746 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10747 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10748 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10749 | pring->sli.sli3.next_cmdidx = 0; |
| 10750 | pring->sli.sli3.local_getidx = 0; |
| 10751 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10752 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10753 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10754 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10755 | pring->flag = 0; |
| 10756 | INIT_LIST_HEAD(&pring->txq); |
| 10757 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10758 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10759 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10760 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10761 | } |
| 10762 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10763 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10764 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10765 | * @phba: Pointer to HBA context object. |
| 10766 | * |
| 10767 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10768 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10769 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10770 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10771 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10772 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10773 | * pending mailbox command queue from the various clients must be stopped; |
| 10774 | * either the HBA is in a state that it will never works on the outstanding |
| 10775 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10776 | * mailbox command has been completed. |
| 10777 | **/ |
| 10778 | static void |
| 10779 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10780 | { |
| 10781 | LIST_HEAD(completions); |
| 10782 | struct lpfc_sli *psli = &phba->sli; |
| 10783 | LPFC_MBOXQ_t *pmb; |
| 10784 | unsigned long iflag; |
| 10785 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10786 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10787 | local_bh_disable(); |
| 10788 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10789 | /* Flush all the mailbox commands in the mbox system */ |
| 10790 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10791 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10792 | /* The pending mailbox command queue */ |
| 10793 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10794 | /* The outstanding active mailbox command */ |
| 10795 | if (psli->mbox_active) { |
| 10796 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10797 | psli->mbox_active = NULL; |
| 10798 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10799 | } |
| 10800 | /* The completed mailbox command queue */ |
| 10801 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10802 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10803 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10804 | /* Enable softirqs again, done with phba->hbalock */ |
| 10805 | local_bh_enable(); |
| 10806 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10807 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10808 | while (!list_empty(&completions)) { |
| 10809 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10810 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10811 | if (pmb->mbox_cmpl) |
| 10812 | pmb->mbox_cmpl(phba, pmb); |
| 10813 | } |
| 10814 | } |
| 10815 | |
| 10816 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10817 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10818 | * @vport: Pointer to virtual port object. |
| 10819 | * |
| 10820 | * lpfc_sli_host_down is called to clean up the resources |
| 10821 | * associated with a vport before destroying virtual |
| 10822 | * port data structures. |
| 10823 | * This function does following operations: |
| 10824 | * - Free discovery resources associated with this virtual |
| 10825 | * port. |
| 10826 | * - Free iocbs associated with this virtual port in |
| 10827 | * the txq. |
| 10828 | * - Send abort for all iocb commands associated with this |
| 10829 | * vport in txcmplq. |
| 10830 | * |
| 10831 | * This function is called with no lock held and always returns 1. |
| 10832 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10833 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10834 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10835 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10836 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10837 | struct lpfc_hba *phba = vport->phba; |
| 10838 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10839 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10840 | struct lpfc_sli_ring *pring; |
| 10841 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10842 | int i; |
| 10843 | unsigned long flags = 0; |
| 10844 | uint16_t prev_pring_flag; |
| 10845 | |
| 10846 | lpfc_cleanup_discovery_resources(vport); |
| 10847 | |
| 10848 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10849 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10850 | /* |
| 10851 | * Error everything on the txq since these iocbs |
| 10852 | * have not been given to the FW yet. |
| 10853 | * Also issue ABTS for everything on the txcmplq |
| 10854 | */ |
| 10855 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10856 | for (i = 0; i < psli->num_rings; i++) { |
| 10857 | pring = &psli->sli3_ring[i]; |
| 10858 | prev_pring_flag = pring->flag; |
| 10859 | /* Only slow rings */ |
| 10860 | if (pring->ringno == LPFC_ELS_RING) { |
| 10861 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10862 | /* Set the lpfc data pending flag */ |
| 10863 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10864 | } |
| 10865 | list_for_each_entry_safe(iocb, next_iocb, |
| 10866 | &pring->txq, list) { |
| 10867 | if (iocb->vport != vport) |
| 10868 | continue; |
| 10869 | list_move_tail(&iocb->list, &completions); |
| 10870 | } |
| 10871 | list_for_each_entry_safe(iocb, next_iocb, |
| 10872 | &pring->txcmplq, list) { |
| 10873 | if (iocb->vport != vport) |
| 10874 | continue; |
| 10875 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10876 | } |
| 10877 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10878 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10879 | } else { |
| 10880 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10881 | pring = qp->pring; |
| 10882 | if (!pring) |
| 10883 | continue; |
| 10884 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10885 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10886 | /* Set the lpfc data pending flag */ |
| 10887 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10888 | } |
| 10889 | prev_pring_flag = pring->flag; |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10890 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10891 | list_for_each_entry_safe(iocb, next_iocb, |
| 10892 | &pring->txq, list) { |
| 10893 | if (iocb->vport != vport) |
| 10894 | continue; |
| 10895 | list_move_tail(&iocb->list, &completions); |
| 10896 | } |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10897 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10898 | list_for_each_entry_safe(iocb, next_iocb, |
| 10899 | &pring->txcmplq, list) { |
| 10900 | if (iocb->vport != vport) |
| 10901 | continue; |
| 10902 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10903 | } |
| 10904 | pring->flag = prev_pring_flag; |
| 10905 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10906 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10907 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10908 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10909 | /* Cancel all the IOCBs from the completions list */ |
| 10910 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10911 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10912 | return 1; |
| 10913 | } |
| 10914 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10915 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10916 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10917 | * @phba: Pointer to HBA context object. |
| 10918 | * |
| 10919 | * This function cleans up all iocb, buffers, mailbox commands |
| 10920 | * while shutting down the HBA. This function is called with no |
| 10921 | * lock held and always returns 1. |
| 10922 | * This function does the following to cleanup driver resources: |
| 10923 | * - Free discovery resources for each virtual port |
| 10924 | * - Cleanup any pending fabric iocbs |
| 10925 | * - Iterate through the iocb txq and free each entry |
| 10926 | * in the list. |
| 10927 | * - Free up any buffer posted to the HBA |
| 10928 | * - Free mailbox commands in the mailbox queue. |
| 10929 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10930 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10931 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10932 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10933 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10934 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10935 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10936 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10937 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10938 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10939 | int i; |
| 10940 | |
| 10941 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10942 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10943 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10944 | lpfc_hba_down_prep(phba); |
| 10945 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10946 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10947 | local_bh_disable(); |
| 10948 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10949 | lpfc_fabric_abort_hba(phba); |
| 10950 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10951 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10952 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10953 | /* |
| 10954 | * Error everything on the txq since these iocbs |
| 10955 | * have not been given to the FW yet. |
| 10956 | */ |
| 10957 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10958 | for (i = 0; i < psli->num_rings; i++) { |
| 10959 | pring = &psli->sli3_ring[i]; |
| 10960 | /* Only slow rings */ |
| 10961 | if (pring->ringno == LPFC_ELS_RING) { |
| 10962 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10963 | /* Set the lpfc data pending flag */ |
| 10964 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10965 | } |
| 10966 | list_splice_init(&pring->txq, &completions); |
| 10967 | } |
| 10968 | } else { |
| 10969 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10970 | pring = qp->pring; |
| 10971 | if (!pring) |
| 10972 | continue; |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 10973 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10974 | list_splice_init(&pring->txq, &completions); |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 10975 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10976 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10977 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10978 | /* Set the lpfc data pending flag */ |
| 10979 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10980 | } |
| 10981 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10982 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10983 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10984 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10985 | /* Cancel all the IOCBs from the completions list */ |
| 10986 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10987 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10988 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10989 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10990 | list_splice_init(&phba->elsbuf, &completions); |
| 10991 | phba->elsbuf_cnt = 0; |
| 10992 | phba->elsbuf_prev_cnt = 0; |
| 10993 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10994 | |
| 10995 | while (!list_empty(&completions)) { |
| 10996 | list_remove_head(&completions, buf_ptr, |
| 10997 | struct lpfc_dmabuf, list); |
| 10998 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10999 | kfree(buf_ptr); |
| 11000 | } |
| 11001 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11002 | /* Enable softirqs again, done with phba->hbalock */ |
| 11003 | local_bh_enable(); |
| 11004 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11005 | /* Return any active mbox cmds */ |
| 11006 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11007 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11008 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11009 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11010 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11011 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11012 | return 1; |
| 11013 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11014 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11015 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11016 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11017 | * @srcp: Source memory pointer. |
| 11018 | * @destp: Destination memory pointer. |
| 11019 | * @cnt: Number of words required to be copied. |
| 11020 | * |
| 11021 | * This function is used for copying data between driver memory |
| 11022 | * and the SLI memory. This function also changes the endianness |
| 11023 | * of each word if native endianness is different from SLI |
| 11024 | * endianness. This function can be called with or without |
| 11025 | * lock. |
| 11026 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11027 | void |
| 11028 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 11029 | { |
| 11030 | uint32_t *src = srcp; |
| 11031 | uint32_t *dest = destp; |
| 11032 | uint32_t ldata; |
| 11033 | int i; |
| 11034 | |
| 11035 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 11036 | ldata = *src; |
| 11037 | ldata = le32_to_cpu(ldata); |
| 11038 | *dest = ldata; |
| 11039 | src++; |
| 11040 | dest++; |
| 11041 | } |
| 11042 | } |
| 11043 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11044 | |
| 11045 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 11046 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 11047 | * @srcp: Source memory pointer. |
| 11048 | * @destp: Destination memory pointer. |
| 11049 | * @cnt: Number of words required to be copied. |
| 11050 | * |
| 11051 | * This function is used for copying data between a data structure |
| 11052 | * with big endian representation to local endianness. |
| 11053 | * This function can be called with or without lock. |
| 11054 | **/ |
| 11055 | void |
| 11056 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 11057 | { |
| 11058 | uint32_t *src = srcp; |
| 11059 | uint32_t *dest = destp; |
| 11060 | uint32_t ldata; |
| 11061 | int i; |
| 11062 | |
| 11063 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 11064 | ldata = *src; |
| 11065 | ldata = be32_to_cpu(ldata); |
| 11066 | *dest = ldata; |
| 11067 | src++; |
| 11068 | dest++; |
| 11069 | } |
| 11070 | } |
| 11071 | |
| 11072 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11073 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11074 | * @phba: Pointer to HBA context object. |
| 11075 | * @pring: Pointer to driver SLI ring object. |
| 11076 | * @mp: Pointer to driver buffer object. |
| 11077 | * |
| 11078 | * This function is called with no lock held. |
| 11079 | * It always return zero after adding the buffer to the postbufq |
| 11080 | * buffer list. |
| 11081 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11082 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11083 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11084 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11085 | { |
| 11086 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 11087 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11088 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11089 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11090 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11091 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11092 | return 0; |
| 11093 | } |
| 11094 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11095 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11096 | * 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] | 11097 | * @phba: Pointer to HBA context object. |
| 11098 | * |
| 11099 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 11100 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 11101 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 11102 | * does not conflict with tags of buffer posted for unsolicited events. |
| 11103 | * The function returns the allocated tag. The function is called with |
| 11104 | * no locks held. |
| 11105 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11106 | uint32_t |
| 11107 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 11108 | { |
| 11109 | spin_lock_irq(&phba->hbalock); |
| 11110 | phba->buffer_tag_count++; |
| 11111 | /* |
| 11112 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 11113 | * a tag assigned by HBQ. |
| 11114 | */ |
| 11115 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 11116 | spin_unlock_irq(&phba->hbalock); |
| 11117 | return phba->buffer_tag_count; |
| 11118 | } |
| 11119 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11120 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11121 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11122 | * @phba: Pointer to HBA context object. |
| 11123 | * @pring: Pointer to driver SLI ring object. |
| 11124 | * @tag: Buffer tag. |
| 11125 | * |
| 11126 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 11127 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 11128 | * iocb is posted to the response ring with the tag of the buffer. |
| 11129 | * This function searches the pring->postbufq list using the tag |
| 11130 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 11131 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 11132 | * buffer is returned to the caller else NULL is returned. |
| 11133 | * This function is called with no lock held. |
| 11134 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11135 | struct lpfc_dmabuf * |
| 11136 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11137 | uint32_t tag) |
| 11138 | { |
| 11139 | struct lpfc_dmabuf *mp, *next_mp; |
| 11140 | struct list_head *slp = &pring->postbufq; |
| 11141 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11142 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11143 | spin_lock_irq(&phba->hbalock); |
| 11144 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11145 | if (mp->buffer_tag == tag) { |
| 11146 | list_del_init(&mp->list); |
| 11147 | pring->postbufq_cnt--; |
| 11148 | spin_unlock_irq(&phba->hbalock); |
| 11149 | return mp; |
| 11150 | } |
| 11151 | } |
| 11152 | |
| 11153 | spin_unlock_irq(&phba->hbalock); |
| 11154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11155 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11156 | "ring %d Data x%lx x%px x%px x%x\n", |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11157 | pring->ringno, (unsigned long) tag, |
| 11158 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11159 | |
| 11160 | return NULL; |
| 11161 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11162 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11163 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11164 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11165 | * @phba: Pointer to HBA context object. |
| 11166 | * @pring: Pointer to driver SLI ring object. |
| 11167 | * @phys: DMA address of the buffer. |
| 11168 | * |
| 11169 | * This function searches the buffer list using the dma_address |
| 11170 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 11171 | * corresponding to the dma_address. The function returns the |
| 11172 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 11173 | * This function is called by the ct and els unsolicited event |
| 11174 | * handlers to get the buffer associated with the unsolicited |
| 11175 | * event. |
| 11176 | * |
| 11177 | * This function is called with no lock held. |
| 11178 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11179 | struct lpfc_dmabuf * |
| 11180 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11181 | dma_addr_t phys) |
| 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 phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11187 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11188 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11189 | if (mp->phys == phys) { |
| 11190 | list_del_init(&mp->list); |
| 11191 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11192 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11193 | return mp; |
| 11194 | } |
| 11195 | } |
| 11196 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11197 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11198 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11199 | "0410 Cannot find virtual addr for mapped buf on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11200 | "ring %d Data x%llx x%px x%px x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11201 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11202 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11203 | return NULL; |
| 11204 | } |
| 11205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11207 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11208 | * @phba: Pointer to HBA context object. |
| 11209 | * @cmdiocb: Pointer to driver command iocb object. |
| 11210 | * @rspiocb: Pointer to driver response iocb object. |
| 11211 | * |
| 11212 | * This function is the completion handler for the abort iocbs for |
| 11213 | * ELS commands. This function is called from the ELS ring event |
| 11214 | * handler with no lock held. This function frees memory resources |
| 11215 | * associated with the abort iocb. |
| 11216 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11217 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11218 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11219 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11220 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11221 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11222 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11223 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11224 | |
| 11225 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11226 | |
| 11227 | /* |
| 11228 | * Assume that the port already completed and returned, or |
| 11229 | * will return the iocb. Just Log the message. |
| 11230 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11231 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11232 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11233 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11234 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11235 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11236 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11237 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11238 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11239 | spin_unlock_irq(&phba->hbalock); |
| 11240 | goto release_iocb; |
| 11241 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11242 | if (abort_iotag != 0 && |
| 11243 | abort_iotag <= phba->sli.last_iotag) |
| 11244 | abort_iocb = |
| 11245 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11246 | } else |
| 11247 | /* For sli4 the abort_tag is the XRI, |
| 11248 | * so the abort routine puts the iotag of the iocb |
| 11249 | * being aborted in the context field of the abort |
| 11250 | * IOCB. |
| 11251 | */ |
| 11252 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11253 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11254 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11255 | "0327 Cannot abort els iocb x%px " |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11256 | "with tag %x context %x, abort status %x, " |
| 11257 | "abort code %x\n", |
| 11258 | abort_iocb, abort_iotag, abort_context, |
| 11259 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11260 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11261 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11262 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11263 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11264 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11265 | return; |
| 11266 | } |
| 11267 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11268 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11269 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11270 | * @phba: Pointer to HBA context object. |
| 11271 | * @cmdiocb: Pointer to driver command iocb object. |
| 11272 | * @rspiocb: Pointer to driver response iocb object. |
| 11273 | * |
| 11274 | * The function is called from SLI ring event handler with no |
| 11275 | * lock held. This function is the completion handler for ELS commands |
| 11276 | * which are aborted. The function frees memory resources used for |
| 11277 | * the aborted ELS commands. |
| 11278 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11279 | static void |
| 11280 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11281 | struct lpfc_iocbq *rspiocb) |
| 11282 | { |
| 11283 | IOCB_t *irsp = &rspiocb->iocb; |
| 11284 | |
| 11285 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11286 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11287 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11288 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11289 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11290 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11291 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11292 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11293 | else |
| 11294 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11295 | return; |
| 11296 | } |
| 11297 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11298 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11299 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11300 | * @phba: Pointer to HBA context object. |
| 11301 | * @pring: Pointer to driver SLI ring object. |
| 11302 | * @cmdiocb: Pointer to driver command iocb object. |
| 11303 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11304 | * This function issues an abort iocb for the provided command iocb down to |
| 11305 | * the port. Other than the case the outstanding command iocb is an abort |
| 11306 | * request, this function issues abort out unconditionally. This function is |
| 11307 | * called with hbalock held. The function returns 0 when it fails due to |
| 11308 | * memory allocation failure or when the command iocb is an abort request. |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 11309 | * The hbalock is asserted held in the code path calling this routine. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11310 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11311 | static int |
| 11312 | 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] | 11313 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11314 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11315 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11316 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11317 | IOCB_t *icmd = NULL; |
| 11318 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11319 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11320 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11321 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11322 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11323 | /* |
| 11324 | * There are certain command types we don't want to abort. And we |
| 11325 | * don't want to abort commands that are already in the process of |
| 11326 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11327 | */ |
| 11328 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11329 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11330 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11331 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11332 | return 0; |
| 11333 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11334 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11335 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11336 | if (abtsiocbp == NULL) |
| 11337 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11338 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11339 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11340 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11341 | */ |
| 11342 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11343 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11344 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11345 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11346 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11347 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11348 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11349 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11350 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11351 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11352 | if (pring->ringno == LPFC_ELS_RING) { |
| 11353 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11354 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11355 | } |
| 11356 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11357 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11358 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11359 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11360 | /* 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] | 11361 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11362 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 11363 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11364 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11365 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11366 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11367 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11368 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11369 | else |
| 11370 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11371 | |
| 11372 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11373 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11374 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11375 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11376 | "0339 Abort xri x%x, original iotag x%x, " |
| 11377 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11378 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11379 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11380 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11381 | |
| 11382 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11383 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11384 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11385 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11386 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11387 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11388 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11389 | abtsiocbp, 0); |
| 11390 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11391 | } else { |
| 11392 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11393 | abtsiocbp, 0); |
| 11394 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11395 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11396 | if (retval) |
| 11397 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11398 | |
| 11399 | /* |
| 11400 | * Caller to this routine should check for IOCB_ERROR |
| 11401 | * and handle it properly. This routine no longer removes |
| 11402 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 11403 | */ |
| 11404 | return retval; |
| 11405 | } |
| 11406 | |
| 11407 | /** |
| 11408 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 11409 | * @phba: Pointer to HBA context object. |
| 11410 | * @pring: Pointer to driver SLI ring object. |
| 11411 | * @cmdiocb: Pointer to driver command iocb object. |
| 11412 | * |
| 11413 | * This function issues an abort iocb for the provided command iocb. In case |
| 11414 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11415 | * ring. Instead, the callback function shall be changed to those commands |
| 11416 | * so that nothing happens when them finishes. This function is called with |
| 11417 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 11418 | * request. |
| 11419 | **/ |
| 11420 | int |
| 11421 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11422 | struct lpfc_iocbq *cmdiocb) |
| 11423 | { |
| 11424 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11425 | int retval = IOCB_ERROR; |
| 11426 | IOCB_t *icmd = NULL; |
| 11427 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11428 | lockdep_assert_held(&phba->hbalock); |
| 11429 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11430 | /* |
| 11431 | * There are certain command types we don't want to abort. And we |
| 11432 | * don't want to abort commands that are already in the process of |
| 11433 | * being aborted. |
| 11434 | */ |
| 11435 | icmd = &cmdiocb->iocb; |
| 11436 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11437 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11438 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11439 | return 0; |
| 11440 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 11441 | if (!pring) { |
| 11442 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11443 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11444 | else |
| 11445 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11446 | goto abort_iotag_exit; |
| 11447 | } |
| 11448 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11449 | /* |
| 11450 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11451 | * the callback so that nothing happens when it finishes. |
| 11452 | */ |
| 11453 | if ((vport->load_flag & FC_UNLOADING) && |
| 11454 | (pring->ringno == LPFC_ELS_RING)) { |
| 11455 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11456 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11457 | else |
| 11458 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11459 | goto abort_iotag_exit; |
| 11460 | } |
| 11461 | |
| 11462 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 11463 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 11464 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11465 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11466 | /* |
| 11467 | * Caller to this routine should check for IOCB_ERROR |
| 11468 | * and handle it properly. This routine no longer removes |
| 11469 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11470 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11471 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11472 | } |
| 11473 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11474 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11475 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11476 | * @phba: pointer to lpfc HBA data structure. |
| 11477 | * |
| 11478 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11479 | **/ |
| 11480 | void |
| 11481 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11482 | { |
| 11483 | struct lpfc_sli *psli = &phba->sli; |
| 11484 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11485 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11486 | int i; |
| 11487 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11488 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11489 | for (i = 0; i < psli->num_rings; i++) { |
| 11490 | pring = &psli->sli3_ring[i]; |
| 11491 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11492 | } |
| 11493 | return; |
| 11494 | } |
| 11495 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11496 | pring = qp->pring; |
| 11497 | if (!pring) |
| 11498 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11499 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11500 | } |
| 11501 | } |
| 11502 | |
| 11503 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11504 | * 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] | 11505 | * @iocbq: Pointer to driver iocb object. |
| 11506 | * @vport: Pointer to driver virtual port object. |
| 11507 | * @tgt_id: SCSI ID of the target. |
| 11508 | * @lun_id: LUN ID of the scsi device. |
| 11509 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11510 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11511 | * 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] | 11512 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11513 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11514 | * 1 if the filtering criteria is not met. |
| 11515 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11516 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11517 | * lun_id parameter. |
| 11518 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11519 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11520 | * parameters. |
| 11521 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11522 | * given iocb is for the SCSI host associated with the given vport. |
| 11523 | * This function is called with no locks held. |
| 11524 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11525 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11526 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11527 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11528 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11529 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11530 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11531 | int rc = 1; |
| 11532 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11533 | if (iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11534 | return rc; |
| 11535 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11536 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11537 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11538 | return rc; |
| 11539 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11540 | 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] | 11541 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11542 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11543 | return rc; |
| 11544 | |
| 11545 | switch (ctx_cmd) { |
| 11546 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11547 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11548 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11549 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11550 | rc = 0; |
| 11551 | break; |
| 11552 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11553 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11554 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11555 | rc = 0; |
| 11556 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11557 | case LPFC_CTX_HOST: |
| 11558 | rc = 0; |
| 11559 | break; |
| 11560 | default: |
| 11561 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11562 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11563 | break; |
| 11564 | } |
| 11565 | |
| 11566 | return rc; |
| 11567 | } |
| 11568 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11569 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11570 | * 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] | 11571 | * @vport: Pointer to virtual port. |
| 11572 | * @tgt_id: SCSI ID of the target. |
| 11573 | * @lun_id: LUN ID of the scsi device. |
| 11574 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11575 | * |
| 11576 | * This function returns number of FCP commands pending for the vport. |
| 11577 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11578 | * commands pending on the vport associated with SCSI device specified |
| 11579 | * by tgt_id and lun_id parameters. |
| 11580 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11581 | * commands pending on the vport associated with SCSI target specified |
| 11582 | * by tgt_id parameter. |
| 11583 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11584 | * commands pending on the vport. |
| 11585 | * This function returns the number of iocbs which satisfy the filter. |
| 11586 | * This function is called without any lock held. |
| 11587 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11588 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11589 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11590 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11591 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11592 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11593 | struct lpfc_iocbq *iocbq; |
| 11594 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11595 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11596 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11597 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11598 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11599 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11600 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11601 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11602 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11603 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11604 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11605 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11606 | return sum; |
| 11607 | } |
| 11608 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11609 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11610 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11611 | * @phba: Pointer to HBA context object |
| 11612 | * @cmdiocb: Pointer to command iocb object. |
| 11613 | * @rspiocb: Pointer to response iocb object. |
| 11614 | * |
| 11615 | * This function is called when an aborted FCP iocb completes. This |
| 11616 | * function is called by the ring event handler with no lock held. |
| 11617 | * This function frees the iocb. |
| 11618 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11619 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11620 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11621 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11622 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11623 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11624 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11625 | "original iotag x%x, abort cmd iotag x%x " |
| 11626 | "status 0x%x, reason 0x%x\n", |
| 11627 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11628 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11629 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11630 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11631 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11632 | return; |
| 11633 | } |
| 11634 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11635 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11636 | * 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] | 11637 | * @vport: Pointer to virtual port. |
| 11638 | * @pring: Pointer to driver SLI ring object. |
| 11639 | * @tgt_id: SCSI ID of the target. |
| 11640 | * @lun_id: LUN ID of the scsi device. |
| 11641 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11642 | * |
| 11643 | * This function sends an abort command for every SCSI command |
| 11644 | * associated with the given virtual port pending on the ring |
| 11645 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11646 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11647 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11648 | * parameters |
| 11649 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11650 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11651 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11652 | * FCP iocbs associated with virtual port. |
| 11653 | * This function returns number of iocbs it failed to abort. |
| 11654 | * This function is called with no locks held. |
| 11655 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11656 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11657 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11658 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11659 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11660 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11661 | struct lpfc_iocbq *iocbq; |
| 11662 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11663 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11664 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11665 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11666 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11667 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11668 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11669 | if (phba->hba_flag & HBA_IOQ_FLUSH) |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11670 | return errcnt; |
| 11671 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11672 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11673 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11674 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11675 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11676 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11677 | continue; |
| 11678 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11679 | /* |
| 11680 | * If the iocbq is already being aborted, don't take a second |
| 11681 | * action, but do count it. |
| 11682 | */ |
| 11683 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11684 | continue; |
| 11685 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11686 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11687 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11688 | if (abtsiocb == NULL) { |
| 11689 | errcnt++; |
| 11690 | continue; |
| 11691 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11692 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11693 | /* indicate the IO is being aborted by the driver. */ |
| 11694 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11695 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11696 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11697 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11698 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11699 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11700 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11701 | else |
| 11702 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11703 | abtsiocb->iocb.ulpLe = 1; |
| 11704 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11705 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11706 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11707 | /* 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] | 11708 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11709 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11710 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11711 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11712 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11713 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11714 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11715 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11716 | else |
| 11717 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11718 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11719 | /* Setup callback routine and issue the command. */ |
| 11720 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11721 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11722 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11723 | if (!pring_s4) |
| 11724 | continue; |
| 11725 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11726 | abtsiocb, 0); |
| 11727 | } else |
| 11728 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11729 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11730 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11731 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11732 | errcnt++; |
| 11733 | continue; |
| 11734 | } |
| 11735 | } |
| 11736 | |
| 11737 | return errcnt; |
| 11738 | } |
| 11739 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11740 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11741 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11742 | * @vport: Pointer to virtual port. |
| 11743 | * @pring: Pointer to driver SLI ring object. |
| 11744 | * @tgt_id: SCSI ID of the target. |
| 11745 | * @lun_id: LUN ID of the scsi device. |
| 11746 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11747 | * |
| 11748 | * This function sends an abort command for every SCSI command |
| 11749 | * associated with the given virtual port pending on the ring |
| 11750 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11751 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11752 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11753 | * parameters |
| 11754 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11755 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11756 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11757 | * FCP iocbs associated with virtual port. |
| 11758 | * This function returns number of iocbs it aborted . |
| 11759 | * This function is called with no locks held right after a taskmgmt |
| 11760 | * command is sent. |
| 11761 | **/ |
| 11762 | int |
| 11763 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11764 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11765 | { |
| 11766 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11767 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11768 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11769 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11770 | struct lpfc_iocbq *iocbq; |
| 11771 | IOCB_t *icmd; |
| 11772 | int sum, i, ret_val; |
| 11773 | unsigned long iflags; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11774 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11775 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11776 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11777 | |
| 11778 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11779 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11780 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11781 | return 0; |
| 11782 | } |
| 11783 | sum = 0; |
| 11784 | |
| 11785 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11786 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11787 | |
| 11788 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11789 | cmd) != 0) |
| 11790 | continue; |
| 11791 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11792 | /* Guard against IO completion being called at same time */ |
| 11793 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
| 11794 | spin_lock(&lpfc_cmd->buf_lock); |
| 11795 | |
| 11796 | if (!lpfc_cmd->pCmd) { |
| 11797 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11798 | continue; |
| 11799 | } |
| 11800 | |
| 11801 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11802 | pring_s4 = |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11803 | phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11804 | if (!pring_s4) { |
| 11805 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11806 | continue; |
| 11807 | } |
| 11808 | /* Note: both hbalock and ring_lock must be set here */ |
| 11809 | spin_lock(&pring_s4->ring_lock); |
| 11810 | } |
| 11811 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11812 | /* |
| 11813 | * If the iocbq is already being aborted, don't take a second |
| 11814 | * action, but do count it. |
| 11815 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11816 | if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) || |
| 11817 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
| 11818 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11819 | spin_unlock(&pring_s4->ring_lock); |
| 11820 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11821 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11822 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11823 | |
| 11824 | /* issue ABTS for this IOCB based on iotag */ |
| 11825 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11826 | if (!abtsiocbq) { |
| 11827 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11828 | spin_unlock(&pring_s4->ring_lock); |
| 11829 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11830 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11831 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11832 | |
| 11833 | icmd = &iocbq->iocb; |
| 11834 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11835 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11836 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11837 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11838 | iocbq->sli4_xritag; |
| 11839 | else |
| 11840 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11841 | abtsiocbq->iocb.ulpLe = 1; |
| 11842 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11843 | abtsiocbq->vport = vport; |
| 11844 | |
| 11845 | /* 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] | 11846 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11847 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11848 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11849 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11850 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11851 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11852 | ndlp = lpfc_cmd->rdata->pnode; |
| 11853 | |
| 11854 | if (lpfc_is_link_up(phba) && |
| 11855 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11856 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11857 | else |
| 11858 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11859 | |
| 11860 | /* Setup callback routine and issue the command. */ |
| 11861 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11862 | |
| 11863 | /* |
| 11864 | * Indicate the IO is being aborted by the driver and set |
| 11865 | * the caller's flag into the aborted IO. |
| 11866 | */ |
| 11867 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11868 | |
| 11869 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11870 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11871 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11872 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11873 | } else { |
| 11874 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11875 | abtsiocbq, 0); |
| 11876 | } |
| 11877 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11878 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11879 | |
| 11880 | if (ret_val == IOCB_ERROR) |
| 11881 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11882 | else |
| 11883 | sum++; |
| 11884 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11885 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11886 | return sum; |
| 11887 | } |
| 11888 | |
| 11889 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11890 | * 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] | 11891 | * @phba: Pointer to HBA context object. |
| 11892 | * @cmdiocbq: Pointer to command iocb. |
| 11893 | * @rspiocbq: Pointer to response iocb. |
| 11894 | * |
| 11895 | * This function is the completion handler for iocbs issued using |
| 11896 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11897 | * ring event handler function without any lock held. This function |
| 11898 | * can be called from both worker thread context and interrupt |
| 11899 | * context. This function also can be called from other thread which |
| 11900 | * cleans up the SLI layer objects. |
| 11901 | * This function copy the contents of the response iocb to the |
| 11902 | * response iocb memory object provided by the caller of |
| 11903 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11904 | * sleeps for the iocb completion. |
| 11905 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11906 | static void |
| 11907 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11908 | struct lpfc_iocbq *cmdiocbq, |
| 11909 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11910 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11911 | wait_queue_head_t *pdone_q; |
| 11912 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11913 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11914 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11915 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11916 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11917 | |
| 11918 | /* |
| 11919 | * A time out has occurred for the iocb. If a time out |
| 11920 | * completion handler has been supplied, call it. Otherwise, |
| 11921 | * just free the iocbq. |
| 11922 | */ |
| 11923 | |
| 11924 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11925 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11926 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11927 | if (cmdiocbq->iocb_cmpl) |
| 11928 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11929 | else |
| 11930 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11931 | return; |
| 11932 | } |
| 11933 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11934 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11935 | if (cmdiocbq->context2 && rspiocbq) |
| 11936 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11937 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11938 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11939 | /* Set the exchange busy flag for task management commands */ |
| 11940 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11941 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11942 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11943 | cur_iocbq); |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 11944 | if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY)) |
| 11945 | lpfc_cmd->flags |= LPFC_SBUF_XBUSY; |
| 11946 | else |
| 11947 | lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11948 | } |
| 11949 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11950 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11951 | if (pdone_q) |
| 11952 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11953 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11954 | return; |
| 11955 | } |
| 11956 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11957 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11958 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11959 | * @phba: Pointer to HBA context object.. |
| 11960 | * @piocbq: Pointer to command iocb. |
| 11961 | * @flag: Flag to test. |
| 11962 | * |
| 11963 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11964 | * see if the passed in flag is set. |
| 11965 | * Returns: |
| 11966 | * 1 if flag is set. |
| 11967 | * 0 if flag is not set. |
| 11968 | **/ |
| 11969 | static int |
| 11970 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11971 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11972 | { |
| 11973 | unsigned long iflags; |
| 11974 | int ret; |
| 11975 | |
| 11976 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11977 | ret = piocbq->iocb_flag & flag; |
| 11978 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11979 | return ret; |
| 11980 | |
| 11981 | } |
| 11982 | |
| 11983 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11984 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11985 | * @phba: Pointer to HBA context object.. |
| 11986 | * @pring: Pointer to sli ring. |
| 11987 | * @piocb: Pointer to command iocb. |
| 11988 | * @prspiocbq: Pointer to response iocb. |
| 11989 | * @timeout: Timeout in number of seconds. |
| 11990 | * |
| 11991 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11992 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11993 | * to handle iocbs which time out. If the field is NULL, the |
| 11994 | * function shall free the iocbq structure. If more clean up is |
| 11995 | * needed, the caller is expected to provide a completion function |
| 11996 | * that will provide the needed clean up. If the iocb command is |
| 11997 | * not completed within timeout seconds, the function will either |
| 11998 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11999 | * completion function set in the iocb_cmpl field and then return |
| 12000 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 12001 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12002 | * The function waits for the iocb completion using an |
| 12003 | * non-interruptible wait. |
| 12004 | * This function will sleep while waiting for iocb completion. |
| 12005 | * So, this function should not be called from any context which |
| 12006 | * does not allow sleeping. Due to the same reason, this function |
| 12007 | * cannot be called with interrupt disabled. |
| 12008 | * This function assumes that the iocb completions occur while |
| 12009 | * this function sleep. So, this function cannot be called from |
| 12010 | * the thread which process iocb completion for this ring. |
| 12011 | * This function clears the iocb_flag of the iocb object before |
| 12012 | * issuing the iocb and the iocb completion handler sets this |
| 12013 | * flag and wakes this thread when the iocb completes. |
| 12014 | * The contents of the response iocb will be copied to prspiocbq |
| 12015 | * by the completion handler when the command completes. |
| 12016 | * This function returns IOCB_SUCCESS when success. |
| 12017 | * This function is called with no lock held. |
| 12018 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12019 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12020 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12021 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12022 | struct lpfc_iocbq *piocb, |
| 12023 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12024 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12025 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 12026 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12027 | long timeleft, timeout_req = 0; |
| 12028 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12029 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12030 | struct lpfc_iocbq *iocb; |
| 12031 | int txq_cnt = 0; |
| 12032 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12033 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12034 | unsigned long iflags; |
| 12035 | bool iocb_completed = true; |
| 12036 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12037 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 12038 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 12039 | else |
| 12040 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12041 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12042 | * If the caller has provided a response iocbq buffer, then context2 |
| 12043 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12044 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12045 | if (prspiocbq) { |
| 12046 | if (piocb->context2) |
| 12047 | return IOCB_ERROR; |
| 12048 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12049 | } |
| 12050 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12051 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12052 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 12053 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12054 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12055 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12056 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12057 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12058 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12059 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 12060 | writel(creg_val, phba->HCregaddr); |
| 12061 | readl(phba->HCregaddr); /* flush */ |
| 12062 | } |
| 12063 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12064 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 12065 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12066 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 12067 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12068 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 12069 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12070 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12071 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12072 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12073 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12074 | /* |
| 12075 | * IOCB timed out. Inform the wake iocb wait |
| 12076 | * completion function and set local status |
| 12077 | */ |
| 12078 | |
| 12079 | iocb_completed = false; |
| 12080 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 12081 | } |
| 12082 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12083 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12084 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12085 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 12086 | /* Note: we are not indicating if the IOCB has a success |
| 12087 | * status or not - that's for the caller to check. |
| 12088 | * IOCB_SUCCESS means just that the command was sent and |
| 12089 | * completed. Not that it completed successfully. |
| 12090 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12091 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12092 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12093 | "0338 IOCB wait timeout error - no " |
| 12094 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12095 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12096 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12097 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12098 | "0330 IOCB wake NOT set, " |
| 12099 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12100 | timeout, (timeleft / jiffies)); |
| 12101 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12102 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12103 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12104 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 12105 | list_for_each_entry(iocb, &pring->txq, list) { |
| 12106 | txq_cnt++; |
| 12107 | } |
| 12108 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 12109 | txcmplq_cnt++; |
| 12110 | } |
| 12111 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12112 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 12113 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 12114 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12115 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12116 | } else { |
| 12117 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12118 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12119 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12120 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12121 | } |
| 12122 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12123 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12124 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12125 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12126 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 12127 | writel(creg_val, phba->HCregaddr); |
| 12128 | readl(phba->HCregaddr); /* flush */ |
| 12129 | } |
| 12130 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12131 | if (prspiocbq) |
| 12132 | piocb->context2 = NULL; |
| 12133 | |
| 12134 | piocb->context_un.wait_queue = NULL; |
| 12135 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12136 | return retval; |
| 12137 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12138 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12139 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12140 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12141 | * @phba: Pointer to HBA context object. |
| 12142 | * @pmboxq: Pointer to driver mailbox object. |
| 12143 | * @timeout: Timeout in number of seconds. |
| 12144 | * |
| 12145 | * This function issues the mailbox to firmware and waits for the |
| 12146 | * mailbox command to complete. If the mailbox command is not |
| 12147 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 12148 | * The function waits for the mailbox completion using an |
| 12149 | * interruptible wait. If the thread is woken up due to a |
| 12150 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 12151 | * should not free the mailbox resources, if this function returns |
| 12152 | * MBX_TIMEOUT. |
| 12153 | * This function will sleep while waiting for mailbox completion. |
| 12154 | * So, this function should not be called from any context which |
| 12155 | * does not allow sleeping. Due to the same reason, this function |
| 12156 | * cannot be called with interrupt disabled. |
| 12157 | * This function assumes that the mailbox completion occurs while |
| 12158 | * this function sleep. So, this function cannot be called from |
| 12159 | * the worker thread which processes mailbox completion. |
| 12160 | * This function is called in the context of HBA management |
| 12161 | * applications. |
| 12162 | * This function returns MBX_SUCCESS when successful. |
| 12163 | * This function is called with no lock held. |
| 12164 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12165 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12166 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12167 | uint32_t timeout) |
| 12168 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12169 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12170 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12171 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12172 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12173 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12174 | /* setup wake call as IOCB callback */ |
| 12175 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12176 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12177 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 12178 | init_completion(&mbox_done); |
| 12179 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12180 | /* now issue the command */ |
| 12181 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12182 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12183 | wait_for_completion_timeout(&mbox_done, |
| 12184 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12185 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12186 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12187 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12188 | /* |
| 12189 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 12190 | * else do not free the resources. |
| 12191 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12192 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12193 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12194 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12195 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12196 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12197 | } |
| 12198 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12199 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12200 | return retval; |
| 12201 | } |
| 12202 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12203 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12204 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12205 | * @phba: Pointer to HBA context. |
| 12206 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12207 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12208 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12209 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12210 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12211 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12212 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12213 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12214 | * as with offline or HBA function reset), this routine will wait for the |
| 12215 | * outstanding mailbox command to complete before invoking the mailbox |
| 12216 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12217 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12218 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12219 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12220 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12221 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12222 | unsigned long timeout; |
| 12223 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12224 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12225 | /* delay 100ms for port state */ |
| 12226 | msleep(100); |
| 12227 | lpfc_sli_mbox_sys_flush(phba); |
| 12228 | return; |
| 12229 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12230 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12231 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12232 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12233 | local_bh_disable(); |
| 12234 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12235 | spin_lock_irq(&phba->hbalock); |
| 12236 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12237 | |
| 12238 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12239 | /* Determine how long we might wait for the active mailbox |
| 12240 | * command to be gracefully completed by firmware. |
| 12241 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12242 | if (phba->sli.mbox_active) |
| 12243 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12244 | phba->sli.mbox_active) * |
| 12245 | 1000) + jiffies; |
| 12246 | spin_unlock_irq(&phba->hbalock); |
| 12247 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12248 | /* Enable softirqs again, done with phba->hbalock */ |
| 12249 | local_bh_enable(); |
| 12250 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12251 | while (phba->sli.mbox_active) { |
| 12252 | /* Check active mailbox complete status every 2ms */ |
| 12253 | msleep(2); |
| 12254 | if (time_after(jiffies, timeout)) |
| 12255 | /* Timeout, let the mailbox flush routine to |
| 12256 | * forcefully release active mailbox command |
| 12257 | */ |
| 12258 | break; |
| 12259 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12260 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12261 | spin_unlock_irq(&phba->hbalock); |
| 12262 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12263 | /* Enable softirqs again, done with phba->hbalock */ |
| 12264 | local_bh_enable(); |
| 12265 | } |
| 12266 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12267 | lpfc_sli_mbox_sys_flush(phba); |
| 12268 | } |
| 12269 | |
| 12270 | /** |
| 12271 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12272 | * @phba: Pointer to HBA context. |
| 12273 | * |
| 12274 | * This function is called to read the SLI3 device error attention registers |
| 12275 | * for possible error attention events. The caller must hold the hostlock |
| 12276 | * with spin_lock_irq(). |
| 12277 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12278 | * 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] | 12279 | * Register and returns 0 otherwise. |
| 12280 | **/ |
| 12281 | static int |
| 12282 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12283 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12284 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12285 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12286 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12287 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12288 | goto unplug_err; |
| 12289 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12290 | if (ha_copy & HA_ERATT) { |
| 12291 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12292 | if (lpfc_sli_read_hs(phba)) |
| 12293 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12294 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12295 | /* Check if there is a deferred error condition is active */ |
| 12296 | if ((HS_FFER1 & phba->work_hs) && |
| 12297 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12298 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12299 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12300 | /* Clear all interrupt enable conditions */ |
| 12301 | writel(0, phba->HCregaddr); |
| 12302 | readl(phba->HCregaddr); |
| 12303 | } |
| 12304 | |
| 12305 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12306 | phba->work_ha |= HA_ERATT; |
| 12307 | /* Indicate polling handles this ERATT */ |
| 12308 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12309 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12310 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12311 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12312 | |
| 12313 | unplug_err: |
| 12314 | /* Set the driver HS work bitmap */ |
| 12315 | phba->work_hs |= UNPLUG_ERR; |
| 12316 | /* Set the driver HA work bitmap */ |
| 12317 | phba->work_ha |= HA_ERATT; |
| 12318 | /* Indicate polling handles this ERATT */ |
| 12319 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12320 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12321 | } |
| 12322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12323 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12324 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12325 | * @phba: Pointer to HBA context. |
| 12326 | * |
| 12327 | * This function is called to read the SLI4 device error attention registers |
| 12328 | * for possible error attention events. The caller must hold the hostlock |
| 12329 | * with spin_lock_irq(). |
| 12330 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12331 | * 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] | 12332 | * Register and returns 0 otherwise. |
| 12333 | **/ |
| 12334 | static int |
| 12335 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12336 | { |
| 12337 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12338 | uint32_t if_type, portsmphr; |
| 12339 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12340 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12341 | /* |
| 12342 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12343 | * registers for error attention. This can be changed later. |
| 12344 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12345 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12346 | switch (if_type) { |
| 12347 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12348 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12349 | &uerr_sta_lo) || |
| 12350 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12351 | &uerr_sta_hi)) { |
| 12352 | phba->work_hs |= UNPLUG_ERR; |
| 12353 | phba->work_ha |= HA_ERATT; |
| 12354 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12355 | return 1; |
| 12356 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12357 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12358 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 12359 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12360 | "1423 HBA Unrecoverable error: " |
| 12361 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12362 | "ue_mask_lo_reg=0x%x, " |
| 12363 | "ue_mask_hi_reg=0x%x\n", |
| 12364 | uerr_sta_lo, uerr_sta_hi, |
| 12365 | phba->sli4_hba.ue_mask_lo, |
| 12366 | phba->sli4_hba.ue_mask_hi); |
| 12367 | phba->work_status[0] = uerr_sta_lo; |
| 12368 | phba->work_status[1] = uerr_sta_hi; |
| 12369 | phba->work_ha |= HA_ERATT; |
| 12370 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12371 | return 1; |
| 12372 | } |
| 12373 | break; |
| 12374 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12375 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12376 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12377 | &portstat_reg.word0) || |
| 12378 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12379 | &portsmphr)){ |
| 12380 | phba->work_hs |= UNPLUG_ERR; |
| 12381 | phba->work_ha |= HA_ERATT; |
| 12382 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12383 | return 1; |
| 12384 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12385 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12386 | phba->work_status[0] = |
| 12387 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12388 | phba->work_status[1] = |
| 12389 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 12390 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12391 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12392 | "port status reg 0x%x, " |
| 12393 | "port smphr reg 0x%x, " |
| 12394 | "error 1=0x%x, error 2=0x%x\n", |
| 12395 | portstat_reg.word0, |
| 12396 | portsmphr, |
| 12397 | phba->work_status[0], |
| 12398 | phba->work_status[1]); |
| 12399 | phba->work_ha |= HA_ERATT; |
| 12400 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12401 | return 1; |
| 12402 | } |
| 12403 | break; |
| 12404 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12405 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12406 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12407 | "2886 HBA Error Attention on unsupported " |
| 12408 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12409 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12410 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12411 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12412 | return 0; |
| 12413 | } |
| 12414 | |
| 12415 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12416 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12417 | * @phba: Pointer to HBA context. |
| 12418 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12419 | * 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] | 12420 | * error attention register bit for error attention events. |
| 12421 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12422 | * 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] | 12423 | * Register and returns 0 otherwise. |
| 12424 | **/ |
| 12425 | int |
| 12426 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12427 | { |
| 12428 | uint32_t ha_copy; |
| 12429 | |
| 12430 | /* If somebody is waiting to handle an eratt, don't process it |
| 12431 | * here. The brdkill function will do this. |
| 12432 | */ |
| 12433 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12434 | return 0; |
| 12435 | |
| 12436 | /* Check if interrupt handler handles this ERATT */ |
| 12437 | spin_lock_irq(&phba->hbalock); |
| 12438 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12439 | /* Interrupt handler has handled ERATT */ |
| 12440 | spin_unlock_irq(&phba->hbalock); |
| 12441 | return 0; |
| 12442 | } |
| 12443 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12444 | /* |
| 12445 | * If there is deferred error attention, do not check for error |
| 12446 | * attention |
| 12447 | */ |
| 12448 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12449 | spin_unlock_irq(&phba->hbalock); |
| 12450 | return 0; |
| 12451 | } |
| 12452 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12453 | /* If PCI channel is offline, don't process it */ |
| 12454 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12455 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12456 | return 0; |
| 12457 | } |
| 12458 | |
| 12459 | switch (phba->sli_rev) { |
| 12460 | case LPFC_SLI_REV2: |
| 12461 | case LPFC_SLI_REV3: |
| 12462 | /* Read chip Host Attention (HA) register */ |
| 12463 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12464 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12465 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12466 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12467 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12468 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12469 | default: |
| 12470 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12471 | "0299 Invalid SLI revision (%d)\n", |
| 12472 | phba->sli_rev); |
| 12473 | ha_copy = 0; |
| 12474 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12475 | } |
| 12476 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12477 | |
| 12478 | return ha_copy; |
| 12479 | } |
| 12480 | |
| 12481 | /** |
| 12482 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12483 | * @phba: Pointer to HBA context. |
| 12484 | * |
| 12485 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12486 | * that the interrupt should be handled. |
| 12487 | * |
| 12488 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12489 | * interrupt should be handled, otherwise -EIO. |
| 12490 | */ |
| 12491 | static inline int |
| 12492 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12493 | { |
| 12494 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12495 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12496 | return -EIO; |
| 12497 | |
| 12498 | /* Update device level interrupt statistics */ |
| 12499 | phba->sli.slistat.sli_intr++; |
| 12500 | |
| 12501 | /* Ignore all interrupts during initialization. */ |
| 12502 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12503 | return -EIO; |
| 12504 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12505 | return 0; |
| 12506 | } |
| 12507 | |
| 12508 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12509 | * 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] | 12510 | * @irq: Interrupt number. |
| 12511 | * @dev_id: The device context pointer. |
| 12512 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12513 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12514 | * service routine when device with SLI-3 interface spec is enabled with |
| 12515 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12516 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12517 | * interrupt mode, this function is called as part of the device-level |
| 12518 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12519 | * is undergoing initialization, the interrupt handler will not process |
| 12520 | * the interrupt. The link attention and ELS ring attention events are |
| 12521 | * handled by the worker thread. The interrupt handler signals the worker |
| 12522 | * thread and returns for these events. This function is called without |
| 12523 | * 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] | 12524 | * structures. |
| 12525 | * |
| 12526 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12527 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12528 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12529 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12530 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12531 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12532 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12533 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12534 | uint32_t work_ha_copy; |
| 12535 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12536 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12537 | uint32_t control; |
| 12538 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12539 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12540 | struct lpfc_vport *vport; |
| 12541 | struct lpfc_nodelist *ndlp; |
| 12542 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12543 | LPFC_MBOXQ_t *pmb; |
| 12544 | int rc; |
| 12545 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12546 | /* |
| 12547 | * Get the driver's phba structure from the dev_id and |
| 12548 | * assume the HBA is not interrupting. |
| 12549 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12550 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12551 | |
| 12552 | if (unlikely(!phba)) |
| 12553 | return IRQ_NONE; |
| 12554 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12555 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12556 | * Stuff needs to be attented to when this function is invoked as an |
| 12557 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12558 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12559 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12560 | /* Check device state for handling interrupt */ |
| 12561 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12562 | return IRQ_NONE; |
| 12563 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12564 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12565 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12566 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12567 | /* If somebody is waiting to handle an eratt don't process it |
| 12568 | * here. The brdkill function will do this. |
| 12569 | */ |
| 12570 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12571 | ha_copy &= ~HA_ERATT; |
| 12572 | /* Check the need for handling ERATT in interrupt handler */ |
| 12573 | if (ha_copy & HA_ERATT) { |
| 12574 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12575 | /* ERATT polling has handled ERATT */ |
| 12576 | ha_copy &= ~HA_ERATT; |
| 12577 | else |
| 12578 | /* Indicate interrupt handler handles ERATT */ |
| 12579 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12580 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12581 | |
| 12582 | /* |
| 12583 | * If there is deferred error attention, do not check for any |
| 12584 | * interrupt. |
| 12585 | */ |
| 12586 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12587 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12588 | return IRQ_NONE; |
| 12589 | } |
| 12590 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12591 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12592 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12593 | goto unplug_error; |
| 12594 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12595 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12596 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12597 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12598 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12599 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12600 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12601 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12602 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12603 | } else |
| 12604 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12605 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12606 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12607 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12608 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12609 | if (work_ha_copy & HA_LATT) { |
| 12610 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12611 | /* |
| 12612 | * Turn off Link Attention interrupts |
| 12613 | * until CLEAR_LA done |
| 12614 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12615 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12616 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12617 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12618 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12619 | control &= ~HC_LAINT_ENA; |
| 12620 | writel(control, phba->HCregaddr); |
| 12621 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12622 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12623 | } |
| 12624 | else |
| 12625 | work_ha_copy &= ~HA_LATT; |
| 12626 | } |
| 12627 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12628 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12629 | /* |
| 12630 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12631 | * the only slow ring. |
| 12632 | */ |
| 12633 | status = (work_ha_copy & |
| 12634 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12635 | status >>= (4*LPFC_ELS_RING); |
| 12636 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12637 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12638 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12639 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12640 | |
| 12641 | lpfc_debugfs_slow_ring_trc(phba, |
| 12642 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12643 | control, status, |
| 12644 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12645 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12646 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12647 | lpfc_debugfs_slow_ring_trc(phba, |
| 12648 | "ISR Disable ring:" |
| 12649 | "pwork:x%x hawork:x%x wait:x%x", |
| 12650 | phba->work_ha, work_ha_copy, |
| 12651 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12652 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12653 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12654 | control &= |
| 12655 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12656 | writel(control, phba->HCregaddr); |
| 12657 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12658 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12659 | else { |
| 12660 | lpfc_debugfs_slow_ring_trc(phba, |
| 12661 | "ISR slow ring: pwork:" |
| 12662 | "x%x hawork:x%x wait:x%x", |
| 12663 | phba->work_ha, work_ha_copy, |
| 12664 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12665 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12666 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12667 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12668 | } |
| 12669 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12670 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12671 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12672 | if (lpfc_sli_read_hs(phba)) |
| 12673 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12674 | /* |
| 12675 | * Check if there is a deferred error condition |
| 12676 | * is active |
| 12677 | */ |
| 12678 | if ((HS_FFER1 & phba->work_hs) && |
| 12679 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12680 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12681 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12682 | phba->hba_flag |= DEFER_ERATT; |
| 12683 | /* Clear all interrupt enable conditions */ |
| 12684 | writel(0, phba->HCregaddr); |
| 12685 | readl(phba->HCregaddr); |
| 12686 | } |
| 12687 | } |
| 12688 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12689 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12690 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12691 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12692 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12693 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12694 | |
| 12695 | /* First check out the status word */ |
| 12696 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12697 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12698 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12699 | /* |
| 12700 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12701 | * mbxStatus <status> |
| 12702 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12703 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12704 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12705 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12706 | "Interrupt mbxCommand x%x " |
| 12707 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12708 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12709 | pmbox->mbxCommand, |
| 12710 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12711 | /* clear mailbox attention bit */ |
| 12712 | work_ha_copy &= ~HA_MBATT; |
| 12713 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12714 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12715 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12716 | phba->last_completion_time = jiffies; |
| 12717 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12718 | if (pmb->mbox_cmpl) { |
| 12719 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12720 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12721 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12722 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12723 | lpfc_sli_pcimem_bcopy( |
| 12724 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12725 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12726 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12727 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12728 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12729 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12730 | |
| 12731 | lpfc_debugfs_disc_trc(vport, |
| 12732 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12733 | "MBOX dflt rpi: : " |
| 12734 | "status:x%x rpi:x%x", |
| 12735 | (uint32_t)pmbox->mbxStatus, |
| 12736 | pmbox->un.varWords[0], 0); |
| 12737 | |
| 12738 | if (!pmbox->mbxStatus) { |
| 12739 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12740 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12741 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12742 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12743 | |
| 12744 | /* Reg_LOGIN of dflt RPI was |
| 12745 | * successful. new lets get |
| 12746 | * rid of the RPI using the |
| 12747 | * same mbox buffer. |
| 12748 | */ |
| 12749 | lpfc_unreg_login(phba, |
| 12750 | vport->vpi, |
| 12751 | pmbox->un.varWords[0], |
| 12752 | pmb); |
| 12753 | pmb->mbox_cmpl = |
| 12754 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12755 | pmb->ctx_buf = mp; |
| 12756 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12757 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12758 | rc = lpfc_sli_issue_mbox(phba, |
| 12759 | pmb, |
| 12760 | MBX_NOWAIT); |
| 12761 | if (rc != MBX_BUSY) |
| 12762 | lpfc_printf_log(phba, |
| 12763 | KERN_ERR, |
| 12764 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12765 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12766 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12767 | if (rc != MBX_NOT_FINISHED) |
| 12768 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12769 | } |
| 12770 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12771 | spin_lock_irqsave( |
| 12772 | &phba->pport->work_port_lock, |
| 12773 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12774 | phba->pport->work_port_events &= |
| 12775 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12776 | spin_unlock_irqrestore( |
| 12777 | &phba->pport->work_port_lock, |
| 12778 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12779 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12780 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12781 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12782 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12783 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12784 | if ((work_ha_copy & HA_MBATT) && |
| 12785 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12786 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12787 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12788 | do { |
| 12789 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12790 | MBX_NOWAIT); |
| 12791 | } while (rc == MBX_NOT_FINISHED); |
| 12792 | if (rc != MBX_SUCCESS) |
| 12793 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12794 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12795 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12796 | } |
| 12797 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12798 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12799 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12800 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12801 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12802 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12803 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12804 | unplug_error: |
| 12805 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12806 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12807 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12808 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12809 | |
| 12810 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12811 | * 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] | 12812 | * @irq: Interrupt number. |
| 12813 | * @dev_id: The device context pointer. |
| 12814 | * |
| 12815 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12816 | * service routine when device with SLI-3 interface spec is enabled with |
| 12817 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12818 | * ring event in the HBA. However, when the device is enabled with either |
| 12819 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12820 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12821 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12822 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12823 | * the intrrupt context. This function is called without any lock held. |
| 12824 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12825 | * |
| 12826 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12827 | * returns IRQ_NONE. |
| 12828 | **/ |
| 12829 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12830 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12831 | { |
| 12832 | struct lpfc_hba *phba; |
| 12833 | uint32_t ha_copy; |
| 12834 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12835 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12836 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12837 | |
| 12838 | /* Get the driver's phba structure from the dev_id and |
| 12839 | * assume the HBA is not interrupting. |
| 12840 | */ |
| 12841 | phba = (struct lpfc_hba *) dev_id; |
| 12842 | |
| 12843 | if (unlikely(!phba)) |
| 12844 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12845 | |
| 12846 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12847 | * Stuff needs to be attented to when this function is invoked as an |
| 12848 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12849 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12850 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12851 | /* Check device state for handling interrupt */ |
| 12852 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12853 | return IRQ_NONE; |
| 12854 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12855 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12856 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12857 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12858 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12859 | /* |
| 12860 | * If there is deferred error attention, do not check for |
| 12861 | * any interrupt. |
| 12862 | */ |
| 12863 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12864 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12865 | return IRQ_NONE; |
| 12866 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12867 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12868 | phba->HAregaddr); |
| 12869 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12870 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12871 | } else |
| 12872 | ha_copy = phba->ha_copy; |
| 12873 | |
| 12874 | /* |
| 12875 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12876 | */ |
| 12877 | ha_copy &= ~(phba->work_ha_mask); |
| 12878 | |
| 12879 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12880 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12881 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12882 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12883 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12884 | |
| 12885 | if (phba->cfg_multi_ring_support == 2) { |
| 12886 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12887 | * Process all events on extra ring. Take the optimized path |
| 12888 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12889 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12890 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12891 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12892 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12893 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12894 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12895 | status); |
| 12896 | } |
| 12897 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12898 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12899 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12900 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12901 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12902 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12903 | * @irq: Interrupt number. |
| 12904 | * @dev_id: The device context pointer. |
| 12905 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12906 | * This function is the HBA device-level interrupt handler to device with |
| 12907 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12908 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12909 | * requires driver attention. This function invokes the slow-path interrupt |
| 12910 | * attention handling function and fast-path interrupt attention handling |
| 12911 | * function in turn to process the relevant HBA attention events. This |
| 12912 | * function is called without any lock held. It gets the hbalock to access |
| 12913 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12914 | * |
| 12915 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12916 | * returns IRQ_NONE. |
| 12917 | **/ |
| 12918 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12919 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12920 | { |
| 12921 | struct lpfc_hba *phba; |
| 12922 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12923 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12924 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12925 | |
| 12926 | /* |
| 12927 | * Get the driver's phba structure from the dev_id and |
| 12928 | * assume the HBA is not interrupting. |
| 12929 | */ |
| 12930 | phba = (struct lpfc_hba *) dev_id; |
| 12931 | |
| 12932 | if (unlikely(!phba)) |
| 12933 | return IRQ_NONE; |
| 12934 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12935 | /* Check device state for handling interrupt */ |
| 12936 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12937 | return IRQ_NONE; |
| 12938 | |
| 12939 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12940 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12941 | spin_unlock(&phba->hbalock); |
| 12942 | return IRQ_HANDLED; |
| 12943 | } |
| 12944 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12945 | if (unlikely(!phba->ha_copy)) { |
| 12946 | spin_unlock(&phba->hbalock); |
| 12947 | return IRQ_NONE; |
| 12948 | } else if (phba->ha_copy & HA_ERATT) { |
| 12949 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12950 | /* ERATT polling has handled ERATT */ |
| 12951 | phba->ha_copy &= ~HA_ERATT; |
| 12952 | else |
| 12953 | /* Indicate interrupt handler handles ERATT */ |
| 12954 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12955 | } |
| 12956 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12957 | /* |
| 12958 | * If there is deferred error attention, do not check for any interrupt. |
| 12959 | */ |
| 12960 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12961 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12962 | return IRQ_NONE; |
| 12963 | } |
| 12964 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12965 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12966 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12967 | spin_unlock(&phba->hbalock); |
| 12968 | return IRQ_HANDLED; |
| 12969 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12970 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12971 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12972 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12973 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12974 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12975 | readl(phba->HAregaddr); /* flush */ |
| 12976 | spin_unlock(&phba->hbalock); |
| 12977 | |
| 12978 | /* |
| 12979 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12980 | */ |
| 12981 | |
| 12982 | /* status of events with mailbox and link attention */ |
| 12983 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12984 | |
| 12985 | /* status of events with ELS ring */ |
| 12986 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12987 | status2 >>= (4*LPFC_ELS_RING); |
| 12988 | |
| 12989 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12990 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12991 | else |
| 12992 | sp_irq_rc = IRQ_NONE; |
| 12993 | |
| 12994 | /* |
| 12995 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12996 | */ |
| 12997 | |
| 12998 | /* status of events with FCP ring */ |
| 12999 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 13000 | status1 >>= (4*LPFC_FCP_RING); |
| 13001 | |
| 13002 | /* status of events with extra ring */ |
| 13003 | if (phba->cfg_multi_ring_support == 2) { |
| 13004 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 13005 | status2 >>= (4*LPFC_EXTRA_RING); |
| 13006 | } else |
| 13007 | status2 = 0; |
| 13008 | |
| 13009 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13010 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13011 | else |
| 13012 | fp_irq_rc = IRQ_NONE; |
| 13013 | |
| 13014 | /* Return device-level interrupt handling status */ |
| 13015 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13016 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13017 | |
| 13018 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13019 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 13020 | * @phba: pointer to lpfc hba data structure. |
| 13021 | * |
| 13022 | * This routine is invoked by the worker thread to process all the pending |
| 13023 | * SLI4 els abort xri events. |
| 13024 | **/ |
| 13025 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 13026 | { |
| 13027 | struct lpfc_cq_event *cq_event; |
| 13028 | |
| 13029 | /* First, declare the els xri abort event has been handled */ |
| 13030 | spin_lock_irq(&phba->hbalock); |
| 13031 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 13032 | spin_unlock_irq(&phba->hbalock); |
| 13033 | /* Now, handle all the els xri abort events */ |
| 13034 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 13035 | /* Get the first event from the head of the event queue */ |
| 13036 | spin_lock_irq(&phba->hbalock); |
| 13037 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 13038 | cq_event, struct lpfc_cq_event, list); |
| 13039 | spin_unlock_irq(&phba->hbalock); |
| 13040 | /* Notify aborted XRI for ELS work queue */ |
| 13041 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 13042 | /* Free the event processed back to the free pool */ |
| 13043 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 13044 | } |
| 13045 | } |
| 13046 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13047 | /** |
| 13048 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 13049 | * @phba: pointer to lpfc hba data structure |
| 13050 | * @pIocbIn: pointer to the rspiocbq |
| 13051 | * @pIocbOut: pointer to the cmdiocbq |
| 13052 | * @wcqe: pointer to the complete wcqe |
| 13053 | * |
| 13054 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 13055 | * by copying all the IOCB fields from command iocbq and transferring the |
| 13056 | * completion status information from the complete wcqe. |
| 13057 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13058 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13059 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 13060 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13061 | struct lpfc_iocbq *pIocbOut, |
| 13062 | struct lpfc_wcqe_complete *wcqe) |
| 13063 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13064 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13065 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13066 | uint32_t status, max_response; |
| 13067 | struct lpfc_dmabuf *dmabuf; |
| 13068 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13069 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 13070 | |
| 13071 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 13072 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13073 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13074 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 13075 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13076 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 13077 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 13078 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 13079 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 13080 | wcqe->total_data_placed; |
| 13081 | else |
| 13082 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13083 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13084 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13085 | switch (pIocbOut->iocb.ulpCommand) { |
| 13086 | case CMD_ELS_REQUEST64_CR: |
| 13087 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 13088 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 13089 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 13090 | max_response = bde.tus.f.bdeSize; |
| 13091 | break; |
| 13092 | case CMD_GEN_REQUEST64_CR: |
| 13093 | max_response = 0; |
| 13094 | if (!pIocbOut->context3) |
| 13095 | break; |
| 13096 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 13097 | sizeof(struct ulp_bde64); |
| 13098 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 13099 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 13100 | for (i = 0; i < numBdes; i++) { |
| 13101 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 13102 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 13103 | max_response += bde.tus.f.bdeSize; |
| 13104 | } |
| 13105 | break; |
| 13106 | default: |
| 13107 | max_response = wcqe->total_data_placed; |
| 13108 | break; |
| 13109 | } |
| 13110 | if (max_response < wcqe->total_data_placed) |
| 13111 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 13112 | else |
| 13113 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 13114 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13115 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13116 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13117 | /* Convert BG errors for completion status */ |
| 13118 | if (status == CQE_STATUS_DI_ERROR) { |
| 13119 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 13120 | |
| 13121 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 13122 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 13123 | else |
| 13124 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 13125 | |
| 13126 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 13127 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 13128 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13129 | BGS_GUARD_ERR_MASK; |
| 13130 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 13131 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13132 | BGS_APPTAG_ERR_MASK; |
| 13133 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 13134 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13135 | BGS_REFTAG_ERR_MASK; |
| 13136 | |
| 13137 | /* Check to see if there was any good data before the error */ |
| 13138 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 13139 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13140 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 13141 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 13142 | wcqe->total_data_placed; |
| 13143 | } |
| 13144 | |
| 13145 | /* |
| 13146 | * Set ALL the error bits to indicate we don't know what |
| 13147 | * type of error it is. |
| 13148 | */ |
| 13149 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 13150 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13151 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 13152 | BGS_GUARD_ERR_MASK); |
| 13153 | } |
| 13154 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13155 | /* Pick up HBA exchange busy condition */ |
| 13156 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 13157 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13158 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 13159 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13160 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13161 | } |
| 13162 | |
| 13163 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13164 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 13165 | * @phba: Pointer to HBA context object. |
| 13166 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13167 | * |
| 13168 | * This routine handles an ELS work-queue completion event and construct |
| 13169 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 13170 | * discovery engine to handle. |
| 13171 | * |
| 13172 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 13173 | **/ |
| 13174 | static struct lpfc_iocbq * |
| 13175 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 13176 | struct lpfc_iocbq *irspiocbq) |
| 13177 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13178 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13179 | struct lpfc_iocbq *cmdiocbq; |
| 13180 | struct lpfc_wcqe_complete *wcqe; |
| 13181 | unsigned long iflags; |
| 13182 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13183 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 13184 | if (unlikely(!pring)) |
| 13185 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13186 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13187 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13188 | pring->stats.iocb_event++; |
| 13189 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 13190 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13191 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13192 | if (unlikely(!cmdiocbq)) { |
| 13193 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13194 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13195 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 13196 | wcqe->word0, wcqe->total_data_placed, |
| 13197 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13198 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 13199 | return NULL; |
| 13200 | } |
| 13201 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13202 | spin_lock_irqsave(&pring->ring_lock, iflags); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13203 | /* Put the iocb back on the txcmplq */ |
| 13204 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13205 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13206 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13207 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13208 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13209 | |
| 13210 | return irspiocbq; |
| 13211 | } |
| 13212 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13213 | inline struct lpfc_cq_event * |
| 13214 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13215 | { |
| 13216 | struct lpfc_cq_event *cq_event; |
| 13217 | |
| 13218 | /* Allocate a new internal CQ_EVENT entry */ |
| 13219 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13220 | if (!cq_event) { |
| 13221 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13222 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13223 | return NULL; |
| 13224 | } |
| 13225 | |
| 13226 | /* Move the CQE into the event */ |
| 13227 | memcpy(&cq_event->cqe, entry, size); |
| 13228 | return cq_event; |
| 13229 | } |
| 13230 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13231 | /** |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13232 | * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13233 | * @phba: Pointer to HBA context object. |
| 13234 | * @cqe: Pointer to mailbox completion queue entry. |
| 13235 | * |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13236 | * This routine process a mailbox completion queue entry with asynchronous |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13237 | * event. |
| 13238 | * |
| 13239 | * Return: true if work posted to worker thread, otherwise false. |
| 13240 | **/ |
| 13241 | static bool |
| 13242 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13243 | { |
| 13244 | struct lpfc_cq_event *cq_event; |
| 13245 | unsigned long iflags; |
| 13246 | |
| 13247 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13248 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13249 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13250 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13251 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13252 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13253 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13254 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13255 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13256 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 13257 | /* Set the async event flag */ |
| 13258 | phba->hba_flag |= ASYNC_EVENT; |
| 13259 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13260 | |
| 13261 | return true; |
| 13262 | } |
| 13263 | |
| 13264 | /** |
| 13265 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13266 | * @phba: Pointer to HBA context object. |
| 13267 | * @cqe: Pointer to mailbox completion queue entry. |
| 13268 | * |
| 13269 | * This routine process a mailbox completion queue entry with mailbox |
| 13270 | * completion event. |
| 13271 | * |
| 13272 | * Return: true if work posted to worker thread, otherwise false. |
| 13273 | **/ |
| 13274 | static bool |
| 13275 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13276 | { |
| 13277 | uint32_t mcqe_status; |
| 13278 | MAILBOX_t *mbox, *pmbox; |
| 13279 | struct lpfc_mqe *mqe; |
| 13280 | struct lpfc_vport *vport; |
| 13281 | struct lpfc_nodelist *ndlp; |
| 13282 | struct lpfc_dmabuf *mp; |
| 13283 | unsigned long iflags; |
| 13284 | LPFC_MBOXQ_t *pmb; |
| 13285 | bool workposted = false; |
| 13286 | int rc; |
| 13287 | |
| 13288 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13289 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13290 | goto out_no_mqe_complete; |
| 13291 | |
| 13292 | /* Get the reference to the active mbox command */ |
| 13293 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13294 | pmb = phba->sli.mbox_active; |
| 13295 | if (unlikely(!pmb)) { |
| 13296 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13297 | "1832 No pending MBOX command to handle\n"); |
| 13298 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13299 | goto out_no_mqe_complete; |
| 13300 | } |
| 13301 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13302 | mqe = &pmb->u.mqe; |
| 13303 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13304 | mbox = phba->mbox; |
| 13305 | vport = pmb->vport; |
| 13306 | |
| 13307 | /* Reset heartbeat timer */ |
| 13308 | phba->last_completion_time = jiffies; |
| 13309 | del_timer(&phba->sli.mbox_tmo); |
| 13310 | |
| 13311 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13312 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13313 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13314 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13315 | /* |
| 13316 | * For mcqe errors, conditionally move a modified error code to |
| 13317 | * the mbox so that the error will not be missed. |
| 13318 | */ |
| 13319 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13320 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13321 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13322 | bf_set(lpfc_mqe_status, mqe, |
| 13323 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13324 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13325 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13326 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13327 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13328 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13329 | mcqe_status, |
| 13330 | pmbox->un.varWords[0], 0); |
| 13331 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13332 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13333 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13334 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 13335 | * RID of the PPI using the same mbox buffer. |
| 13336 | */ |
| 13337 | lpfc_unreg_login(phba, vport->vpi, |
| 13338 | pmbox->un.varWords[0], pmb); |
| 13339 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13340 | pmb->ctx_buf = mp; |
| 13341 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13342 | pmb->vport = vport; |
| 13343 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13344 | if (rc != MBX_BUSY) |
| 13345 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 13346 | LOG_SLI, "0385 rc should " |
| 13347 | "have been MBX_BUSY\n"); |
| 13348 | if (rc != MBX_NOT_FINISHED) |
| 13349 | goto send_current_mbox; |
| 13350 | } |
| 13351 | } |
| 13352 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13353 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13354 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13355 | |
| 13356 | /* There is mailbox completion work to do */ |
| 13357 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13358 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13359 | phba->work_ha |= HA_MBATT; |
| 13360 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13361 | workposted = true; |
| 13362 | |
| 13363 | send_current_mbox: |
| 13364 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13365 | /* Release the mailbox command posting token */ |
| 13366 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13367 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13368 | phba->sli.mbox_active = NULL; |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13369 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13370 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13371 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13372 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13373 | lpfc_worker_wake_up(phba); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13374 | return workposted; |
| 13375 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13376 | out_no_mqe_complete: |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13377 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13378 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13379 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13380 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13381 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13382 | } |
| 13383 | |
| 13384 | /** |
| 13385 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13386 | * @phba: Pointer to HBA context object. |
| 13387 | * @cqe: Pointer to mailbox completion queue entry. |
| 13388 | * |
| 13389 | * This routine process a mailbox completion queue entry, it invokes the |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13390 | * proper mailbox complete handling or asynchronous event handling routine |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13391 | * according to the MCQE's async bit. |
| 13392 | * |
| 13393 | * Return: true if work posted to worker thread, otherwise false. |
| 13394 | **/ |
| 13395 | static bool |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13396 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13397 | struct lpfc_cqe *cqe) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13398 | { |
| 13399 | struct lpfc_mcqe mcqe; |
| 13400 | bool workposted; |
| 13401 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13402 | cq->CQ_mbox++; |
| 13403 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13404 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13405 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13406 | |
| 13407 | /* Invoke the proper event handling routine */ |
| 13408 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13409 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13410 | else |
| 13411 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13412 | return workposted; |
| 13413 | } |
| 13414 | |
| 13415 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13416 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13417 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13418 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13419 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13420 | * |
| 13421 | * This routine handles an ELS work-queue completion event. |
| 13422 | * |
| 13423 | * Return: true if work posted to worker thread, otherwise false. |
| 13424 | **/ |
| 13425 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13426 | 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] | 13427 | struct lpfc_wcqe_complete *wcqe) |
| 13428 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13429 | struct lpfc_iocbq *irspiocbq; |
| 13430 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13431 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13432 | int txq_cnt = 0; |
| 13433 | int txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13434 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13435 | /* Check for response status */ |
| 13436 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13437 | /* Log the error status */ |
| 13438 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13439 | "0357 ELS CQE error: status=x%x: " |
| 13440 | "CQE: %08x %08x %08x %08x\n", |
| 13441 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13442 | wcqe->word0, wcqe->total_data_placed, |
| 13443 | wcqe->parameter, wcqe->word3); |
| 13444 | } |
| 13445 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13446 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13447 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13448 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13449 | if (!list_empty(&pring->txq)) |
| 13450 | txq_cnt++; |
| 13451 | if (!list_empty(&pring->txcmplq)) |
| 13452 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13453 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13454 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
James Smart | ff349bc | 2019-09-21 20:59:05 -0700 | [diff] [blame] | 13455 | "els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13456 | txq_cnt, phba->iocb_cnt, |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13457 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13458 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13459 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13460 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13461 | /* Save off the slow-path queue event for work thread to process */ |
| 13462 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13463 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13464 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13465 | &phba->sli4_hba.sp_queue_event); |
| 13466 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13467 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13468 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13469 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13470 | } |
| 13471 | |
| 13472 | /** |
| 13473 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13474 | * @phba: Pointer to HBA context object. |
| 13475 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13476 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13477 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13478 | * proper WQ release routine to the slow-path WQ. |
| 13479 | **/ |
| 13480 | static void |
| 13481 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13482 | struct lpfc_wcqe_release *wcqe) |
| 13483 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13484 | /* sanity check on queue memory */ |
| 13485 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13486 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13487 | /* Check for the slow-path ELS work queue */ |
| 13488 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13489 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13490 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13491 | else |
| 13492 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13493 | "2579 Slow-path wqe consume event carries " |
| 13494 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13495 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13496 | phba->sli4_hba.els_wq->queue_id); |
| 13497 | } |
| 13498 | |
| 13499 | /** |
| 13500 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13501 | * @phba: Pointer to HBA context object. |
| 13502 | * @cq: Pointer to a WQ completion queue. |
| 13503 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13504 | * |
| 13505 | * This routine handles an XRI abort event. |
| 13506 | * |
| 13507 | * Return: true if work posted to worker thread, otherwise false. |
| 13508 | **/ |
| 13509 | static bool |
| 13510 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13511 | struct lpfc_queue *cq, |
| 13512 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13513 | { |
| 13514 | bool workposted = false; |
| 13515 | struct lpfc_cq_event *cq_event; |
| 13516 | unsigned long iflags; |
| 13517 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13518 | switch (cq->subtype) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13519 | case LPFC_IO: |
| 13520 | lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq); |
| 13521 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13522 | /* Notify aborted XRI for NVME work queue */ |
| 13523 | if (phba->nvmet_support) |
| 13524 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13525 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13526 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13527 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13528 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13529 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13530 | cq_event = lpfc_cq_event_setup( |
| 13531 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13532 | if (!cq_event) |
| 13533 | return false; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13534 | cq_event->hdwq = cq->hdwq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13535 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13536 | list_add_tail(&cq_event->list, |
| 13537 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13538 | /* Set the els xri abort event flag */ |
| 13539 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13540 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13541 | workposted = true; |
| 13542 | break; |
| 13543 | default: |
| 13544 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13545 | "0603 Invalid CQ subtype %d: " |
| 13546 | "%08x %08x %08x %08x\n", |
| 13547 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13548 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13549 | workposted = false; |
| 13550 | break; |
| 13551 | } |
| 13552 | return workposted; |
| 13553 | } |
| 13554 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13555 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13556 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13557 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13558 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13559 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13560 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13561 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13562 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13563 | * |
| 13564 | * Return: true if work posted to worker thread, otherwise false. |
| 13565 | **/ |
| 13566 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13567 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13568 | { |
| 13569 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13570 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13571 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13572 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13573 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13574 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13575 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13576 | unsigned long iflags; |
| 13577 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13578 | /* sanity check on queue memory */ |
| 13579 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13580 | return workposted; |
| 13581 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13582 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13583 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13584 | else |
| 13585 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13586 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13587 | goto out; |
| 13588 | |
| 13589 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13590 | switch (status) { |
| 13591 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13592 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13593 | "2537 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 13594 | /* fall through */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13595 | case FC_STATUS_RQ_SUCCESS: |
| 13596 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13597 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13598 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13599 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13600 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13601 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13602 | goto out; |
| 13603 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13604 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13605 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13606 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13607 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13608 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13609 | |
| 13610 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13611 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13612 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13613 | /* Handle MDS Loopback frames */ |
| 13614 | lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf); |
| 13615 | break; |
| 13616 | } |
| 13617 | |
| 13618 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13619 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13620 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13621 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13622 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13623 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13624 | workposted = true; |
| 13625 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13626 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13627 | if (phba->nvmet_support) { |
| 13628 | tgtp = phba->targetport->private; |
| 13629 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13630 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13631 | "%d: %x %x %x\n", |
| 13632 | status, hrq->RQ_buf_posted, |
| 13633 | hrq->RQ_no_posted_buf, |
| 13634 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13635 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13636 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13637 | } |
| 13638 | /* fallthrough */ |
| 13639 | |
| 13640 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13641 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13642 | /* Post more buffers if possible */ |
| 13643 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13644 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13645 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13646 | workposted = true; |
| 13647 | break; |
| 13648 | } |
| 13649 | out: |
| 13650 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13651 | } |
| 13652 | |
| 13653 | /** |
| 13654 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13655 | * @phba: Pointer to HBA context object. |
| 13656 | * @cq: Pointer to the completion queue. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13657 | * @cqe: Pointer to a completion queue entry. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13658 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13659 | * 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] | 13660 | * entry. |
| 13661 | * |
| 13662 | * Return: true if work posted to worker thread, otherwise false. |
| 13663 | **/ |
| 13664 | static bool |
| 13665 | 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] | 13666 | struct lpfc_cqe *cqe) |
| 13667 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13668 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13669 | bool workposted = false; |
| 13670 | |
| 13671 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13672 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13673 | |
| 13674 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13675 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13676 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13677 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13678 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13679 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13680 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13681 | break; |
| 13682 | case CQE_CODE_RELEASE_WQE: |
| 13683 | /* Process the WQ release event */ |
| 13684 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13685 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13686 | break; |
| 13687 | case CQE_CODE_XRI_ABORTED: |
| 13688 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13689 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13690 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13691 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13692 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13693 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13694 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13695 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13696 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13697 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13698 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13699 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13700 | default: |
| 13701 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13702 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13703 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13704 | break; |
| 13705 | } |
| 13706 | return workposted; |
| 13707 | } |
| 13708 | |
| 13709 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13710 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13711 | * @phba: Pointer to HBA context object. |
| 13712 | * @eqe: Pointer to fast-path event queue entry. |
| 13713 | * |
| 13714 | * This routine process a event queue entry from the slow-path event queue. |
| 13715 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13716 | * completion event on a completion queue, if not, an error shall be logged |
| 13717 | * and just return. Otherwise, it will get to the corresponding completion |
| 13718 | * queue and process all the entries on that completion queue, rearm the |
| 13719 | * completion queue, and then return. |
| 13720 | * |
| 13721 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13722 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13723 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13724 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13725 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13726 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13727 | uint16_t cqid; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 13728 | int ret = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13729 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13730 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13731 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13732 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13733 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13734 | if (childq->queue_id == cqid) { |
| 13735 | cq = childq; |
| 13736 | break; |
| 13737 | } |
| 13738 | } |
| 13739 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13740 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13741 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13742 | "0365 Slow-path CQ identifier " |
| 13743 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13744 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13745 | } |
| 13746 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13747 | /* Save EQ associated with this CQ */ |
| 13748 | cq->assoc_qp = speq; |
| 13749 | |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 13750 | if (is_kdump_kernel()) |
| 13751 | ret = queue_work(phba->wq, &cq->spwork); |
| 13752 | else |
| 13753 | ret = queue_work_on(cq->chann, phba->wq, &cq->spwork); |
| 13754 | |
| 13755 | if (!ret) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13756 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13757 | "0390 Cannot schedule soft IRQ " |
| 13758 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 13759 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13760 | } |
| 13761 | |
| 13762 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13763 | * __lpfc_sli4_process_cq - Process elements of a CQ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13764 | * @phba: Pointer to HBA context object. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13765 | * @cq: Pointer to CQ to be processed |
| 13766 | * @handler: Routine to process each cqe |
| 13767 | * @delay: Pointer to usdelay to set in case of rescheduling of the handler |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13768 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13769 | * This routine processes completion queue entries in a CQ. While a valid |
| 13770 | * queue element is found, the handler is called. During processing checks |
| 13771 | * are made for periodic doorbell writes to let the hardware know of |
| 13772 | * element consumption. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13773 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13774 | * If the max limit on cqes to process is hit, or there are no more valid |
| 13775 | * entries, the loop stops. If we processed a sufficient number of elements, |
| 13776 | * meaning there is sufficient load, rather than rearming and generating |
| 13777 | * another interrupt, a cq rescheduling delay will be set. A delay of 0 |
| 13778 | * indicates no rescheduling. |
| 13779 | * |
| 13780 | * Returns True if work scheduled, False otherwise. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13781 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13782 | static bool |
| 13783 | __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13784 | bool (*handler)(struct lpfc_hba *, struct lpfc_queue *, |
| 13785 | struct lpfc_cqe *), unsigned long *delay) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13786 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13787 | struct lpfc_cqe *cqe; |
| 13788 | bool workposted = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13789 | int count = 0, consumed = 0; |
| 13790 | bool arm = true; |
| 13791 | |
| 13792 | /* default - no reschedule */ |
| 13793 | *delay = 0; |
| 13794 | |
| 13795 | if (cmpxchg(&cq->queue_claimed, 0, 1) != 0) |
| 13796 | goto rearm_and_exit; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13797 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13798 | /* Process all the entries to the CQ */ |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13799 | cq->q_flag = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13800 | cqe = lpfc_sli4_cq_get(cq); |
| 13801 | while (cqe) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13802 | workposted |= handler(phba, cq, cqe); |
| 13803 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 13804 | |
| 13805 | consumed++; |
| 13806 | if (!(++count % cq->max_proc_limit)) |
| 13807 | break; |
| 13808 | |
| 13809 | if (!(count % cq->notify_interval)) { |
| 13810 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13811 | LPFC_QUEUE_NOARM); |
| 13812 | consumed = 0; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 13813 | cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13814 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13815 | |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13816 | if (count == LPFC_NVMET_CQ_NOTIFY) |
| 13817 | cq->q_flag |= HBA_NVMET_CQ_NOTIFY; |
| 13818 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13819 | cqe = lpfc_sli4_cq_get(cq); |
| 13820 | } |
| 13821 | if (count >= phba->cfg_cq_poll_threshold) { |
| 13822 | *delay = 1; |
| 13823 | arm = false; |
| 13824 | } |
| 13825 | |
| 13826 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13827 | if (count > cq->CQ_max_cqe) |
| 13828 | cq->CQ_max_cqe = count; |
| 13829 | |
| 13830 | cq->assoc_qp->EQ_cqe_cnt += count; |
| 13831 | |
| 13832 | /* Catch the no cq entry condition */ |
| 13833 | if (unlikely(count == 0)) |
| 13834 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13835 | "0369 No entry from completion queue " |
| 13836 | "qid=%d\n", cq->queue_id); |
| 13837 | |
Dick Kennedy | 164ba8d | 2020-05-01 14:43:03 -0700 | [diff] [blame] | 13838 | xchg(&cq->queue_claimed, 0); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13839 | |
| 13840 | rearm_and_exit: |
| 13841 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13842 | arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM); |
| 13843 | |
| 13844 | return workposted; |
| 13845 | } |
| 13846 | |
| 13847 | /** |
| 13848 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13849 | * @cq: pointer to CQ to process |
| 13850 | * |
| 13851 | * This routine calls the cq processing routine with a handler specific |
| 13852 | * to the type of queue bound to it. |
| 13853 | * |
| 13854 | * The CQ routine returns two values: the first is the calling status, |
| 13855 | * which indicates whether work was queued to the background discovery |
| 13856 | * thread. If true, the routine should wakeup the discovery thread; |
| 13857 | * the second is the delay parameter. If non-zero, rather than rearming |
| 13858 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 13859 | * that it is processed in a subsequent polling action. The value of |
| 13860 | * the delay indicates when to reschedule it. |
| 13861 | **/ |
| 13862 | static void |
| 13863 | __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq) |
| 13864 | { |
| 13865 | struct lpfc_hba *phba = cq->phba; |
| 13866 | unsigned long delay; |
| 13867 | bool workposted = false; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 13868 | int ret = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13869 | |
| 13870 | /* Process and rearm the CQ */ |
| 13871 | switch (cq->type) { |
| 13872 | case LPFC_MCQ: |
| 13873 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13874 | lpfc_sli4_sp_handle_mcqe, |
| 13875 | &delay); |
| 13876 | break; |
| 13877 | case LPFC_WCQ: |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13878 | if (cq->subtype == LPFC_IO) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13879 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13880 | lpfc_sli4_fp_handle_cqe, |
| 13881 | &delay); |
| 13882 | else |
| 13883 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13884 | lpfc_sli4_sp_handle_cqe, |
| 13885 | &delay); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13886 | break; |
| 13887 | default: |
| 13888 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13889 | "0370 Invalid completion queue type (%d)\n", |
| 13890 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13891 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13892 | } |
| 13893 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13894 | if (delay) { |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 13895 | if (is_kdump_kernel()) |
| 13896 | ret = queue_delayed_work(phba->wq, &cq->sched_spwork, |
| 13897 | delay); |
| 13898 | else |
| 13899 | ret = queue_delayed_work_on(cq->chann, phba->wq, |
| 13900 | &cq->sched_spwork, delay); |
| 13901 | if (!ret) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13902 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13903 | "0394 Cannot schedule soft IRQ " |
| 13904 | "for cqid=%d on CPU %d\n", |
| 13905 | cq->queue_id, cq->chann); |
| 13906 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13907 | |
| 13908 | /* wake up worker thread if there are works to be done */ |
| 13909 | if (workposted) |
| 13910 | lpfc_worker_wake_up(phba); |
| 13911 | } |
| 13912 | |
| 13913 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13914 | * lpfc_sli4_sp_process_cq - slow-path work handler when started by |
| 13915 | * interrupt |
| 13916 | * @work: pointer to work element |
| 13917 | * |
| 13918 | * translates from the work handler and calls the slow-path handler. |
| 13919 | **/ |
| 13920 | static void |
| 13921 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13922 | { |
| 13923 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork); |
| 13924 | |
| 13925 | __lpfc_sli4_sp_process_cq(cq); |
| 13926 | } |
| 13927 | |
| 13928 | /** |
| 13929 | * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer |
| 13930 | * @work: pointer to work element |
| 13931 | * |
| 13932 | * translates from the work handler and calls the slow-path handler. |
| 13933 | **/ |
| 13934 | static void |
| 13935 | lpfc_sli4_dly_sp_process_cq(struct work_struct *work) |
| 13936 | { |
| 13937 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 13938 | struct lpfc_queue, sched_spwork); |
| 13939 | |
| 13940 | __lpfc_sli4_sp_process_cq(cq); |
| 13941 | } |
| 13942 | |
| 13943 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13944 | * 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] | 13945 | * @phba: Pointer to HBA context object. |
| 13946 | * @cq: Pointer to associated CQ |
| 13947 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13948 | * |
| 13949 | * This routine process a fast-path work queue completion entry from fast-path |
| 13950 | * event queue for FCP command response completion. |
| 13951 | **/ |
| 13952 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13953 | 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] | 13954 | struct lpfc_wcqe_complete *wcqe) |
| 13955 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13956 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13957 | struct lpfc_iocbq *cmdiocbq; |
| 13958 | struct lpfc_iocbq irspiocbq; |
| 13959 | unsigned long iflags; |
| 13960 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13961 | /* Check for response status */ |
| 13962 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13963 | /* If resource errors reported from HBA, reduce queue |
| 13964 | * depth of the SCSI device. |
| 13965 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13966 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13967 | IOSTAT_LOCAL_REJECT)) && |
| 13968 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13969 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13970 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13971 | |
Dick Kennedy | 28ed737 | 2020-06-30 14:49:56 -0700 | [diff] [blame] | 13972 | /* Log the cmpl status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13973 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
Dick Kennedy | 28ed737 | 2020-06-30 14:49:56 -0700 | [diff] [blame] | 13974 | "0373 FCP CQE cmpl: status=x%x: " |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13975 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13976 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13977 | wcqe->word0, wcqe->total_data_placed, |
| 13978 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13979 | } |
| 13980 | |
| 13981 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13982 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13983 | pring->stats.iocb_event++; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13984 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13985 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13986 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13987 | if (unlikely(!cmdiocbq)) { |
| 13988 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13989 | "0374 FCP complete with no corresponding " |
| 13990 | "cmdiocb: iotag (%d)\n", |
| 13991 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13992 | return; |
| 13993 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13994 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13995 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13996 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13997 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13998 | if (cmdiocbq->wqe_cmpl) { |
| 13999 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 14000 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14001 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 14002 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14003 | } |
| 14004 | |
| 14005 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 14006 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 14007 | return; |
| 14008 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14009 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14010 | "0375 FCP cmdiocb not callback function " |
| 14011 | "iotag: (%d)\n", |
| 14012 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 14013 | return; |
| 14014 | } |
| 14015 | |
| 14016 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14017 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14018 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 14019 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 14020 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14021 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 14022 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14023 | } |
| 14024 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14025 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 14026 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 14027 | } |
| 14028 | |
| 14029 | /** |
| 14030 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 14031 | * @phba: Pointer to HBA context object. |
| 14032 | * @cq: Pointer to completion queue. |
| 14033 | * @wcqe: Pointer to work-queue completion queue entry. |
| 14034 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 14035 | * 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] | 14036 | * proper WQ release routine to the slow-path WQ. |
| 14037 | **/ |
| 14038 | static void |
| 14039 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14040 | struct lpfc_wcqe_release *wcqe) |
| 14041 | { |
| 14042 | struct lpfc_queue *childwq; |
| 14043 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14044 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14045 | |
| 14046 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14047 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14048 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14049 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14050 | lpfc_sli4_wq_release(childwq, |
| 14051 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14052 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 14053 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14054 | wqid_matched = true; |
| 14055 | break; |
| 14056 | } |
| 14057 | } |
| 14058 | /* Report warning log message if no match found */ |
| 14059 | if (wqid_matched != true) |
| 14060 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14061 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14062 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14063 | } |
| 14064 | |
| 14065 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14066 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 14067 | * @phba: Pointer to HBA context object. |
| 14068 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 14069 | * |
| 14070 | * This routine process a receive-queue completion queue entry. |
| 14071 | * |
| 14072 | * Return: true if work posted to worker thread, otherwise false. |
| 14073 | **/ |
| 14074 | static bool |
| 14075 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14076 | struct lpfc_rcqe *rcqe) |
| 14077 | { |
| 14078 | bool workposted = false; |
| 14079 | struct lpfc_queue *hrq; |
| 14080 | struct lpfc_queue *drq; |
| 14081 | struct rqb_dmabuf *dma_buf; |
| 14082 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14083 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14084 | uint32_t status, rq_id; |
| 14085 | unsigned long iflags; |
| 14086 | uint32_t fctl, idx; |
| 14087 | |
| 14088 | if ((phba->nvmet_support == 0) || |
| 14089 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 14090 | return workposted; |
| 14091 | |
| 14092 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14093 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 14094 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 14095 | |
| 14096 | /* sanity check on queue memory */ |
| 14097 | if (unlikely(!hrq) || unlikely(!drq)) |
| 14098 | return workposted; |
| 14099 | |
| 14100 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 14101 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 14102 | else |
| 14103 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 14104 | |
| 14105 | if ((phba->nvmet_support == 0) || |
| 14106 | (rq_id != hrq->queue_id)) |
| 14107 | return workposted; |
| 14108 | |
| 14109 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 14110 | switch (status) { |
| 14111 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 14112 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14113 | "6126 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14114 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14115 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14116 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 14117 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14118 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 14119 | if (!dma_buf) { |
| 14120 | hrq->RQ_no_buf_found++; |
| 14121 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14122 | goto out; |
| 14123 | } |
| 14124 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14125 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14126 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14127 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 14128 | |
| 14129 | /* Just some basic sanity checks on FCP Command frame */ |
| 14130 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 14131 | fc_hdr->fh_f_ctl[1] << 8 | |
| 14132 | fc_hdr->fh_f_ctl[2]); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14133 | if (((fctl & |
| 14134 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 14135 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 14136 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 14137 | goto drop; |
| 14138 | |
| 14139 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14140 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 14141 | lpfc_nvmet_unsol_fcp_event( |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14142 | phba, idx, dma_buf, cq->isr_timestamp, |
| 14143 | cq->q_flag & HBA_NVMET_CQ_NOTIFY); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14144 | return false; |
| 14145 | } |
| 14146 | drop: |
James Smart | 22b738a | 2019-03-12 16:30:11 -0700 | [diff] [blame] | 14147 | lpfc_rq_buf_free(phba, &dma_buf->hbuf); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14148 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14149 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14150 | if (phba->nvmet_support) { |
| 14151 | tgtp = phba->targetport->private; |
| 14152 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 14153 | "6401 RQE Error x%x, posted %d err_cnt " |
| 14154 | "%d: %x %x %x\n", |
| 14155 | status, hrq->RQ_buf_posted, |
| 14156 | hrq->RQ_no_posted_buf, |
| 14157 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 14158 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 14159 | atomic_read(&tgtp->xmt_fcp_release)); |
| 14160 | } |
| 14161 | /* fallthrough */ |
| 14162 | |
| 14163 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14164 | hrq->RQ_no_posted_buf++; |
| 14165 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14166 | break; |
| 14167 | } |
| 14168 | out: |
| 14169 | return workposted; |
| 14170 | } |
| 14171 | |
| 14172 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14173 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14174 | * @phba: adapter with cq |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14175 | * @cq: Pointer to the completion queue. |
| 14176 | * @eqe: Pointer to fast-path completion queue entry. |
| 14177 | * |
| 14178 | * This routine process a fast-path work queue completion entry from fast-path |
| 14179 | * event queue for FCP command response completion. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14180 | * |
| 14181 | * Return: true if work posted to worker thread, otherwise false. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14182 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14183 | static bool |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14184 | 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] | 14185 | struct lpfc_cqe *cqe) |
| 14186 | { |
| 14187 | struct lpfc_wcqe_release wcqe; |
| 14188 | bool workposted = false; |
| 14189 | |
| 14190 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14191 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14192 | |
| 14193 | /* Check and process for different type of WCQE and dispatch */ |
| 14194 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 14195 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14196 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14197 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14198 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 14199 | phba->last_completion_time = jiffies; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14200 | if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14201 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14202 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14203 | break; |
| 14204 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14205 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14206 | /* Process the WQ release event */ |
| 14207 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 14208 | (struct lpfc_wcqe_release *)&wcqe); |
| 14209 | break; |
| 14210 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14211 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14212 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14213 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14214 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 14215 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 14216 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14217 | case CQE_CODE_RECEIVE_V1: |
| 14218 | case CQE_CODE_RECEIVE: |
| 14219 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14220 | if (cq->subtype == LPFC_NVMET) { |
| 14221 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 14222 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 14223 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14224 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14225 | default: |
| 14226 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14227 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14228 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 14229 | break; |
| 14230 | } |
| 14231 | return workposted; |
| 14232 | } |
| 14233 | |
| 14234 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14235 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14236 | * @phba: Pointer to HBA context object. |
| 14237 | * @eqe: Pointer to fast-path event queue entry. |
| 14238 | * |
| 14239 | * This routine process a event queue entry from the fast-path event queue. |
| 14240 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14241 | * completion event on a completion queue, if not, an error shall be logged |
| 14242 | * and just return. Otherwise, it will get to the corresponding completion |
| 14243 | * queue and process all the entries on the completion queue, rearm the |
| 14244 | * completion queue, and then return. |
| 14245 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14246 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14247 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 14248 | struct lpfc_eqe *eqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14249 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14250 | struct lpfc_queue *cq = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14251 | uint32_t qidx = eq->hdwq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14252 | uint16_t cqid, id; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14253 | int ret = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14254 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14255 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14256 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14257 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14258 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14259 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14260 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14261 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14262 | } |
| 14263 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14264 | /* Get the reference to the corresponding CQ */ |
| 14265 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14266 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14267 | /* Use the fast lookup method first */ |
| 14268 | if (cqid <= phba->sli4_hba.cq_max) { |
| 14269 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 14270 | if (cq) |
| 14271 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14272 | } |
| 14273 | |
| 14274 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14275 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14276 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14277 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14278 | /* Process NVMET unsol rcv */ |
| 14279 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14280 | goto process_cq; |
| 14281 | } |
| 14282 | } |
| 14283 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14284 | if (phba->sli4_hba.nvmels_cq && |
| 14285 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14286 | /* Process NVME unsol rcv */ |
| 14287 | cq = phba->sli4_hba.nvmels_cq; |
| 14288 | } |
| 14289 | |
| 14290 | /* Otherwise this is a Slow path event */ |
| 14291 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14292 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 14293 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14294 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14295 | } |
| 14296 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14297 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14298 | if (unlikely(cqid != cq->queue_id)) { |
| 14299 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14300 | "0368 Miss-matched fast-path completion " |
| 14301 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14302 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14303 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14304 | } |
| 14305 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14306 | work_cq: |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14307 | #if defined(CONFIG_SCSI_LPFC_DEBUG_FS) |
| 14308 | if (phba->ktime_on) |
| 14309 | cq->isr_timestamp = ktime_get_ns(); |
| 14310 | else |
| 14311 | cq->isr_timestamp = 0; |
| 14312 | #endif |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14313 | if (is_kdump_kernel()) |
| 14314 | ret = queue_work(phba->wq, &cq->irqwork); |
| 14315 | else |
| 14316 | ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork); |
| 14317 | if (!ret) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14318 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14319 | "0363 Cannot schedule soft IRQ " |
| 14320 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14321 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14322 | } |
| 14323 | |
| 14324 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14325 | * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14326 | * @cq: Pointer to CQ to be processed |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14327 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14328 | * This routine calls the cq processing routine with the handler for |
| 14329 | * fast path CQEs. |
| 14330 | * |
| 14331 | * The CQ routine returns two values: the first is the calling status, |
| 14332 | * which indicates whether work was queued to the background discovery |
| 14333 | * thread. If true, the routine should wakeup the discovery thread; |
| 14334 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14335 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14336 | * that it is processed in a subsequent polling action. The value of |
| 14337 | * the delay indicates when to reschedule it. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14338 | **/ |
| 14339 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14340 | __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14341 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14342 | struct lpfc_hba *phba = cq->phba; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14343 | unsigned long delay; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14344 | bool workposted = false; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14345 | int ret = 0; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14346 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14347 | /* process and rearm the CQ */ |
| 14348 | workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe, |
| 14349 | &delay); |
| 14350 | |
| 14351 | if (delay) { |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14352 | if (is_kdump_kernel()) |
| 14353 | ret = queue_delayed_work(phba->wq, &cq->sched_irqwork, |
| 14354 | delay); |
| 14355 | else |
| 14356 | ret = queue_delayed_work_on(cq->chann, phba->wq, |
| 14357 | &cq->sched_irqwork, delay); |
| 14358 | if (!ret) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14359 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14360 | "0367 Cannot schedule soft IRQ " |
| 14361 | "for cqid=%d on CPU %d\n", |
| 14362 | cq->queue_id, cq->chann); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14363 | } |
| 14364 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14365 | /* wake up worker thread if there are works to be done */ |
| 14366 | if (workposted) |
| 14367 | lpfc_worker_wake_up(phba); |
| 14368 | } |
| 14369 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14370 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14371 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by |
| 14372 | * interrupt |
| 14373 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14374 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14375 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14376 | **/ |
| 14377 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14378 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14379 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14380 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14381 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14382 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14383 | } |
| 14384 | |
| 14385 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14386 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer |
| 14387 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14388 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14389 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14390 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14391 | static void |
| 14392 | lpfc_sli4_dly_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14393 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14394 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14395 | struct lpfc_queue, sched_irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14396 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14397 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14398 | } |
| 14399 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14400 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14401 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14402 | * @irq: Interrupt number. |
| 14403 | * @dev_id: The device context pointer. |
| 14404 | * |
| 14405 | * This function is directly called from the PCI layer as an interrupt |
| 14406 | * service routine when device with SLI-4 interface spec is enabled with |
| 14407 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14408 | * ring event in the HBA. However, when the device is enabled with either |
| 14409 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14410 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14411 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14412 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14413 | * the intrrupt context. This function is called without any lock held. |
| 14414 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14415 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14416 | * equal to that of FCP CQ index. |
| 14417 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14418 | * The link attention and ELS ring attention events are handled |
| 14419 | * by the worker thread. The interrupt handler signals the worker thread |
| 14420 | * and returns for these events. This function is called without any lock |
| 14421 | * held. It gets the hbalock to access and update SLI data structures. |
| 14422 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14423 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14424 | * returns IRQ_NONE. |
| 14425 | **/ |
| 14426 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14427 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14428 | { |
| 14429 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14430 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14431 | struct lpfc_queue *fpeq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14432 | unsigned long iflag; |
| 14433 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14434 | int hba_eqidx; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14435 | struct lpfc_eq_intr_info *eqi; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14436 | |
| 14437 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14438 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14439 | phba = hba_eq_hdl->phba; |
| 14440 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14441 | |
| 14442 | if (unlikely(!phba)) |
| 14443 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14444 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14445 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14446 | |
| 14447 | /* Get to the EQ struct associated with this vector */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14448 | fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14449 | if (unlikely(!fpeq)) |
| 14450 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14451 | |
| 14452 | /* Check device state for handling interrupt */ |
| 14453 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14454 | /* Check again for link_state with lock held */ |
| 14455 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14456 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14457 | /* Flush, clear interrupt, and rearm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 14458 | lpfc_sli4_eqcq_flush(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14459 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14460 | return IRQ_NONE; |
| 14461 | } |
| 14462 | |
Dick Kennedy | a7fc071 | 2020-05-01 14:43:08 -0700 | [diff] [blame] | 14463 | eqi = this_cpu_ptr(phba->sli4_hba.eq_info); |
| 14464 | eqi->icnt++; |
| 14465 | |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14466 | fpeq->last_cpu = raw_smp_processor_id(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14467 | |
Dick Kennedy | a7fc071 | 2020-05-01 14:43:08 -0700 | [diff] [blame] | 14468 | if (eqi->icnt > LPFC_EQD_ISR_TRIGGER && |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 14469 | fpeq->q_flag & HBA_EQ_DELAY_CHK && |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14470 | phba->cfg_auto_imax && |
| 14471 | fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY && |
| 14472 | phba->sli.sli_flag & LPFC_SLI_USE_EQDR) |
| 14473 | 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] | 14474 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14475 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14476 | ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14477 | |
| 14478 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14479 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14480 | if (phba->intr_type == MSIX) |
| 14481 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14482 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14483 | "0358 MSI-X interrupt with no EQE\n"); |
| 14484 | else |
| 14485 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14486 | return IRQ_NONE; |
| 14487 | } |
| 14488 | |
| 14489 | return IRQ_HANDLED; |
| 14490 | } /* lpfc_sli4_fp_intr_handler */ |
| 14491 | |
| 14492 | /** |
| 14493 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14494 | * @irq: Interrupt number. |
| 14495 | * @dev_id: The device context pointer. |
| 14496 | * |
| 14497 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14498 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14499 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14500 | * driver attention. This function invokes the slow-path interrupt attention |
| 14501 | * handling function and fast-path interrupt attention handling function in |
| 14502 | * turn to process the relevant HBA attention events. This function is called |
| 14503 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14504 | * structures. |
| 14505 | * |
| 14506 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14507 | * returns IRQ_NONE. |
| 14508 | **/ |
| 14509 | irqreturn_t |
| 14510 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14511 | { |
| 14512 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14513 | irqreturn_t hba_irq_rc; |
| 14514 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14515 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14516 | |
| 14517 | /* Get the driver's phba structure from the dev_id */ |
| 14518 | phba = (struct lpfc_hba *)dev_id; |
| 14519 | |
| 14520 | if (unlikely(!phba)) |
| 14521 | return IRQ_NONE; |
| 14522 | |
| 14523 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14524 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14525 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14526 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14527 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14528 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14529 | if (hba_irq_rc == IRQ_HANDLED) |
| 14530 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14531 | } |
| 14532 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14533 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14534 | } /* lpfc_sli4_intr_handler */ |
| 14535 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14536 | void lpfc_sli4_poll_hbtimer(struct timer_list *t) |
| 14537 | { |
| 14538 | struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer); |
| 14539 | struct lpfc_queue *eq; |
| 14540 | int i = 0; |
| 14541 | |
| 14542 | rcu_read_lock(); |
| 14543 | |
| 14544 | list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list) |
| 14545 | i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH); |
| 14546 | if (!list_empty(&phba->poll_list)) |
| 14547 | mod_timer(&phba->cpuhp_poll_timer, |
| 14548 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
| 14549 | |
| 14550 | rcu_read_unlock(); |
| 14551 | } |
| 14552 | |
| 14553 | inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path) |
| 14554 | { |
| 14555 | struct lpfc_hba *phba = eq->phba; |
| 14556 | int i = 0; |
| 14557 | |
| 14558 | /* |
| 14559 | * Unlocking an irq is one of the entry point to check |
| 14560 | * for re-schedule, but we are good for io submission |
| 14561 | * path as midlayer does a get_cpu to glue us in. Flush |
| 14562 | * out the invalidate queue so we can see the updated |
| 14563 | * value for flag. |
| 14564 | */ |
| 14565 | smp_rmb(); |
| 14566 | |
| 14567 | if (READ_ONCE(eq->mode) == LPFC_EQ_POLL) |
| 14568 | /* We will not likely get the completion for the caller |
| 14569 | * during this iteration but i guess that's fine. |
| 14570 | * Future io's coming on this eq should be able to |
| 14571 | * pick it up. As for the case of single io's, they |
| 14572 | * will be handled through a sched from polling timer |
| 14573 | * function which is currently triggered every 1msec. |
| 14574 | */ |
| 14575 | i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM); |
| 14576 | |
| 14577 | return i; |
| 14578 | } |
| 14579 | |
| 14580 | static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq) |
| 14581 | { |
| 14582 | struct lpfc_hba *phba = eq->phba; |
| 14583 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 14584 | /* kickstart slowpath processing if needed */ |
| 14585 | if (list_empty(&phba->poll_list)) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14586 | mod_timer(&phba->cpuhp_poll_timer, |
| 14587 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14588 | |
| 14589 | list_add_rcu(&eq->_poll_list, &phba->poll_list); |
| 14590 | synchronize_rcu(); |
| 14591 | } |
| 14592 | |
| 14593 | static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq) |
| 14594 | { |
| 14595 | struct lpfc_hba *phba = eq->phba; |
| 14596 | |
| 14597 | /* Disable slowpath processing for this eq. Kick start the eq |
| 14598 | * by RE-ARMING the eq's ASAP |
| 14599 | */ |
| 14600 | list_del_rcu(&eq->_poll_list); |
| 14601 | synchronize_rcu(); |
| 14602 | |
| 14603 | if (list_empty(&phba->poll_list)) |
| 14604 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 14605 | } |
| 14606 | |
James Smart | d480e57 | 2019-11-11 15:03:58 -0800 | [diff] [blame] | 14607 | void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14608 | { |
| 14609 | struct lpfc_queue *eq, *next; |
| 14610 | |
| 14611 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) |
| 14612 | list_del(&eq->_poll_list); |
| 14613 | |
| 14614 | INIT_LIST_HEAD(&phba->poll_list); |
| 14615 | synchronize_rcu(); |
| 14616 | } |
| 14617 | |
| 14618 | static inline void |
| 14619 | __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode) |
| 14620 | { |
| 14621 | if (mode == eq->mode) |
| 14622 | return; |
| 14623 | /* |
| 14624 | * currently this function is only called during a hotplug |
| 14625 | * event and the cpu on which this function is executing |
| 14626 | * is going offline. By now the hotplug has instructed |
| 14627 | * the scheduler to remove this cpu from cpu active mask. |
| 14628 | * So we don't need to work about being put aside by the |
| 14629 | * scheduler for a high priority process. Yes, the inte- |
| 14630 | * rrupts could come but they are known to retire ASAP. |
| 14631 | */ |
| 14632 | |
| 14633 | /* Disable polling in the fastpath */ |
| 14634 | WRITE_ONCE(eq->mode, mode); |
| 14635 | /* flush out the store buffer */ |
| 14636 | smp_wmb(); |
| 14637 | |
| 14638 | /* |
| 14639 | * Add this eq to the polling list and start polling. For |
| 14640 | * a grace period both interrupt handler and poller will |
| 14641 | * try to process the eq _but_ that's fine. We have a |
| 14642 | * synchronization mechanism in place (queue_claimed) to |
| 14643 | * deal with it. This is just a draining phase for int- |
| 14644 | * errupt handler (not eq's) as we have guranteed through |
| 14645 | * barrier that all the CPUs have seen the new CQ_POLLED |
| 14646 | * state. which will effectively disable the REARMING of |
| 14647 | * the EQ. The whole idea is eq's die off eventually as |
| 14648 | * we are not rearming EQ's anymore. |
| 14649 | */ |
| 14650 | mode ? lpfc_sli4_add_to_poll_list(eq) : |
| 14651 | lpfc_sli4_remove_from_poll_list(eq); |
| 14652 | } |
| 14653 | |
| 14654 | void lpfc_sli4_start_polling(struct lpfc_queue *eq) |
| 14655 | { |
| 14656 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL); |
| 14657 | } |
| 14658 | |
| 14659 | void lpfc_sli4_stop_polling(struct lpfc_queue *eq) |
| 14660 | { |
| 14661 | struct lpfc_hba *phba = eq->phba; |
| 14662 | |
| 14663 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT); |
| 14664 | |
| 14665 | /* Kick start for the pending io's in h/w. |
| 14666 | * Once we switch back to interrupt processing on a eq |
| 14667 | * the io path completion will only arm eq's when it |
| 14668 | * receives a completion. But since eq's are in disa- |
| 14669 | * rmed state it doesn't receive a completion. This |
| 14670 | * creates a deadlock scenaro. |
| 14671 | */ |
| 14672 | phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM); |
| 14673 | } |
| 14674 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14675 | /** |
| 14676 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14677 | * @queue: The queue structure to free. |
| 14678 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14679 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14680 | * the host resident queue. This function must be called after destroying the |
| 14681 | * queue on the HBA. |
| 14682 | **/ |
| 14683 | void |
| 14684 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14685 | { |
| 14686 | struct lpfc_dmabuf *dmabuf; |
| 14687 | |
| 14688 | if (!queue) |
| 14689 | return; |
| 14690 | |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 14691 | if (!list_empty(&queue->wq_list)) |
| 14692 | list_del(&queue->wq_list); |
| 14693 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14694 | while (!list_empty(&queue->page_list)) { |
| 14695 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14696 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14697 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14698 | dmabuf->virt, dmabuf->phys); |
| 14699 | kfree(dmabuf); |
| 14700 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14701 | if (queue->rqbp) { |
| 14702 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14703 | kfree(queue->rqbp); |
| 14704 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14705 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14706 | if (!list_empty(&queue->cpu_list)) |
| 14707 | list_del(&queue->cpu_list); |
| 14708 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14709 | kfree(queue); |
| 14710 | return; |
| 14711 | } |
| 14712 | |
| 14713 | /** |
| 14714 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14715 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14716 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14717 | * @entry_size: The size of each queue entry for this queue. |
| 14718 | * @entry count: The number of entries that this queue will handle. |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14719 | * @cpu: The cpu that will primarily utilize this queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14720 | * |
| 14721 | * This function allocates a queue structure and the DMAable memory used for |
| 14722 | * the host resident queue. This function must be called before creating the |
| 14723 | * queue on the HBA. |
| 14724 | **/ |
| 14725 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14726 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14727 | uint32_t entry_size, uint32_t entry_count, int cpu) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14728 | { |
| 14729 | struct lpfc_queue *queue; |
| 14730 | struct lpfc_dmabuf *dmabuf; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14731 | 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] | 14732 | uint16_t x, pgcnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14733 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14734 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14735 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14736 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14737 | pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14738 | |
| 14739 | /* If needed, Adjust page count to match the max the adapter supports */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14740 | if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 14741 | pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14742 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14743 | queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt), |
| 14744 | GFP_KERNEL, cpu_to_node(cpu)); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14745 | if (!queue) |
| 14746 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14747 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14748 | INIT_LIST_HEAD(&queue->list); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14749 | INIT_LIST_HEAD(&queue->_poll_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14750 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14751 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14752 | INIT_LIST_HEAD(&queue->page_list); |
| 14753 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14754 | INIT_LIST_HEAD(&queue->cpu_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14755 | |
| 14756 | /* Set queue parameters now. If the system cannot provide memory |
| 14757 | * resources, the free routine needs to know what was allocated. |
| 14758 | */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14759 | queue->page_count = pgcnt; |
| 14760 | queue->q_pgs = (void **)&queue[1]; |
| 14761 | queue->entry_cnt_per_pg = hw_page_size / entry_size; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14762 | queue->entry_size = entry_size; |
| 14763 | queue->entry_count = entry_count; |
| 14764 | queue->page_size = hw_page_size; |
| 14765 | queue->phba = phba; |
| 14766 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14767 | for (x = 0; x < queue->page_count; x++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14768 | dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL, |
| 14769 | dev_to_node(&phba->pcidev->dev)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14770 | if (!dmabuf) |
| 14771 | goto out_fail; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 14772 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 14773 | hw_page_size, &dmabuf->phys, |
| 14774 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14775 | if (!dmabuf->virt) { |
| 14776 | kfree(dmabuf); |
| 14777 | goto out_fail; |
| 14778 | } |
| 14779 | dmabuf->buffer_tag = x; |
| 14780 | list_add_tail(&dmabuf->list, &queue->page_list); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14781 | /* use lpfc_sli4_qe to index a paritcular entry in this page */ |
| 14782 | queue->q_pgs[x] = dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14783 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14784 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14785 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14786 | INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq); |
| 14787 | INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14788 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14789 | /* notify_interval will be set during q creation */ |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14790 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14791 | return queue; |
| 14792 | out_fail: |
| 14793 | lpfc_sli4_queue_free(queue); |
| 14794 | return NULL; |
| 14795 | } |
| 14796 | |
| 14797 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14798 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14799 | * @phba: HBA structure that indicates port to create a queue on. |
| 14800 | * @pci_barset: PCI BAR set flag. |
| 14801 | * |
| 14802 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14803 | * memory address if not already done so and return it. The returned host |
| 14804 | * memory address can be NULL. |
| 14805 | */ |
| 14806 | static void __iomem * |
| 14807 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14808 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14809 | if (!phba->pcidev) |
| 14810 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14811 | |
| 14812 | switch (pci_barset) { |
| 14813 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14814 | return phba->pci_bar0_memmap_p; |
| 14815 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14816 | return phba->pci_bar2_memmap_p; |
| 14817 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14818 | return phba->pci_bar4_memmap_p; |
| 14819 | default: |
| 14820 | break; |
| 14821 | } |
| 14822 | return NULL; |
| 14823 | } |
| 14824 | |
| 14825 | /** |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14826 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs |
| 14827 | * @phba: HBA structure that EQs are on. |
| 14828 | * @startq: The starting EQ index to modify |
| 14829 | * @numq: The number of EQs (consecutive indexes) to modify |
| 14830 | * @usdelay: amount of delay |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14831 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14832 | * This function revises the EQ delay on 1 or more EQs. The EQ delay |
| 14833 | * is set either by writing to a register (if supported by the SLI Port) |
| 14834 | * or by mailbox command. The mailbox command allows several EQs to be |
| 14835 | * updated at once. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14836 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14837 | * The @phba struct is used to send a mailbox command to HBA. The @startq |
| 14838 | * is used to get the starting EQ index to change. The @numq value is |
| 14839 | * used to specify how many consecutive EQ indexes, starting at EQ index, |
| 14840 | * are to be changed. This function is asynchronous and will wait for any |
| 14841 | * mailbox commands to finish before returning. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14842 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14843 | * On success this function will return a zero. If unable to allocate |
| 14844 | * enough memory this function will return -ENOMEM. If a mailbox command |
| 14845 | * fails this function will return -ENXIO. Note: on ENXIO, some EQs may |
| 14846 | * have had their delay multipler changed. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14847 | **/ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14848 | void |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14849 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14850 | uint32_t numq, uint32_t usdelay) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14851 | { |
| 14852 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14853 | LPFC_MBOXQ_t *mbox; |
| 14854 | struct lpfc_queue *eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14855 | int cnt = 0, rc, length; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14856 | uint32_t shdr_status, shdr_add_status; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14857 | uint32_t dmult; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14858 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14859 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14860 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14861 | if (startq >= phba->cfg_irq_chann) |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14862 | return; |
| 14863 | |
| 14864 | if (usdelay > 0xFFFF) { |
| 14865 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14866 | "6429 usdelay %d too large. Scaled down to " |
| 14867 | "0xFFFF.\n", usdelay); |
| 14868 | usdelay = 0xFFFF; |
| 14869 | } |
| 14870 | |
| 14871 | /* set values by EQ_DELAY register if supported */ |
| 14872 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14873 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14874 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14875 | if (!eq) |
| 14876 | continue; |
| 14877 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14878 | lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14879 | |
| 14880 | if (++cnt >= numq) |
| 14881 | break; |
| 14882 | } |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14883 | return; |
| 14884 | } |
| 14885 | |
| 14886 | /* Otherwise, set values by mailbox cmd */ |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14887 | |
| 14888 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14889 | if (!mbox) { |
| 14890 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14891 | "6428 Failed allocating mailbox cmd buffer." |
| 14892 | " EQ delay was not set.\n"); |
| 14893 | return; |
| 14894 | } |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14895 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14896 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14897 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14898 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14899 | length, LPFC_SLI4_MBX_EMBED); |
| 14900 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14901 | |
| 14902 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14903 | dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC; |
| 14904 | if (dmult) |
| 14905 | dmult--; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14906 | if (dmult > LPFC_DMULT_MAX) |
| 14907 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14908 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14909 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14910 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14911 | if (!eq) |
| 14912 | continue; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14913 | eq->q_mode = usdelay; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14914 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14915 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14916 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14917 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14918 | if (++cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14919 | break; |
| 14920 | } |
| 14921 | eq_delay->u.request.num_eq = cnt; |
| 14922 | |
| 14923 | mbox->vport = phba->pport; |
| 14924 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14925 | mbox->ctx_buf = NULL; |
| 14926 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14927 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14928 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14929 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14930 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14931 | if (shdr_status || shdr_add_status || rc) { |
| 14932 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14933 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14934 | "status x%x add_status x%x, mbx status x%x\n", |
| 14935 | shdr_status, shdr_add_status, rc); |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14936 | } |
| 14937 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14938 | return; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14939 | } |
| 14940 | |
| 14941 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14942 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14943 | * @phba: HBA structure that indicates port to create a queue on. |
| 14944 | * @eq: The queue structure to use to create the event queue. |
| 14945 | * @imax: The maximum interrupt per second limit. |
| 14946 | * |
| 14947 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14948 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14949 | * |
| 14950 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14951 | * is used to get the entry count and entry size that are necessary to |
| 14952 | * determine the number of pages to allocate and use for this queue. This |
| 14953 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14954 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14955 | * command to finish before continuing. |
| 14956 | * |
| 14957 | * 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] | 14958 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14959 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14960 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14961 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14962 | 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] | 14963 | { |
| 14964 | struct lpfc_mbx_eq_create *eq_create; |
| 14965 | LPFC_MBOXQ_t *mbox; |
| 14966 | int rc, length, status = 0; |
| 14967 | struct lpfc_dmabuf *dmabuf; |
| 14968 | uint32_t shdr_status, shdr_add_status; |
| 14969 | union lpfc_sli4_cfg_shdr *shdr; |
| 14970 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14971 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14972 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14973 | /* sanity check on queue memory */ |
| 14974 | if (!eq) |
| 14975 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14976 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14977 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14978 | |
| 14979 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14980 | if (!mbox) |
| 14981 | return -ENOMEM; |
| 14982 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14983 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14984 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14985 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14986 | length, LPFC_SLI4_MBX_EMBED); |
| 14987 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14988 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14989 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14990 | eq->page_count); |
| 14991 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14992 | LPFC_EQE_SIZE); |
| 14993 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14994 | |
| 14995 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 14996 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 14997 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14998 | LPFC_Q_CREATE_VERSION_2); |
| 14999 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 15000 | phba->sli4_hba.pc_sli4_params.eqav); |
| 15001 | } |
| 15002 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 15003 | /* don't setup delay multiplier using EQ_CREATE */ |
| 15004 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15005 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 15006 | dmult); |
| 15007 | switch (eq->entry_count) { |
| 15008 | default: |
| 15009 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15010 | "0360 Unsupported EQ count. (%d)\n", |
| 15011 | eq->entry_count); |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 15012 | if (eq->entry_count < 256) { |
| 15013 | status = -EINVAL; |
| 15014 | goto out; |
| 15015 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15016 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15017 | case 256: |
| 15018 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15019 | LPFC_EQ_CNT_256); |
| 15020 | break; |
| 15021 | case 512: |
| 15022 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15023 | LPFC_EQ_CNT_512); |
| 15024 | break; |
| 15025 | case 1024: |
| 15026 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15027 | LPFC_EQ_CNT_1024); |
| 15028 | break; |
| 15029 | case 2048: |
| 15030 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15031 | LPFC_EQ_CNT_2048); |
| 15032 | break; |
| 15033 | case 4096: |
| 15034 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15035 | LPFC_EQ_CNT_4096); |
| 15036 | break; |
| 15037 | } |
| 15038 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15039 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15040 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15041 | putPaddrLow(dmabuf->phys); |
| 15042 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15043 | putPaddrHigh(dmabuf->phys); |
| 15044 | } |
| 15045 | mbox->vport = phba->pport; |
| 15046 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 15047 | mbox->ctx_buf = NULL; |
| 15048 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15049 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15050 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15051 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15052 | if (shdr_status || shdr_add_status || rc) { |
| 15053 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15054 | "2500 EQ_CREATE mailbox failed with " |
| 15055 | "status x%x add_status x%x, mbx status x%x\n", |
| 15056 | shdr_status, shdr_add_status, rc); |
| 15057 | status = -ENXIO; |
| 15058 | } |
| 15059 | eq->type = LPFC_EQ; |
| 15060 | eq->subtype = LPFC_NONE; |
| 15061 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 15062 | if (eq->queue_id == 0xFFFF) |
| 15063 | status = -ENXIO; |
| 15064 | eq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15065 | eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL; |
| 15066 | eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT; |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 15067 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15068 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15069 | return status; |
| 15070 | } |
| 15071 | |
| 15072 | /** |
| 15073 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 15074 | * @phba: HBA structure that indicates port to create a queue on. |
| 15075 | * @cq: The queue structure to use to create the completion queue. |
| 15076 | * @eq: The event queue to bind this completion queue to. |
| 15077 | * |
| 15078 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 15079 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 15080 | * |
| 15081 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15082 | * is used to get the entry count and entry size that are necessary to |
| 15083 | * determine the number of pages to allocate and use for this queue. The @eq |
| 15084 | * is used to indicate which event queue to bind this completion queue to. This |
| 15085 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 15086 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 15087 | * command to finish before continuing. |
| 15088 | * |
| 15089 | * 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] | 15090 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15091 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15092 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15093 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15094 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 15095 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 15096 | { |
| 15097 | struct lpfc_mbx_cq_create *cq_create; |
| 15098 | struct lpfc_dmabuf *dmabuf; |
| 15099 | LPFC_MBOXQ_t *mbox; |
| 15100 | int rc, length, status = 0; |
| 15101 | uint32_t shdr_status, shdr_add_status; |
| 15102 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15103 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15104 | /* sanity check on queue memory */ |
| 15105 | if (!cq || !eq) |
| 15106 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15107 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15108 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15109 | if (!mbox) |
| 15110 | return -ENOMEM; |
| 15111 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 15112 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15113 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15114 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 15115 | length, LPFC_SLI4_MBX_EMBED); |
| 15116 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15117 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15118 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 15119 | cq->page_count); |
| 15120 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 15121 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15122 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15123 | phba->sli4_hba.pc_sli4_params.cqv); |
| 15124 | 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] | 15125 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 15126 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15127 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 15128 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15129 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 15130 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15131 | } else { |
| 15132 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 15133 | eq->queue_id); |
| 15134 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15135 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15136 | case 2048: |
| 15137 | case 4096: |
| 15138 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15139 | LPFC_Q_CREATE_VERSION_2) { |
| 15140 | cq_create->u.request.context.lpfc_cq_context_count = |
| 15141 | cq->entry_count; |
| 15142 | bf_set(lpfc_cq_context_count, |
| 15143 | &cq_create->u.request.context, |
| 15144 | LPFC_CQ_CNT_WORD7); |
| 15145 | break; |
| 15146 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15147 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15148 | default: |
| 15149 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15150 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15151 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15152 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15153 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15154 | if (cq->entry_count < 256) { |
| 15155 | status = -EINVAL; |
| 15156 | goto out; |
| 15157 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15158 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15159 | case 256: |
| 15160 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15161 | LPFC_CQ_CNT_256); |
| 15162 | break; |
| 15163 | case 512: |
| 15164 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15165 | LPFC_CQ_CNT_512); |
| 15166 | break; |
| 15167 | case 1024: |
| 15168 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15169 | LPFC_CQ_CNT_1024); |
| 15170 | break; |
| 15171 | } |
| 15172 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15173 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15174 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15175 | putPaddrLow(dmabuf->phys); |
| 15176 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15177 | putPaddrHigh(dmabuf->phys); |
| 15178 | } |
| 15179 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15180 | |
| 15181 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15182 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15183 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15184 | if (shdr_status || shdr_add_status || rc) { |
| 15185 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15186 | "2501 CQ_CREATE mailbox failed with " |
| 15187 | "status x%x add_status x%x, mbx status x%x\n", |
| 15188 | shdr_status, shdr_add_status, rc); |
| 15189 | status = -ENXIO; |
| 15190 | goto out; |
| 15191 | } |
| 15192 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 15193 | if (cq->queue_id == 0xFFFF) { |
| 15194 | status = -ENXIO; |
| 15195 | goto out; |
| 15196 | } |
| 15197 | /* link the cq onto the parent eq child list */ |
| 15198 | list_add_tail(&cq->list, &eq->child_list); |
| 15199 | /* Set up completion queue's type and subtype */ |
| 15200 | cq->type = type; |
| 15201 | cq->subtype = subtype; |
| 15202 | 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] | 15203 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15204 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15205 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15206 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15207 | 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] | 15208 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15209 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15210 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15211 | out: |
| 15212 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15213 | return status; |
| 15214 | } |
| 15215 | |
| 15216 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15217 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 15218 | * @phba: HBA structure that indicates port to create a queue on. |
| 15219 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15220 | * @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] | 15221 | * |
| 15222 | * This function creates a set of completion queue, s to support MRQ |
| 15223 | * as detailed in @cqp, on a port, |
| 15224 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 15225 | * |
| 15226 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15227 | * is used to get the entry count and entry size that are necessary to |
| 15228 | * determine the number of pages to allocate and use for this queue. The @eq |
| 15229 | * is used to indicate which event queue to bind this completion queue to. This |
| 15230 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 15231 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 15232 | * command to finish before continuing. |
| 15233 | * |
| 15234 | * On success this function will return a zero. If unable to allocate enough |
| 15235 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15236 | * fails this function will return -ENXIO. |
| 15237 | **/ |
| 15238 | int |
| 15239 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15240 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 15241 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15242 | { |
| 15243 | struct lpfc_queue *cq; |
| 15244 | struct lpfc_queue *eq; |
| 15245 | struct lpfc_mbx_cq_create_set *cq_set; |
| 15246 | struct lpfc_dmabuf *dmabuf; |
| 15247 | LPFC_MBOXQ_t *mbox; |
| 15248 | int rc, length, alloclen, status = 0; |
| 15249 | int cnt, idx, numcq, page_idx = 0; |
| 15250 | uint32_t shdr_status, shdr_add_status; |
| 15251 | union lpfc_sli4_cfg_shdr *shdr; |
| 15252 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15253 | |
| 15254 | /* sanity check on queue memory */ |
| 15255 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15256 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15257 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15258 | |
| 15259 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15260 | if (!mbox) |
| 15261 | return -ENOMEM; |
| 15262 | |
| 15263 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 15264 | length += ((numcq * cqp[0]->page_count) * |
| 15265 | sizeof(struct dma_address)); |
| 15266 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15267 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 15268 | LPFC_SLI4_MBX_NEMBED); |
| 15269 | if (alloclen < length) { |
| 15270 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15271 | "3098 Allocated DMA memory size (%d) is " |
| 15272 | "less than the requested DMA memory size " |
| 15273 | "(%d)\n", alloclen, length); |
| 15274 | status = -ENOMEM; |
| 15275 | goto out; |
| 15276 | } |
| 15277 | cq_set = mbox->sge_array->addr[0]; |
| 15278 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 15279 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 15280 | |
| 15281 | for (idx = 0; idx < numcq; idx++) { |
| 15282 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15283 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15284 | if (!cq || !eq) { |
| 15285 | status = -ENOMEM; |
| 15286 | goto out; |
| 15287 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15288 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15289 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15290 | |
| 15291 | switch (idx) { |
| 15292 | case 0: |
| 15293 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 15294 | &cq_set->u.request, |
| 15295 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 15296 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 15297 | &cq_set->u.request, cq->page_count); |
| 15298 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 15299 | &cq_set->u.request, 1); |
| 15300 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 15301 | &cq_set->u.request, 1); |
| 15302 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 15303 | &cq_set->u.request, 0); |
| 15304 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 15305 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15306 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 15307 | &cq_set->u.request, |
| 15308 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15309 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15310 | case 2048: |
| 15311 | case 4096: |
| 15312 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15313 | LPFC_Q_CREATE_VERSION_2) { |
| 15314 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15315 | &cq_set->u.request, |
| 15316 | cq->entry_count); |
| 15317 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15318 | &cq_set->u.request, |
| 15319 | LPFC_CQ_CNT_WORD7); |
| 15320 | break; |
| 15321 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15322 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15323 | default: |
| 15324 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15325 | "3118 Bad CQ count. (%d)\n", |
| 15326 | cq->entry_count); |
| 15327 | if (cq->entry_count < 256) { |
| 15328 | status = -EINVAL; |
| 15329 | goto out; |
| 15330 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15331 | /* fall through - otherwise default to smallest */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15332 | case 256: |
| 15333 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15334 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 15335 | break; |
| 15336 | case 512: |
| 15337 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15338 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 15339 | break; |
| 15340 | case 1024: |
| 15341 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15342 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 15343 | break; |
| 15344 | } |
| 15345 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 15346 | &cq_set->u.request, eq->queue_id); |
| 15347 | break; |
| 15348 | case 1: |
| 15349 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 15350 | &cq_set->u.request, eq->queue_id); |
| 15351 | break; |
| 15352 | case 2: |
| 15353 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 15354 | &cq_set->u.request, eq->queue_id); |
| 15355 | break; |
| 15356 | case 3: |
| 15357 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 15358 | &cq_set->u.request, eq->queue_id); |
| 15359 | break; |
| 15360 | case 4: |
| 15361 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 15362 | &cq_set->u.request, eq->queue_id); |
| 15363 | break; |
| 15364 | case 5: |
| 15365 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 15366 | &cq_set->u.request, eq->queue_id); |
| 15367 | break; |
| 15368 | case 6: |
| 15369 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 15370 | &cq_set->u.request, eq->queue_id); |
| 15371 | break; |
| 15372 | case 7: |
| 15373 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 15374 | &cq_set->u.request, eq->queue_id); |
| 15375 | break; |
| 15376 | case 8: |
| 15377 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 15378 | &cq_set->u.request, eq->queue_id); |
| 15379 | break; |
| 15380 | case 9: |
| 15381 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 15382 | &cq_set->u.request, eq->queue_id); |
| 15383 | break; |
| 15384 | case 10: |
| 15385 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 15386 | &cq_set->u.request, eq->queue_id); |
| 15387 | break; |
| 15388 | case 11: |
| 15389 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 15390 | &cq_set->u.request, eq->queue_id); |
| 15391 | break; |
| 15392 | case 12: |
| 15393 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 15394 | &cq_set->u.request, eq->queue_id); |
| 15395 | break; |
| 15396 | case 13: |
| 15397 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 15398 | &cq_set->u.request, eq->queue_id); |
| 15399 | break; |
| 15400 | case 14: |
| 15401 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 15402 | &cq_set->u.request, eq->queue_id); |
| 15403 | break; |
| 15404 | case 15: |
| 15405 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 15406 | &cq_set->u.request, eq->queue_id); |
| 15407 | break; |
| 15408 | } |
| 15409 | |
| 15410 | /* link the cq onto the parent eq child list */ |
| 15411 | list_add_tail(&cq->list, &eq->child_list); |
| 15412 | /* Set up completion queue's type and subtype */ |
| 15413 | cq->type = type; |
| 15414 | cq->subtype = subtype; |
| 15415 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15416 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15417 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15418 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15419 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, |
| 15420 | cq->entry_count); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15421 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15422 | |
| 15423 | rc = 0; |
| 15424 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15425 | memset(dmabuf->virt, 0, hw_page_size); |
| 15426 | cnt = page_idx + dmabuf->buffer_tag; |
| 15427 | cq_set->u.request.page[cnt].addr_lo = |
| 15428 | putPaddrLow(dmabuf->phys); |
| 15429 | cq_set->u.request.page[cnt].addr_hi = |
| 15430 | putPaddrHigh(dmabuf->phys); |
| 15431 | rc++; |
| 15432 | } |
| 15433 | page_idx += rc; |
| 15434 | } |
| 15435 | |
| 15436 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15437 | |
| 15438 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15439 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15440 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15441 | if (shdr_status || shdr_add_status || rc) { |
| 15442 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15443 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15444 | "status x%x add_status x%x, mbx status x%x\n", |
| 15445 | shdr_status, shdr_add_status, rc); |
| 15446 | status = -ENXIO; |
| 15447 | goto out; |
| 15448 | } |
| 15449 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15450 | if (rc == 0xFFFF) { |
| 15451 | status = -ENXIO; |
| 15452 | goto out; |
| 15453 | } |
| 15454 | |
| 15455 | for (idx = 0; idx < numcq; idx++) { |
| 15456 | cq = cqp[idx]; |
| 15457 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15458 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15459 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15460 | } |
| 15461 | |
| 15462 | out: |
| 15463 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15464 | return status; |
| 15465 | } |
| 15466 | |
| 15467 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15468 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15469 | * @phba: HBA structure that indicates port to create a queue on. |
| 15470 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15471 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15472 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15473 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15474 | * This function provides failback (fb) functionality when the |
| 15475 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15476 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15477 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15478 | * This routine cannot fail as all attributes were previously accessed and |
| 15479 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15480 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15481 | static void |
| 15482 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15483 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15484 | { |
| 15485 | struct lpfc_mbx_mq_create *mq_create; |
| 15486 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15487 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15488 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15489 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15490 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15491 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15492 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15493 | length, LPFC_SLI4_MBX_EMBED); |
| 15494 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15495 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15496 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15497 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15498 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15499 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15500 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15501 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15502 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15503 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15504 | break; |
| 15505 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15506 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15507 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15508 | break; |
| 15509 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15510 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15511 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15512 | break; |
| 15513 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15514 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15515 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15516 | break; |
| 15517 | } |
| 15518 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15519 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15520 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15521 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15522 | putPaddrHigh(dmabuf->phys); |
| 15523 | } |
| 15524 | } |
| 15525 | |
| 15526 | /** |
| 15527 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15528 | * @phba: HBA structure that indicates port to create a queue on. |
| 15529 | * @mq: The queue structure to use to create the mailbox queue. |
| 15530 | * @cq: The completion queue to associate with this cq. |
| 15531 | * @subtype: The queue's subtype. |
| 15532 | * |
| 15533 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15534 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15535 | * |
| 15536 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15537 | * is used to get the entry count and entry size that are necessary to |
| 15538 | * determine the number of pages to allocate and use for this queue. This |
| 15539 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15540 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15541 | * command to finish before continuing. |
| 15542 | * |
| 15543 | * 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] | 15544 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15545 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15546 | **/ |
| 15547 | int32_t |
| 15548 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15549 | struct lpfc_queue *cq, uint32_t subtype) |
| 15550 | { |
| 15551 | struct lpfc_mbx_mq_create *mq_create; |
| 15552 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15553 | struct lpfc_dmabuf *dmabuf; |
| 15554 | LPFC_MBOXQ_t *mbox; |
| 15555 | int rc, length, status = 0; |
| 15556 | uint32_t shdr_status, shdr_add_status; |
| 15557 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15558 | 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] | 15559 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15560 | /* sanity check on queue memory */ |
| 15561 | if (!mq || !cq) |
| 15562 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15563 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15564 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15565 | |
| 15566 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15567 | if (!mbox) |
| 15568 | return -ENOMEM; |
| 15569 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15570 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15571 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15572 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15573 | length, LPFC_SLI4_MBX_EMBED); |
| 15574 | |
| 15575 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15576 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15577 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15578 | &mq_create_ext->u.request, mq->page_count); |
| 15579 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15580 | &mq_create_ext->u.request, 1); |
| 15581 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15582 | &mq_create_ext->u.request, 1); |
| 15583 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15584 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15585 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15586 | &mq_create_ext->u.request, 1); |
| 15587 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15588 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15589 | 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] | 15590 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15591 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15592 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15593 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15594 | cq->queue_id); |
| 15595 | else |
| 15596 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15597 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15598 | switch (mq->entry_count) { |
| 15599 | default: |
| 15600 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15601 | "0362 Unsupported MQ count. (%d)\n", |
| 15602 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15603 | if (mq->entry_count < 16) { |
| 15604 | status = -EINVAL; |
| 15605 | goto out; |
| 15606 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15607 | /* fall through - otherwise default to smallest count */ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15608 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15609 | bf_set(lpfc_mq_context_ring_size, |
| 15610 | &mq_create_ext->u.request.context, |
| 15611 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15612 | break; |
| 15613 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15614 | bf_set(lpfc_mq_context_ring_size, |
| 15615 | &mq_create_ext->u.request.context, |
| 15616 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15617 | break; |
| 15618 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15619 | bf_set(lpfc_mq_context_ring_size, |
| 15620 | &mq_create_ext->u.request.context, |
| 15621 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15622 | break; |
| 15623 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15624 | bf_set(lpfc_mq_context_ring_size, |
| 15625 | &mq_create_ext->u.request.context, |
| 15626 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15627 | break; |
| 15628 | } |
| 15629 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15630 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15631 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15632 | putPaddrLow(dmabuf->phys); |
| 15633 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15634 | putPaddrHigh(dmabuf->phys); |
| 15635 | } |
| 15636 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15637 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15638 | &mq_create_ext->u.response); |
| 15639 | if (rc != MBX_SUCCESS) { |
| 15640 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15641 | "2795 MQ_CREATE_EXT failed with " |
| 15642 | "status x%x. Failback to MQ_CREATE.\n", |
| 15643 | rc); |
| 15644 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15645 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15646 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15647 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15648 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15649 | &mq_create->u.response); |
| 15650 | } |
| 15651 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15652 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15653 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15654 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15655 | if (shdr_status || shdr_add_status || rc) { |
| 15656 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15657 | "2502 MQ_CREATE mailbox failed with " |
| 15658 | "status x%x add_status x%x, mbx status x%x\n", |
| 15659 | shdr_status, shdr_add_status, rc); |
| 15660 | status = -ENXIO; |
| 15661 | goto out; |
| 15662 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15663 | if (mq->queue_id == 0xFFFF) { |
| 15664 | status = -ENXIO; |
| 15665 | goto out; |
| 15666 | } |
| 15667 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15668 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15669 | mq->subtype = subtype; |
| 15670 | mq->host_index = 0; |
| 15671 | mq->hba_index = 0; |
| 15672 | |
| 15673 | /* link the mq onto the parent cq child list */ |
| 15674 | list_add_tail(&mq->list, &cq->child_list); |
| 15675 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15676 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15677 | return status; |
| 15678 | } |
| 15679 | |
| 15680 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15681 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15682 | * @phba: HBA structure that indicates port to create a queue on. |
| 15683 | * @wq: The queue structure to use to create the work queue. |
| 15684 | * @cq: The completion queue to bind this work queue to. |
| 15685 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15686 | * |
| 15687 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15688 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15689 | * |
| 15690 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15691 | * is used to get the entry count and entry size that are necessary to |
| 15692 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15693 | * is used to indicate which completion queue to bind this work queue to. This |
| 15694 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15695 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15696 | * command to finish before continuing. |
| 15697 | * |
| 15698 | * 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] | 15699 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15700 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15701 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15702 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15703 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15704 | struct lpfc_queue *cq, uint32_t subtype) |
| 15705 | { |
| 15706 | struct lpfc_mbx_wq_create *wq_create; |
| 15707 | struct lpfc_dmabuf *dmabuf; |
| 15708 | LPFC_MBOXQ_t *mbox; |
| 15709 | int rc, length, status = 0; |
| 15710 | uint32_t shdr_status, shdr_add_status; |
| 15711 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15712 | 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] | 15713 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15714 | void __iomem *bar_memmap_p; |
| 15715 | uint32_t db_offset; |
| 15716 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15717 | uint8_t dpp_barset; |
| 15718 | uint32_t dpp_offset; |
| 15719 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15720 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15721 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15722 | /* sanity check on queue memory */ |
| 15723 | if (!wq || !cq) |
| 15724 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15725 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15726 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15727 | |
| 15728 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15729 | if (!mbox) |
| 15730 | return -ENOMEM; |
| 15731 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15732 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15733 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15734 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15735 | length, LPFC_SLI4_MBX_EMBED); |
| 15736 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15737 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15738 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15739 | wq->page_count); |
| 15740 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15741 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15742 | |
| 15743 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15744 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15745 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15746 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15747 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15748 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15749 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15750 | else |
| 15751 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15752 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15753 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15754 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15755 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15756 | else |
| 15757 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15758 | |
| 15759 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15760 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15761 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15762 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15763 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15764 | LPFC_Q_CREATE_VERSION_1); |
| 15765 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15766 | switch (wq->entry_size) { |
| 15767 | default: |
| 15768 | case 64: |
| 15769 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15770 | &wq_create->u.request_1, |
| 15771 | LPFC_WQ_WQE_SIZE_64); |
| 15772 | break; |
| 15773 | case 128: |
| 15774 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15775 | &wq_create->u.request_1, |
| 15776 | LPFC_WQ_WQE_SIZE_128); |
| 15777 | break; |
| 15778 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15779 | /* Request DPP by default */ |
| 15780 | 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] | 15781 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15782 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15783 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15784 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15785 | break; |
| 15786 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15787 | page = wq_create->u.request.page; |
| 15788 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15789 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15790 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15791 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15792 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15793 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15794 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15795 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15796 | |
| 15797 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15798 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15799 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15800 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15801 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15802 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15803 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15804 | if (shdr_status || shdr_add_status || rc) { |
| 15805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15806 | "2503 WQ_CREATE mailbox failed with " |
| 15807 | "status x%x add_status x%x, mbx status x%x\n", |
| 15808 | shdr_status, shdr_add_status, rc); |
| 15809 | status = -ENXIO; |
| 15810 | goto out; |
| 15811 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15812 | |
| 15813 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15814 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15815 | &wq_create->u.response); |
| 15816 | else |
| 15817 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15818 | &wq_create->u.response_1); |
| 15819 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15820 | if (wq->queue_id == 0xFFFF) { |
| 15821 | status = -ENXIO; |
| 15822 | goto out; |
| 15823 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15824 | |
| 15825 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15826 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15827 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15828 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15829 | &wq_create->u.response); |
| 15830 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15831 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15833 | "3265 WQ[%d] doorbell format " |
| 15834 | "not supported: x%x\n", |
| 15835 | wq->queue_id, wq->db_format); |
| 15836 | status = -EINVAL; |
| 15837 | goto out; |
| 15838 | } |
| 15839 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15840 | &wq_create->u.response); |
| 15841 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15842 | pci_barset); |
| 15843 | if (!bar_memmap_p) { |
| 15844 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15845 | "3263 WQ[%d] failed to memmap " |
| 15846 | "pci barset:x%x\n", |
| 15847 | wq->queue_id, pci_barset); |
| 15848 | status = -ENOMEM; |
| 15849 | goto out; |
| 15850 | } |
| 15851 | db_offset = wq_create->u.response.doorbell_offset; |
| 15852 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15853 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15855 | "3252 WQ[%d] doorbell offset " |
| 15856 | "not supported: x%x\n", |
| 15857 | wq->queue_id, db_offset); |
| 15858 | status = -EINVAL; |
| 15859 | goto out; |
| 15860 | } |
| 15861 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15862 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15863 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15864 | "format:x%x\n", wq->queue_id, |
| 15865 | pci_barset, db_offset, wq->db_format); |
| 15866 | } else |
| 15867 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15868 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15869 | /* Check if DPP was honored by the firmware */ |
| 15870 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15871 | &wq_create->u.response_1); |
| 15872 | if (wq->dpp_enable) { |
| 15873 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15874 | &wq_create->u.response_1); |
| 15875 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15876 | pci_barset); |
| 15877 | if (!bar_memmap_p) { |
| 15878 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15879 | "3267 WQ[%d] failed to memmap " |
| 15880 | "pci barset:x%x\n", |
| 15881 | wq->queue_id, pci_barset); |
| 15882 | status = -ENOMEM; |
| 15883 | goto out; |
| 15884 | } |
| 15885 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15886 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15887 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15888 | &wq_create->u.response_1); |
| 15889 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15890 | &wq_create->u.response_1); |
| 15891 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15892 | dpp_barset); |
| 15893 | if (!bar_memmap_p) { |
| 15894 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15895 | "3268 WQ[%d] failed to memmap " |
| 15896 | "pci barset:x%x\n", |
| 15897 | wq->queue_id, dpp_barset); |
| 15898 | status = -ENOMEM; |
| 15899 | goto out; |
| 15900 | } |
| 15901 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15902 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15903 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15904 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15905 | "dpp_id:x%x dpp_barset:x%x " |
| 15906 | "dpp_offset:x%x\n", |
| 15907 | wq->queue_id, pci_barset, db_offset, |
| 15908 | wq->dpp_id, dpp_barset, dpp_offset); |
| 15909 | |
| 15910 | /* Enable combined writes for DPP aperture */ |
| 15911 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 15912 | #ifdef CONFIG_X86 |
| 15913 | rc = set_memory_wc(pg_addr, 1); |
| 15914 | if (rc) { |
| 15915 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15916 | "3272 Cannot setup Combined " |
| 15917 | "Write on WQ[%d] - disable DPP\n", |
| 15918 | wq->queue_id); |
| 15919 | phba->cfg_enable_dpp = 0; |
| 15920 | } |
| 15921 | #else |
| 15922 | phba->cfg_enable_dpp = 0; |
| 15923 | #endif |
| 15924 | } else |
| 15925 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15926 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15927 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15928 | if (wq->pring == NULL) { |
| 15929 | status = -ENOMEM; |
| 15930 | goto out; |
| 15931 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15932 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15933 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15934 | wq->subtype = subtype; |
| 15935 | wq->host_index = 0; |
| 15936 | wq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15937 | wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15938 | |
| 15939 | /* link the wq onto the parent cq child list */ |
| 15940 | list_add_tail(&wq->list, &cq->child_list); |
| 15941 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15942 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15943 | return status; |
| 15944 | } |
| 15945 | |
| 15946 | /** |
| 15947 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15948 | * @phba: HBA structure that indicates port to create a queue on. |
| 15949 | * @hrq: The queue structure to use to create the header receive queue. |
| 15950 | * @drq: The queue structure to use to create the data receive queue. |
| 15951 | * @cq: The completion queue to bind this work queue to. |
| 15952 | * |
| 15953 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15954 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15955 | * to the HBA. |
| 15956 | * |
| 15957 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15958 | * struct is used to get the entry count that is necessary to determine the |
| 15959 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15960 | * completion queue to bind received buffers that are posted to these queues to. |
| 15961 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15962 | * receive queue pair. This function is asynchronous and will wait for the |
| 15963 | * mailbox command to finish before continuing. |
| 15964 | * |
| 15965 | * 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] | 15966 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15967 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15968 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15969 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15970 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15971 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15972 | { |
| 15973 | struct lpfc_mbx_rq_create *rq_create; |
| 15974 | struct lpfc_dmabuf *dmabuf; |
| 15975 | LPFC_MBOXQ_t *mbox; |
| 15976 | int rc, length, status = 0; |
| 15977 | uint32_t shdr_status, shdr_add_status; |
| 15978 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15979 | 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] | 15980 | void __iomem *bar_memmap_p; |
| 15981 | uint32_t db_offset; |
| 15982 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15983 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15984 | /* sanity check on queue memory */ |
| 15985 | if (!hrq || !drq || !cq) |
| 15986 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15987 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15988 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15989 | |
| 15990 | if (hrq->entry_count != drq->entry_count) |
| 15991 | return -EINVAL; |
| 15992 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15993 | if (!mbox) |
| 15994 | return -ENOMEM; |
| 15995 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15996 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15997 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15998 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15999 | length, LPFC_SLI4_MBX_EMBED); |
| 16000 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16001 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 16002 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16003 | phba->sli4_hba.pc_sli4_params.rqv); |
| 16004 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 16005 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16006 | &rq_create->u.request.context, |
| 16007 | hrq->entry_count); |
| 16008 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16009 | bf_set(lpfc_rq_context_rqe_size, |
| 16010 | &rq_create->u.request.context, |
| 16011 | LPFC_RQE_SIZE_8); |
| 16012 | bf_set(lpfc_rq_context_page_size, |
| 16013 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 16014 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16015 | } else { |
| 16016 | switch (hrq->entry_count) { |
| 16017 | default: |
| 16018 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16019 | "2535 Unsupported RQ count. (%d)\n", |
| 16020 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16021 | if (hrq->entry_count < 512) { |
| 16022 | status = -EINVAL; |
| 16023 | goto out; |
| 16024 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 16025 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16026 | case 512: |
| 16027 | bf_set(lpfc_rq_context_rqe_count, |
| 16028 | &rq_create->u.request.context, |
| 16029 | LPFC_RQ_RING_SIZE_512); |
| 16030 | break; |
| 16031 | case 1024: |
| 16032 | bf_set(lpfc_rq_context_rqe_count, |
| 16033 | &rq_create->u.request.context, |
| 16034 | LPFC_RQ_RING_SIZE_1024); |
| 16035 | break; |
| 16036 | case 2048: |
| 16037 | bf_set(lpfc_rq_context_rqe_count, |
| 16038 | &rq_create->u.request.context, |
| 16039 | LPFC_RQ_RING_SIZE_2048); |
| 16040 | break; |
| 16041 | case 4096: |
| 16042 | bf_set(lpfc_rq_context_rqe_count, |
| 16043 | &rq_create->u.request.context, |
| 16044 | LPFC_RQ_RING_SIZE_4096); |
| 16045 | break; |
| 16046 | } |
| 16047 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 16048 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16049 | } |
| 16050 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 16051 | cq->queue_id); |
| 16052 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 16053 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16054 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16055 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16056 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16057 | putPaddrLow(dmabuf->phys); |
| 16058 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16059 | putPaddrHigh(dmabuf->phys); |
| 16060 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16061 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16062 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 16063 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16064 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16065 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16066 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16067 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16068 | if (shdr_status || shdr_add_status || rc) { |
| 16069 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16070 | "2504 RQ_CREATE mailbox failed with " |
| 16071 | "status x%x add_status x%x, mbx status x%x\n", |
| 16072 | shdr_status, shdr_add_status, rc); |
| 16073 | status = -ENXIO; |
| 16074 | goto out; |
| 16075 | } |
| 16076 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16077 | if (hrq->queue_id == 0xFFFF) { |
| 16078 | status = -ENXIO; |
| 16079 | goto out; |
| 16080 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16081 | |
| 16082 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 16083 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 16084 | &rq_create->u.response); |
| 16085 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 16086 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 16087 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16088 | "3262 RQ [%d] doorbell format not " |
| 16089 | "supported: x%x\n", hrq->queue_id, |
| 16090 | hrq->db_format); |
| 16091 | status = -EINVAL; |
| 16092 | goto out; |
| 16093 | } |
| 16094 | |
| 16095 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 16096 | &rq_create->u.response); |
| 16097 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 16098 | if (!bar_memmap_p) { |
| 16099 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16100 | "3269 RQ[%d] failed to memmap pci " |
| 16101 | "barset:x%x\n", hrq->queue_id, |
| 16102 | pci_barset); |
| 16103 | status = -ENOMEM; |
| 16104 | goto out; |
| 16105 | } |
| 16106 | |
| 16107 | db_offset = rq_create->u.response.doorbell_offset; |
| 16108 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 16109 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 16110 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16111 | "3270 RQ[%d] doorbell offset not " |
| 16112 | "supported: x%x\n", hrq->queue_id, |
| 16113 | db_offset); |
| 16114 | status = -EINVAL; |
| 16115 | goto out; |
| 16116 | } |
| 16117 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 16118 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 16119 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 16120 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 16121 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16122 | } else { |
| 16123 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16124 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16125 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16126 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16127 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16128 | hrq->subtype = subtype; |
| 16129 | hrq->host_index = 0; |
| 16130 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16131 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16132 | |
| 16133 | /* now create the data queue */ |
| 16134 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16135 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 16136 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16137 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16138 | phba->sli4_hba.pc_sli4_params.rqv); |
| 16139 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 16140 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16141 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16142 | if (subtype == LPFC_NVMET) |
| 16143 | rq_create->u.request.context.buffer_size = |
| 16144 | LPFC_NVMET_DATA_BUF_SIZE; |
| 16145 | else |
| 16146 | rq_create->u.request.context.buffer_size = |
| 16147 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16148 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 16149 | LPFC_RQE_SIZE_8); |
| 16150 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 16151 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16152 | } else { |
| 16153 | switch (drq->entry_count) { |
| 16154 | default: |
| 16155 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16156 | "2536 Unsupported RQ count. (%d)\n", |
| 16157 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16158 | if (drq->entry_count < 512) { |
| 16159 | status = -EINVAL; |
| 16160 | goto out; |
| 16161 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 16162 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16163 | case 512: |
| 16164 | bf_set(lpfc_rq_context_rqe_count, |
| 16165 | &rq_create->u.request.context, |
| 16166 | LPFC_RQ_RING_SIZE_512); |
| 16167 | break; |
| 16168 | case 1024: |
| 16169 | bf_set(lpfc_rq_context_rqe_count, |
| 16170 | &rq_create->u.request.context, |
| 16171 | LPFC_RQ_RING_SIZE_1024); |
| 16172 | break; |
| 16173 | case 2048: |
| 16174 | bf_set(lpfc_rq_context_rqe_count, |
| 16175 | &rq_create->u.request.context, |
| 16176 | LPFC_RQ_RING_SIZE_2048); |
| 16177 | break; |
| 16178 | case 4096: |
| 16179 | bf_set(lpfc_rq_context_rqe_count, |
| 16180 | &rq_create->u.request.context, |
| 16181 | LPFC_RQ_RING_SIZE_4096); |
| 16182 | break; |
| 16183 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16184 | if (subtype == LPFC_NVMET) |
| 16185 | bf_set(lpfc_rq_context_buf_size, |
| 16186 | &rq_create->u.request.context, |
| 16187 | LPFC_NVMET_DATA_BUF_SIZE); |
| 16188 | else |
| 16189 | bf_set(lpfc_rq_context_buf_size, |
| 16190 | &rq_create->u.request.context, |
| 16191 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16192 | } |
| 16193 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 16194 | cq->queue_id); |
| 16195 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 16196 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16197 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16198 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16199 | putPaddrLow(dmabuf->phys); |
| 16200 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16201 | putPaddrHigh(dmabuf->phys); |
| 16202 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16203 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16204 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16205 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16206 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16207 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 16208 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16209 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16210 | if (shdr_status || shdr_add_status || rc) { |
| 16211 | status = -ENXIO; |
| 16212 | goto out; |
| 16213 | } |
| 16214 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16215 | if (drq->queue_id == 0xFFFF) { |
| 16216 | status = -ENXIO; |
| 16217 | goto out; |
| 16218 | } |
| 16219 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16220 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16221 | drq->subtype = subtype; |
| 16222 | drq->host_index = 0; |
| 16223 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16224 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16225 | |
| 16226 | /* link the header and data RQs onto the parent cq child list */ |
| 16227 | list_add_tail(&hrq->list, &cq->child_list); |
| 16228 | list_add_tail(&drq->list, &cq->child_list); |
| 16229 | |
| 16230 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16231 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16232 | return status; |
| 16233 | } |
| 16234 | |
| 16235 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16236 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 16237 | * @phba: HBA structure that indicates port to create a queue on. |
| 16238 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 16239 | * @drqp: The queue structure array to use to create the data receive queues. |
| 16240 | * @cqp: The completion queue array to bind these receive queues to. |
| 16241 | * |
| 16242 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 16243 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 16244 | * to the HBA. |
| 16245 | * |
| 16246 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 16247 | * struct is used to get the entry count that is necessary to determine the |
| 16248 | * number of pages to use for this queue. The @cq is used to indicate which |
| 16249 | * completion queue to bind received buffers that are posted to these queues to. |
| 16250 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 16251 | * receive queue pair. This function is asynchronous and will wait for the |
| 16252 | * mailbox command to finish before continuing. |
| 16253 | * |
| 16254 | * On success this function will return a zero. If unable to allocate enough |
| 16255 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16256 | * fails this function will return -ENXIO. |
| 16257 | **/ |
| 16258 | int |
| 16259 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 16260 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 16261 | uint32_t subtype) |
| 16262 | { |
| 16263 | struct lpfc_queue *hrq, *drq, *cq; |
| 16264 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 16265 | struct lpfc_dmabuf *dmabuf; |
| 16266 | LPFC_MBOXQ_t *mbox; |
| 16267 | int rc, length, alloclen, status = 0; |
| 16268 | int cnt, idx, numrq, page_idx = 0; |
| 16269 | uint32_t shdr_status, shdr_add_status; |
| 16270 | union lpfc_sli4_cfg_shdr *shdr; |
| 16271 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 16272 | |
| 16273 | numrq = phba->cfg_nvmet_mrq; |
| 16274 | /* sanity check on array memory */ |
| 16275 | if (!hrqp || !drqp || !cqp || !numrq) |
| 16276 | return -ENODEV; |
| 16277 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16278 | hw_page_size = SLI4_PAGE_SIZE; |
| 16279 | |
| 16280 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16281 | if (!mbox) |
| 16282 | return -ENOMEM; |
| 16283 | |
| 16284 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 16285 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 16286 | sizeof(struct dma_address)); |
| 16287 | |
| 16288 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16289 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 16290 | LPFC_SLI4_MBX_NEMBED); |
| 16291 | if (alloclen < length) { |
| 16292 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16293 | "3099 Allocated DMA memory size (%d) is " |
| 16294 | "less than the requested DMA memory size " |
| 16295 | "(%d)\n", alloclen, length); |
| 16296 | status = -ENOMEM; |
| 16297 | goto out; |
| 16298 | } |
| 16299 | |
| 16300 | |
| 16301 | |
| 16302 | rq_create = mbox->sge_array->addr[0]; |
| 16303 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 16304 | |
| 16305 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 16306 | cnt = 0; |
| 16307 | |
| 16308 | for (idx = 0; idx < numrq; idx++) { |
| 16309 | hrq = hrqp[idx]; |
| 16310 | drq = drqp[idx]; |
| 16311 | cq = cqp[idx]; |
| 16312 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16313 | /* sanity check on queue memory */ |
| 16314 | if (!hrq || !drq || !cq) { |
| 16315 | status = -ENODEV; |
| 16316 | goto out; |
| 16317 | } |
| 16318 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 16319 | if (hrq->entry_count != drq->entry_count) { |
| 16320 | status = -EINVAL; |
| 16321 | goto out; |
| 16322 | } |
| 16323 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16324 | if (idx == 0) { |
| 16325 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 16326 | &rq_create->u.request, |
| 16327 | hrq->page_count); |
| 16328 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 16329 | &rq_create->u.request, (numrq * 2)); |
| 16330 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 16331 | 1); |
| 16332 | bf_set(lpfc_rq_context_base_cq, |
| 16333 | &rq_create->u.request.context, |
| 16334 | cq->queue_id); |
| 16335 | bf_set(lpfc_rq_context_data_size, |
| 16336 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16337 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16338 | bf_set(lpfc_rq_context_hdr_size, |
| 16339 | &rq_create->u.request.context, |
| 16340 | LPFC_HDR_BUF_SIZE); |
| 16341 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16342 | &rq_create->u.request.context, |
| 16343 | hrq->entry_count); |
| 16344 | bf_set(lpfc_rq_context_rqe_size, |
| 16345 | &rq_create->u.request.context, |
| 16346 | LPFC_RQE_SIZE_8); |
| 16347 | bf_set(lpfc_rq_context_page_size, |
| 16348 | &rq_create->u.request.context, |
| 16349 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 16350 | } |
| 16351 | rc = 0; |
| 16352 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 16353 | memset(dmabuf->virt, 0, hw_page_size); |
| 16354 | cnt = page_idx + dmabuf->buffer_tag; |
| 16355 | rq_create->u.request.page[cnt].addr_lo = |
| 16356 | putPaddrLow(dmabuf->phys); |
| 16357 | rq_create->u.request.page[cnt].addr_hi = |
| 16358 | putPaddrHigh(dmabuf->phys); |
| 16359 | rc++; |
| 16360 | } |
| 16361 | page_idx += rc; |
| 16362 | |
| 16363 | rc = 0; |
| 16364 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16365 | memset(dmabuf->virt, 0, hw_page_size); |
| 16366 | cnt = page_idx + dmabuf->buffer_tag; |
| 16367 | rq_create->u.request.page[cnt].addr_lo = |
| 16368 | putPaddrLow(dmabuf->phys); |
| 16369 | rq_create->u.request.page[cnt].addr_hi = |
| 16370 | putPaddrHigh(dmabuf->phys); |
| 16371 | rc++; |
| 16372 | } |
| 16373 | page_idx += rc; |
| 16374 | |
| 16375 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16376 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16377 | hrq->type = LPFC_HRQ; |
| 16378 | hrq->assoc_qid = cq->queue_id; |
| 16379 | hrq->subtype = subtype; |
| 16380 | hrq->host_index = 0; |
| 16381 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16382 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16383 | |
| 16384 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 16385 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16386 | drq->type = LPFC_DRQ; |
| 16387 | drq->assoc_qid = cq->queue_id; |
| 16388 | drq->subtype = subtype; |
| 16389 | drq->host_index = 0; |
| 16390 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16391 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16392 | |
| 16393 | list_add_tail(&hrq->list, &cq->child_list); |
| 16394 | list_add_tail(&drq->list, &cq->child_list); |
| 16395 | } |
| 16396 | |
| 16397 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16398 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16399 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16400 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16401 | if (shdr_status || shdr_add_status || rc) { |
| 16402 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16403 | "3120 RQ_CREATE mailbox failed with " |
| 16404 | "status x%x add_status x%x, mbx status x%x\n", |
| 16405 | shdr_status, shdr_add_status, rc); |
| 16406 | status = -ENXIO; |
| 16407 | goto out; |
| 16408 | } |
| 16409 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16410 | if (rc == 0xFFFF) { |
| 16411 | status = -ENXIO; |
| 16412 | goto out; |
| 16413 | } |
| 16414 | |
| 16415 | /* Initialize all RQs with associated queue id */ |
| 16416 | for (idx = 0; idx < numrq; idx++) { |
| 16417 | hrq = hrqp[idx]; |
| 16418 | hrq->queue_id = rc + (2 * idx); |
| 16419 | drq = drqp[idx]; |
| 16420 | drq->queue_id = rc + (2 * idx) + 1; |
| 16421 | } |
| 16422 | |
| 16423 | out: |
| 16424 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16425 | return status; |
| 16426 | } |
| 16427 | |
| 16428 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16429 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 16430 | * @eq: The queue structure associated with the queue to destroy. |
| 16431 | * |
| 16432 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16433 | * command, specific to the type of queue, to the HBA. |
| 16434 | * |
| 16435 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16436 | * |
| 16437 | * 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] | 16438 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16439 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16440 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16441 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16442 | { |
| 16443 | LPFC_MBOXQ_t *mbox; |
| 16444 | int rc, length, status = 0; |
| 16445 | uint32_t shdr_status, shdr_add_status; |
| 16446 | union lpfc_sli4_cfg_shdr *shdr; |
| 16447 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16448 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16449 | if (!eq) |
| 16450 | return -ENODEV; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16451 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16452 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16453 | if (!mbox) |
| 16454 | return -ENOMEM; |
| 16455 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16456 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16457 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16458 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16459 | length, LPFC_SLI4_MBX_EMBED); |
| 16460 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16461 | eq->queue_id); |
| 16462 | mbox->vport = eq->phba->pport; |
| 16463 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16464 | |
| 16465 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16466 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16467 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16468 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16469 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16470 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16471 | if (shdr_status || shdr_add_status || rc) { |
| 16472 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16473 | "2505 EQ_DESTROY mailbox failed with " |
| 16474 | "status x%x add_status x%x, mbx status x%x\n", |
| 16475 | shdr_status, shdr_add_status, rc); |
| 16476 | status = -ENXIO; |
| 16477 | } |
| 16478 | |
| 16479 | /* Remove eq from any list */ |
| 16480 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16481 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16482 | return status; |
| 16483 | } |
| 16484 | |
| 16485 | /** |
| 16486 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 16487 | * @cq: The queue structure associated with the queue to destroy. |
| 16488 | * |
| 16489 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16490 | * command, specific to the type of queue, to the HBA. |
| 16491 | * |
| 16492 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16493 | * |
| 16494 | * 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] | 16495 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16496 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16497 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16498 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16499 | { |
| 16500 | LPFC_MBOXQ_t *mbox; |
| 16501 | int rc, length, status = 0; |
| 16502 | uint32_t shdr_status, shdr_add_status; |
| 16503 | union lpfc_sli4_cfg_shdr *shdr; |
| 16504 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16505 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16506 | if (!cq) |
| 16507 | return -ENODEV; |
| 16508 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16509 | if (!mbox) |
| 16510 | return -ENOMEM; |
| 16511 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16512 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16513 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16514 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16515 | length, LPFC_SLI4_MBX_EMBED); |
| 16516 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16517 | cq->queue_id); |
| 16518 | mbox->vport = cq->phba->pport; |
| 16519 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16520 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16521 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16522 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16523 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16524 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16525 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16526 | if (shdr_status || shdr_add_status || rc) { |
| 16527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16528 | "2506 CQ_DESTROY mailbox failed with " |
| 16529 | "status x%x add_status x%x, mbx status x%x\n", |
| 16530 | shdr_status, shdr_add_status, rc); |
| 16531 | status = -ENXIO; |
| 16532 | } |
| 16533 | /* Remove cq from any list */ |
| 16534 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16535 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16536 | return status; |
| 16537 | } |
| 16538 | |
| 16539 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16540 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 16541 | * @qm: The queue structure associated with the queue to destroy. |
| 16542 | * |
| 16543 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16544 | * command, specific to the type of queue, to the HBA. |
| 16545 | * |
| 16546 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16547 | * |
| 16548 | * 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] | 16549 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16550 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16551 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16552 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16553 | { |
| 16554 | LPFC_MBOXQ_t *mbox; |
| 16555 | int rc, length, status = 0; |
| 16556 | uint32_t shdr_status, shdr_add_status; |
| 16557 | union lpfc_sli4_cfg_shdr *shdr; |
| 16558 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16559 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16560 | if (!mq) |
| 16561 | return -ENODEV; |
| 16562 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16563 | if (!mbox) |
| 16564 | return -ENOMEM; |
| 16565 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16566 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16567 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16568 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16569 | length, LPFC_SLI4_MBX_EMBED); |
| 16570 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16571 | mq->queue_id); |
| 16572 | mbox->vport = mq->phba->pport; |
| 16573 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16574 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16575 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16576 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16577 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16578 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16579 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16580 | if (shdr_status || shdr_add_status || rc) { |
| 16581 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16582 | "2507 MQ_DESTROY mailbox failed with " |
| 16583 | "status x%x add_status x%x, mbx status x%x\n", |
| 16584 | shdr_status, shdr_add_status, rc); |
| 16585 | status = -ENXIO; |
| 16586 | } |
| 16587 | /* Remove mq from any list */ |
| 16588 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16589 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16590 | return status; |
| 16591 | } |
| 16592 | |
| 16593 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16594 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16595 | * @wq: The queue structure associated with the queue to destroy. |
| 16596 | * |
| 16597 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16598 | * command, specific to the type of queue, to the HBA. |
| 16599 | * |
| 16600 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16601 | * |
| 16602 | * 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] | 16603 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16604 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16605 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16606 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16607 | { |
| 16608 | LPFC_MBOXQ_t *mbox; |
| 16609 | int rc, length, status = 0; |
| 16610 | uint32_t shdr_status, shdr_add_status; |
| 16611 | union lpfc_sli4_cfg_shdr *shdr; |
| 16612 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16613 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16614 | if (!wq) |
| 16615 | return -ENODEV; |
| 16616 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16617 | if (!mbox) |
| 16618 | return -ENOMEM; |
| 16619 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16620 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16621 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16622 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16623 | length, LPFC_SLI4_MBX_EMBED); |
| 16624 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16625 | wq->queue_id); |
| 16626 | mbox->vport = wq->phba->pport; |
| 16627 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16628 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16629 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16630 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16631 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16632 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16633 | if (shdr_status || shdr_add_status || rc) { |
| 16634 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16635 | "2508 WQ_DESTROY mailbox failed with " |
| 16636 | "status x%x add_status x%x, mbx status x%x\n", |
| 16637 | shdr_status, shdr_add_status, rc); |
| 16638 | status = -ENXIO; |
| 16639 | } |
| 16640 | /* Remove wq from any list */ |
| 16641 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16642 | kfree(wq->pring); |
| 16643 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16644 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16645 | return status; |
| 16646 | } |
| 16647 | |
| 16648 | /** |
| 16649 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16650 | * @rq: The queue structure associated with the queue to destroy. |
| 16651 | * |
| 16652 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16653 | * command, specific to the type of queue, to the HBA. |
| 16654 | * |
| 16655 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16656 | * |
| 16657 | * 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] | 16658 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16659 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16660 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16661 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16662 | struct lpfc_queue *drq) |
| 16663 | { |
| 16664 | LPFC_MBOXQ_t *mbox; |
| 16665 | int rc, length, status = 0; |
| 16666 | uint32_t shdr_status, shdr_add_status; |
| 16667 | union lpfc_sli4_cfg_shdr *shdr; |
| 16668 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16669 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16670 | if (!hrq || !drq) |
| 16671 | return -ENODEV; |
| 16672 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16673 | if (!mbox) |
| 16674 | return -ENOMEM; |
| 16675 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16676 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16677 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16678 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16679 | length, LPFC_SLI4_MBX_EMBED); |
| 16680 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16681 | hrq->queue_id); |
| 16682 | mbox->vport = hrq->phba->pport; |
| 16683 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16684 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16685 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16686 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16687 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16688 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16689 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16690 | if (shdr_status || shdr_add_status || rc) { |
| 16691 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16692 | "2509 RQ_DESTROY mailbox failed with " |
| 16693 | "status x%x add_status x%x, mbx status x%x\n", |
| 16694 | shdr_status, shdr_add_status, rc); |
| 16695 | if (rc != MBX_TIMEOUT) |
| 16696 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16697 | return -ENXIO; |
| 16698 | } |
| 16699 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16700 | drq->queue_id); |
| 16701 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16702 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16703 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16704 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16705 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16706 | if (shdr_status || shdr_add_status || rc) { |
| 16707 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16708 | "2510 RQ_DESTROY mailbox failed with " |
| 16709 | "status x%x add_status x%x, mbx status x%x\n", |
| 16710 | shdr_status, shdr_add_status, rc); |
| 16711 | status = -ENXIO; |
| 16712 | } |
| 16713 | list_del_init(&hrq->list); |
| 16714 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16715 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16716 | return status; |
| 16717 | } |
| 16718 | |
| 16719 | /** |
| 16720 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16721 | * @phba: The virtual port for which this call being executed. |
| 16722 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16723 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16724 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16725 | * |
| 16726 | * This routine will post the sgl pages for the IO that has the xritag |
| 16727 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16728 | * creation and persists for as long as the driver is loaded. |
| 16729 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16730 | * pdma_phys_addr1 should be 0. |
| 16731 | * If the caller needs to map more than 256 scatter gather segment then |
| 16732 | * pdma_phys_addr1 should be a valid physical address. |
| 16733 | * physical address for SGLs must be 64 byte aligned. |
| 16734 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16735 | * the second sgl can have between 1 and 256 entries. |
| 16736 | * |
| 16737 | * Return codes: |
| 16738 | * 0 - Success |
| 16739 | * -ENXIO, -ENOMEM - Failure |
| 16740 | **/ |
| 16741 | int |
| 16742 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16743 | dma_addr_t pdma_phys_addr0, |
| 16744 | dma_addr_t pdma_phys_addr1, |
| 16745 | uint16_t xritag) |
| 16746 | { |
| 16747 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16748 | LPFC_MBOXQ_t *mbox; |
| 16749 | int rc; |
| 16750 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16751 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16752 | union lpfc_sli4_cfg_shdr *shdr; |
| 16753 | |
| 16754 | if (xritag == NO_XRI) { |
| 16755 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16756 | "0364 Invalid param:\n"); |
| 16757 | return -EINVAL; |
| 16758 | } |
| 16759 | |
| 16760 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16761 | if (!mbox) |
| 16762 | return -ENOMEM; |
| 16763 | |
| 16764 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16765 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16766 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16767 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16768 | |
| 16769 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16770 | &mbox->u.mqe.un.post_sgl_pages; |
| 16771 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16772 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16773 | |
| 16774 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16775 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16776 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16777 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16778 | |
| 16779 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16780 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16781 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16782 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16783 | if (!phba->sli4_hba.intr_enable) |
| 16784 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16785 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16786 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16787 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16788 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16789 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16790 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16791 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16792 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16793 | if (rc != MBX_TIMEOUT) |
| 16794 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16795 | if (shdr_status || shdr_add_status || rc) { |
| 16796 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16797 | "2511 POST_SGL mailbox failed with " |
| 16798 | "status x%x add_status x%x, mbx status x%x\n", |
| 16799 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16800 | } |
| 16801 | return 0; |
| 16802 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16803 | |
| 16804 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16805 | * 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] | 16806 | * @phba: pointer to lpfc hba data structure. |
| 16807 | * |
| 16808 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16809 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16810 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16811 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16812 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16813 | * Returns |
| 16814 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16815 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16816 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16817 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16818 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16819 | { |
| 16820 | unsigned long xri; |
| 16821 | |
| 16822 | /* |
| 16823 | * Fetch the next logical xri. Because this index is logical, |
| 16824 | * the driver starts at 0 each time. |
| 16825 | */ |
| 16826 | spin_lock_irq(&phba->hbalock); |
| 16827 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16828 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16829 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16830 | spin_unlock_irq(&phba->hbalock); |
| 16831 | return NO_XRI; |
| 16832 | } else { |
| 16833 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16834 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16835 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16836 | spin_unlock_irq(&phba->hbalock); |
| 16837 | return xri; |
| 16838 | } |
| 16839 | |
| 16840 | /** |
| 16841 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16842 | * @phba: pointer to lpfc hba data structure. |
| 16843 | * |
| 16844 | * This routine is invoked to release an xri to the pool of |
| 16845 | * available rpis maintained by the driver. |
| 16846 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16847 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16848 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16849 | { |
| 16850 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16851 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16852 | } |
| 16853 | } |
| 16854 | |
| 16855 | /** |
| 16856 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16857 | * @phba: pointer to lpfc hba data structure. |
| 16858 | * |
| 16859 | * This routine is invoked to release an xri to the pool of |
| 16860 | * available rpis maintained by the driver. |
| 16861 | **/ |
| 16862 | void |
| 16863 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16864 | { |
| 16865 | spin_lock_irq(&phba->hbalock); |
| 16866 | __lpfc_sli4_free_xri(phba, xri); |
| 16867 | spin_unlock_irq(&phba->hbalock); |
| 16868 | } |
| 16869 | |
| 16870 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16871 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16872 | * @phba: Pointer to HBA context object. |
| 16873 | * |
| 16874 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16875 | * it will return 0xffff. |
| 16876 | * The function returns the allocated xritag if successful, else returns zero. |
| 16877 | * Zero is not a valid xritag. |
| 16878 | * The caller is not required to hold any lock. |
| 16879 | **/ |
| 16880 | uint16_t |
| 16881 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16882 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16883 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16884 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16885 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16886 | if (xri_index == NO_XRI) |
| 16887 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16888 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16889 | " Max XRI is %d, Used XRI is %d\n", |
| 16890 | xri_index, |
| 16891 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16892 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16893 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16894 | } |
| 16895 | |
| 16896 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16897 | * 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] | 16898 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16899 | * @post_sgl_list: pointer to els sgl entry list. |
| 16900 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16901 | * |
| 16902 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16903 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16904 | * is only called when the driver is loading and after all IO has been |
| 16905 | * stopped. |
| 16906 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16907 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16908 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16909 | struct list_head *post_sgl_list, |
| 16910 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16911 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16912 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16913 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16914 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16915 | void *viraddr; |
| 16916 | LPFC_MBOXQ_t *mbox; |
| 16917 | uint32_t reqlen, alloclen, pg_pairs; |
| 16918 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16919 | uint16_t xritag_start = 0; |
| 16920 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16921 | uint32_t shdr_status, shdr_add_status; |
| 16922 | union lpfc_sli4_cfg_shdr *shdr; |
| 16923 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16924 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16925 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16926 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16927 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16928 | "2559 Block sgl registration required DMA " |
| 16929 | "size (%d) great than a page\n", reqlen); |
| 16930 | return -ENOMEM; |
| 16931 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16932 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16933 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16934 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16935 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16936 | |
| 16937 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16938 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16939 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16940 | LPFC_SLI4_MBX_NEMBED); |
| 16941 | |
| 16942 | if (alloclen < reqlen) { |
| 16943 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16944 | "0285 Allocated DMA memory size (%d) is " |
| 16945 | "less than the requested DMA memory " |
| 16946 | "size (%d)\n", alloclen, reqlen); |
| 16947 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16948 | return -ENOMEM; |
| 16949 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16950 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16951 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16952 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16953 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16954 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16955 | pg_pairs = 0; |
| 16956 | 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] | 16957 | /* Set up the sge entry */ |
| 16958 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16959 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16960 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16961 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16962 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16963 | cpu_to_le32(putPaddrLow(0)); |
| 16964 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16965 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16966 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16967 | /* Keep the first xritag on the list */ |
| 16968 | if (pg_pairs == 0) |
| 16969 | xritag_start = sglq_entry->sli4_xritag; |
| 16970 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16971 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16972 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16973 | |
| 16974 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16975 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16976 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16977 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16978 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16979 | if (!phba->sli4_hba.intr_enable) |
| 16980 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16981 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16982 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16983 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16984 | } |
| 16985 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16986 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16987 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16988 | if (rc != MBX_TIMEOUT) |
| 16989 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16990 | if (shdr_status || shdr_add_status || rc) { |
| 16991 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16992 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16993 | "status x%x add_status x%x mbx status x%x\n", |
| 16994 | shdr_status, shdr_add_status, rc); |
| 16995 | rc = -ENXIO; |
| 16996 | } |
| 16997 | return rc; |
| 16998 | } |
| 16999 | |
| 17000 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17001 | * 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] | 17002 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17003 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17004 | * @count: number of scsi buffers on the list. |
| 17005 | * |
| 17006 | * 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] | 17007 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17008 | * No Lock is held. |
| 17009 | * |
| 17010 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17011 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17012 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 17013 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17014 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17015 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17016 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 17017 | struct sgl_page_pairs *sgl_pg_pairs; |
| 17018 | void *viraddr; |
| 17019 | LPFC_MBOXQ_t *mbox; |
| 17020 | uint32_t reqlen, alloclen, pg_pairs; |
| 17021 | uint32_t mbox_tmo; |
| 17022 | uint16_t xritag_start = 0; |
| 17023 | int rc = 0; |
| 17024 | uint32_t shdr_status, shdr_add_status; |
| 17025 | dma_addr_t pdma_phys_bpl1; |
| 17026 | union lpfc_sli4_cfg_shdr *shdr; |
| 17027 | |
| 17028 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17029 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17030 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17031 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17032 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17033 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17034 | "size (%d) great than a page\n", reqlen); |
| 17035 | return -ENOMEM; |
| 17036 | } |
| 17037 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17038 | if (!mbox) { |
| 17039 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17040 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17041 | return -ENOMEM; |
| 17042 | } |
| 17043 | |
| 17044 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 17045 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17046 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 17047 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17048 | |
| 17049 | if (alloclen < reqlen) { |
| 17050 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17051 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17052 | "less than the requested DMA memory " |
| 17053 | "size (%d)\n", alloclen, reqlen); |
| 17054 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17055 | return -ENOMEM; |
| 17056 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17057 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17058 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17059 | viraddr = mbox->sge_array->addr[0]; |
| 17060 | |
| 17061 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 17062 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 17063 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 17064 | |
| 17065 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17066 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17067 | /* Set up the sge entry */ |
| 17068 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17069 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17070 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17071 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17072 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17073 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 17074 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17075 | else |
| 17076 | pdma_phys_bpl1 = 0; |
| 17077 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 17078 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 17079 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 17080 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 17081 | /* Keep the first xritag on the list */ |
| 17082 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17083 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17084 | sgl_pg_pairs++; |
| 17085 | pg_pairs++; |
| 17086 | } |
| 17087 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 17088 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 17089 | /* Perform endian conversion if necessary */ |
| 17090 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 17091 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17092 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17093 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17094 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17095 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17096 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17097 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17098 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17099 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17100 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17101 | if (rc != MBX_TIMEOUT) |
| 17102 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17103 | if (shdr_status || shdr_add_status || rc) { |
| 17104 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17105 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17106 | "status x%x add_status x%x mbx status x%x\n", |
| 17107 | shdr_status, shdr_add_status, rc); |
| 17108 | rc = -ENXIO; |
| 17109 | } |
| 17110 | return rc; |
| 17111 | } |
| 17112 | |
| 17113 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17114 | * 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] | 17115 | * @phba: pointer to lpfc hba data structure. |
| 17116 | * @post_nblist: pointer to the nvme buffer list. |
| 17117 | * |
| 17118 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 17119 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 17120 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 17121 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 17122 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 17123 | * must be local list, thus no lock is needed when manipulate the list. |
| 17124 | * |
| 17125 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 17126 | **/ |
| 17127 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17128 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 17129 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17130 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17131 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17132 | int status, sgl_size; |
| 17133 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 17134 | dma_addr_t pdma_phys_sgl1; |
| 17135 | int last_xritag = NO_XRI; |
| 17136 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17137 | LIST_HEAD(prep_nblist); |
| 17138 | LIST_HEAD(blck_nblist); |
| 17139 | LIST_HEAD(nvme_nblist); |
| 17140 | |
| 17141 | /* sanity check */ |
| 17142 | if (sb_count <= 0) |
| 17143 | return -EINVAL; |
| 17144 | |
| 17145 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 17146 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 17147 | list_del_init(&lpfc_ncmd->list); |
| 17148 | block_cnt++; |
| 17149 | if ((last_xritag != NO_XRI) && |
| 17150 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 17151 | /* a hole in xri block, form a sgl posting block */ |
| 17152 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17153 | post_cnt = block_cnt - 1; |
| 17154 | /* prepare list for next posting block */ |
| 17155 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 17156 | block_cnt = 1; |
| 17157 | } else { |
| 17158 | /* prepare list for next posting block */ |
| 17159 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 17160 | /* enough sgls for non-embed sgl mbox command */ |
| 17161 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 17162 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17163 | post_cnt = block_cnt; |
| 17164 | block_cnt = 0; |
| 17165 | } |
| 17166 | } |
| 17167 | num_posting++; |
| 17168 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 17169 | |
| 17170 | /* end of repost sgl list condition for NVME buffers */ |
| 17171 | if (num_posting == sb_count) { |
| 17172 | if (post_cnt == 0) { |
| 17173 | /* last sgl posting block */ |
| 17174 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17175 | post_cnt = block_cnt; |
| 17176 | } else if (block_cnt == 1) { |
| 17177 | /* last single sgl with non-contiguous xri */ |
| 17178 | if (sgl_size > SGL_PAGE_SIZE) |
| 17179 | pdma_phys_sgl1 = |
| 17180 | lpfc_ncmd->dma_phys_sgl + |
| 17181 | SGL_PAGE_SIZE; |
| 17182 | else |
| 17183 | pdma_phys_sgl1 = 0; |
| 17184 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 17185 | status = lpfc_sli4_post_sgl( |
| 17186 | phba, lpfc_ncmd->dma_phys_sgl, |
| 17187 | pdma_phys_sgl1, cur_xritag); |
| 17188 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17189 | /* Post error. Buffer unavailable. */ |
| 17190 | lpfc_ncmd->flags |= |
| 17191 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17192 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17193 | /* Post success. Bffer available. */ |
| 17194 | lpfc_ncmd->flags &= |
| 17195 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17196 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 17197 | num_posted++; |
| 17198 | } |
| 17199 | /* success, put on NVME buffer sgl list */ |
| 17200 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 17201 | } |
| 17202 | } |
| 17203 | |
| 17204 | /* continue until a nembed page worth of sgls */ |
| 17205 | if (post_cnt == 0) |
| 17206 | continue; |
| 17207 | |
| 17208 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17209 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 17210 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17211 | |
| 17212 | /* don't reset xirtag due to hole in xri block */ |
| 17213 | if (block_cnt == 0) |
| 17214 | last_xritag = NO_XRI; |
| 17215 | |
| 17216 | /* reset NVME buffer post count for next round of posting */ |
| 17217 | post_cnt = 0; |
| 17218 | |
| 17219 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 17220 | while (!list_empty(&blck_nblist)) { |
| 17221 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17222 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17223 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17224 | /* Post error. Mark buffer unavailable. */ |
| 17225 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17226 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17227 | /* Post success, Mark buffer available. */ |
| 17228 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17229 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 17230 | num_posted++; |
| 17231 | } |
| 17232 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 17233 | } |
| 17234 | } |
| 17235 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17236 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 17237 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17238 | return num_posted; |
| 17239 | } |
| 17240 | |
| 17241 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17242 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 17243 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 17244 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17245 | * |
| 17246 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 17247 | * valid type of frame that the LPFC driver will handle. This function will |
| 17248 | * return a zero if the frame is a valid frame or a non zero value when the |
| 17249 | * frame does not pass the check. |
| 17250 | **/ |
| 17251 | static int |
| 17252 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 17253 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 17254 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17255 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17256 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17257 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 17258 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 17259 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17260 | switch (fc_hdr->fh_r_ctl) { |
| 17261 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 17262 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 17263 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 17264 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 17265 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 17266 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 17267 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 17268 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 17269 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 17270 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 17271 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 17272 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 17273 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 17274 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 17275 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 17276 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 17277 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 17278 | case FC_RCTL_BA_PRMT: |
| 17279 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 17280 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 17281 | case FC_RCTL_P_RJT: /* port reject */ |
| 17282 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 17283 | case FC_RCTL_P_BSY: /* port busy */ |
| 17284 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 17285 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 17286 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17287 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17288 | case FC_RCTL_END: /* end */ |
| 17289 | break; |
| 17290 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 17291 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17292 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 17293 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 17294 | default: |
| 17295 | goto drop; |
| 17296 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17297 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17298 | switch (fc_hdr->fh_type) { |
| 17299 | case FC_TYPE_BLS: |
| 17300 | case FC_TYPE_ELS: |
| 17301 | case FC_TYPE_FCP: |
| 17302 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17303 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17304 | break; |
| 17305 | case FC_TYPE_IP: |
| 17306 | case FC_TYPE_ILS: |
| 17307 | default: |
| 17308 | goto drop; |
| 17309 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17310 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17311 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17312 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 17313 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17314 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 17315 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 17316 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 17317 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 17318 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17319 | return 0; |
| 17320 | drop: |
| 17321 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17322 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 17323 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17324 | return 1; |
| 17325 | } |
| 17326 | |
| 17327 | /** |
| 17328 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 17329 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17330 | * |
| 17331 | * This function processes the FC header to retrieve the VFI from the VF |
| 17332 | * header, if one exists. This function will return the VFI if one exists |
| 17333 | * or 0 if no VSAN Header exists. |
| 17334 | **/ |
| 17335 | static uint32_t |
| 17336 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 17337 | { |
| 17338 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17339 | |
| 17340 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 17341 | return 0; |
| 17342 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 17343 | } |
| 17344 | |
| 17345 | /** |
| 17346 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 17347 | * @phba: Pointer to the HBA structure to search for the vport on |
| 17348 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17349 | * @fcfi: The FC Fabric ID that the frame came from |
| 17350 | * |
| 17351 | * This function searches the @phba for a vport that matches the content of the |
| 17352 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 17353 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 17354 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 17355 | * vport. |
| 17356 | **/ |
| 17357 | static struct lpfc_vport * |
| 17358 | 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] | 17359 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17360 | { |
| 17361 | struct lpfc_vport **vports; |
| 17362 | struct lpfc_vport *vport = NULL; |
| 17363 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17364 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 17365 | if (did == Fabric_DID) |
| 17366 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17367 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 17368 | !(phba->link_state == LPFC_HBA_READY)) |
| 17369 | return phba->pport; |
| 17370 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17371 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17372 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17373 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 17374 | if (phba->fcf.fcfi == fcfi && |
| 17375 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 17376 | vports[i]->fc_myDID == did) { |
| 17377 | vport = vports[i]; |
| 17378 | break; |
| 17379 | } |
| 17380 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17381 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17382 | lpfc_destroy_vport_work_array(phba, vports); |
| 17383 | return vport; |
| 17384 | } |
| 17385 | |
| 17386 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17387 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 17388 | * @vport: The vport to work on. |
| 17389 | * |
| 17390 | * This function updates the receive sequence time stamp for this vport. The |
| 17391 | * receive sequence time stamp indicates the time that the last frame of the |
| 17392 | * the sequence that has been idle for the longest amount of time was received. |
| 17393 | * the driver uses this time stamp to indicate if any received sequences have |
| 17394 | * timed out. |
| 17395 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17396 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17397 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 17398 | { |
| 17399 | struct lpfc_dmabuf *h_buf; |
| 17400 | struct hbq_dmabuf *dmabuf = NULL; |
| 17401 | |
| 17402 | /* get the oldest sequence on the rcv list */ |
| 17403 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 17404 | struct lpfc_dmabuf, list); |
| 17405 | if (!h_buf) |
| 17406 | return; |
| 17407 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17408 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 17409 | } |
| 17410 | |
| 17411 | /** |
| 17412 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17413 | * @vport: The vport that the received sequences were sent to. |
| 17414 | * |
| 17415 | * This function cleans up all outstanding received sequences. This is called |
| 17416 | * by the driver when a link event or user action invalidates all the received |
| 17417 | * sequences. |
| 17418 | **/ |
| 17419 | void |
| 17420 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17421 | { |
| 17422 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17423 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17424 | struct hbq_dmabuf *dmabuf = NULL; |
| 17425 | |
| 17426 | /* start with the oldest sequence on the rcv list */ |
| 17427 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17428 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17429 | list_del_init(&dmabuf->hbuf.list); |
| 17430 | list_for_each_entry_safe(d_buf, dnext, |
| 17431 | &dmabuf->dbuf.list, list) { |
| 17432 | list_del_init(&d_buf->list); |
| 17433 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17434 | } |
| 17435 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17436 | } |
| 17437 | } |
| 17438 | |
| 17439 | /** |
| 17440 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17441 | * @vport: The vport that the received sequences were sent to. |
| 17442 | * |
| 17443 | * This function determines whether any received sequences have timed out by |
| 17444 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17445 | * indicates that there is at least one timed out sequence this routine will |
| 17446 | * go through the received sequences one at a time from most inactive to most |
| 17447 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17448 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17449 | * without sending an abort. |
| 17450 | **/ |
| 17451 | void |
| 17452 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17453 | { |
| 17454 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17455 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17456 | struct hbq_dmabuf *dmabuf = NULL; |
| 17457 | unsigned long timeout; |
| 17458 | int abort_count = 0; |
| 17459 | |
| 17460 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17461 | vport->rcv_buffer_time_stamp); |
| 17462 | if (list_empty(&vport->rcv_buffer_list) || |
| 17463 | time_before(jiffies, timeout)) |
| 17464 | return; |
| 17465 | /* start with the oldest sequence on the rcv list */ |
| 17466 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17467 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17468 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17469 | dmabuf->time_stamp); |
| 17470 | if (time_before(jiffies, timeout)) |
| 17471 | break; |
| 17472 | abort_count++; |
| 17473 | list_del_init(&dmabuf->hbuf.list); |
| 17474 | list_for_each_entry_safe(d_buf, dnext, |
| 17475 | &dmabuf->dbuf.list, list) { |
| 17476 | list_del_init(&d_buf->list); |
| 17477 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17478 | } |
| 17479 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17480 | } |
| 17481 | if (abort_count) |
| 17482 | lpfc_update_rcv_time_stamp(vport); |
| 17483 | } |
| 17484 | |
| 17485 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17486 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 17487 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17488 | * |
| 17489 | * This function searches through the existing incomplete sequences that have |
| 17490 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17491 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17492 | * make up that sequence. If no sequence is found that matches this frame then |
| 17493 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17494 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17495 | * the frame was linked to. |
| 17496 | **/ |
| 17497 | static struct hbq_dmabuf * |
| 17498 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17499 | { |
| 17500 | struct fc_frame_header *new_hdr; |
| 17501 | struct fc_frame_header *temp_hdr; |
| 17502 | struct lpfc_dmabuf *d_buf; |
| 17503 | struct lpfc_dmabuf *h_buf; |
| 17504 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17505 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17506 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17507 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17508 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17509 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17510 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17511 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17512 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17513 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17514 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17515 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17516 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17517 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17518 | continue; |
| 17519 | /* found a pending sequence that matches this frame */ |
| 17520 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17521 | break; |
| 17522 | } |
| 17523 | if (!seq_dmabuf) { |
| 17524 | /* |
| 17525 | * This indicates first frame received for this sequence. |
| 17526 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17527 | */ |
| 17528 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17529 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17530 | return dmabuf; |
| 17531 | } |
| 17532 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17533 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17534 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17535 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17536 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17537 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17538 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17539 | return dmabuf; |
| 17540 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17541 | /* move this sequence to the tail to indicate a young sequence */ |
| 17542 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17543 | seq_dmabuf->time_stamp = jiffies; |
| 17544 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17545 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 17546 | temp_hdr = dmabuf->hbuf.virt; |
| 17547 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17548 | return seq_dmabuf; |
| 17549 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17550 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17551 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17552 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17553 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17554 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17555 | /* |
| 17556 | * If the frame's sequence count is greater than the frame on |
| 17557 | * the list then insert the frame right after this frame |
| 17558 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17559 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17560 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17561 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17562 | found = 1; |
| 17563 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17564 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17565 | |
| 17566 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17567 | break; |
| 17568 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17569 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17570 | |
| 17571 | if (found) |
| 17572 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17573 | return NULL; |
| 17574 | } |
| 17575 | |
| 17576 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17577 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17578 | * @vport: pointer to a vitural port |
| 17579 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17580 | * |
| 17581 | * This function tries to abort from the partially assembed sequence, described |
| 17582 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17583 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17584 | * the frames from the partially assembled sequence. |
| 17585 | * |
| 17586 | * Return |
| 17587 | * true -- if there is matching partially assembled sequence present and all |
| 17588 | * the frames freed with the sequence; |
| 17589 | * false -- if there is no matching partially assembled sequence present so |
| 17590 | * nothing got aborted in the lower layer driver |
| 17591 | **/ |
| 17592 | static bool |
| 17593 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17594 | struct hbq_dmabuf *dmabuf) |
| 17595 | { |
| 17596 | struct fc_frame_header *new_hdr; |
| 17597 | struct fc_frame_header *temp_hdr; |
| 17598 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 17599 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17600 | |
| 17601 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 17602 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 17603 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 17604 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 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 | |
| 17616 | /* Free up all the frames from the partially assembled sequence */ |
| 17617 | if (seq_dmabuf) { |
| 17618 | list_for_each_entry_safe(d_buf, n_buf, |
| 17619 | &seq_dmabuf->dbuf.list, list) { |
| 17620 | list_del_init(&d_buf->list); |
| 17621 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17622 | } |
| 17623 | return true; |
| 17624 | } |
| 17625 | return false; |
| 17626 | } |
| 17627 | |
| 17628 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17629 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 17630 | * @vport: pointer to a vitural port |
| 17631 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17632 | * |
| 17633 | * This function tries to abort from the assembed sequence from upper level |
| 17634 | * protocol, described by the information from basic abbort @dmabuf. It |
| 17635 | * checks to see whether such pending context exists at upper level protocol. |
| 17636 | * If so, it shall clean up the pending context. |
| 17637 | * |
| 17638 | * Return |
| 17639 | * true -- if there is matching pending context of the sequence cleaned |
| 17640 | * at ulp; |
| 17641 | * false -- if there is no matching pending context of the sequence present |
| 17642 | * at ulp. |
| 17643 | **/ |
| 17644 | static bool |
| 17645 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17646 | { |
| 17647 | struct lpfc_hba *phba = vport->phba; |
| 17648 | int handled; |
| 17649 | |
| 17650 | /* Accepting abort at ulp with SLI4 only */ |
| 17651 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 17652 | return false; |
| 17653 | |
| 17654 | /* Register all caring upper level protocols to attend abort */ |
| 17655 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 17656 | if (handled) |
| 17657 | return true; |
| 17658 | |
| 17659 | return false; |
| 17660 | } |
| 17661 | |
| 17662 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17663 | * 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] | 17664 | * @phba: Pointer to HBA context object. |
| 17665 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 17666 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 17667 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17668 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17669 | * event. It properly releases the memory allocated to the sequence abort |
| 17670 | * accept iocb. |
| 17671 | **/ |
| 17672 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17673 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17674 | struct lpfc_iocbq *cmd_iocbq, |
| 17675 | struct lpfc_iocbq *rsp_iocbq) |
| 17676 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17677 | struct lpfc_nodelist *ndlp; |
| 17678 | |
| 17679 | if (cmd_iocbq) { |
| 17680 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 17681 | lpfc_nlp_put(ndlp); |
| 17682 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17683 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17684 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17685 | |
| 17686 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 17687 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 17688 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17689 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17690 | rsp_iocbq->iocb.ulpStatus, |
| 17691 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17692 | } |
| 17693 | |
| 17694 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17695 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17696 | * @phba: Pointer to HBA context object. |
| 17697 | * @xri: xri id in transaction. |
| 17698 | * |
| 17699 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17700 | * used by the driver. |
| 17701 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17702 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17703 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17704 | uint16_t xri) |
| 17705 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17706 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17707 | |
| 17708 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17709 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17710 | return i; |
| 17711 | } |
| 17712 | return NO_XRI; |
| 17713 | } |
| 17714 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17715 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17716 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17717 | * @phba: Pointer to HBA context object. |
| 17718 | * @fc_hdr: pointer to a FC frame header. |
| 17719 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17720 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17721 | * event after aborting the sequence handling. |
| 17722 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17723 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17724 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17725 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17726 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17727 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17728 | struct lpfc_iocbq *ctiocb = NULL; |
| 17729 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17730 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17731 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17732 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17733 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17734 | |
| 17735 | if (!lpfc_is_link_up(phba)) |
| 17736 | return; |
| 17737 | |
| 17738 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17739 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17740 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17741 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17742 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17743 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17744 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17745 | if (!ndlp) { |
| 17746 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17747 | "1268 Failed to allocate ndlp for " |
| 17748 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17749 | return; |
| 17750 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17751 | /* Put ndlp onto pport node list */ |
| 17752 | lpfc_enqueue_node(vport, ndlp); |
| 17753 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17754 | /* re-setup ndlp without removing from node list */ |
| 17755 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17756 | if (!ndlp) { |
| 17757 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17758 | "3275 Failed to active ndlp found " |
| 17759 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17760 | return; |
| 17761 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17762 | } |
| 17763 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17764 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17765 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17766 | if (!ctiocb) |
| 17767 | return; |
| 17768 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17769 | /* Extract the F_CTL field from FC_HDR */ |
| 17770 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17771 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17772 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17773 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17774 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17775 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17776 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17777 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17778 | |
| 17779 | /* Fill in the rest of iocb fields */ |
| 17780 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17781 | icmd->ulpBdeCount = 0; |
| 17782 | icmd->ulpLe = 1; |
| 17783 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17784 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17785 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17786 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17787 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17788 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17789 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17790 | ctiocb->sli4_xritag = NO_XRI; |
| 17791 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17792 | if (fctl & FC_FC_EX_CTX) |
| 17793 | /* Exchange responder sent the abort so we |
| 17794 | * own the oxid. |
| 17795 | */ |
| 17796 | xri = oxid; |
| 17797 | else |
| 17798 | xri = rxid; |
| 17799 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17800 | if (lxri != NO_XRI) |
| 17801 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17802 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17803 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17804 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17805 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17806 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17807 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17808 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17809 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17810 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17811 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17812 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17813 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17814 | } |
| 17815 | |
| 17816 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17817 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17818 | * the IOCB for a BA_RJT. |
| 17819 | */ |
| 17820 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17821 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17822 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17823 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17824 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17825 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17826 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17827 | if (fctl & FC_FC_EX_CTX) { |
| 17828 | /* ABTS sent by responder to CT exchange, construction |
| 17829 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17830 | * field and RX_ID from ABTS for RX_ID field. |
| 17831 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17832 | 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] | 17833 | } else { |
| 17834 | /* ABTS sent by initiator to CT exchange, construction |
| 17835 | * 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] | 17836 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17837 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17838 | 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] | 17839 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17840 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17841 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17842 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17843 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17844 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17845 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17846 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17847 | |
| 17848 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17849 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17850 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17851 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17852 | "xri x%x, Data x%x\n", |
| 17853 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17854 | phba->link_state); |
| 17855 | lpfc_nlp_put(ndlp); |
| 17856 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17857 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17858 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17859 | } |
| 17860 | |
| 17861 | /** |
| 17862 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17863 | * @vport: Pointer to the vport on which this sequence was received |
| 17864 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17865 | * |
| 17866 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17867 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17868 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17869 | * unsolicited receive sequence has been completely assembled and passed to |
| 17870 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17871 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17872 | * accept to accept the abort. |
| 17873 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17874 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17875 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17876 | struct hbq_dmabuf *dmabuf) |
| 17877 | { |
| 17878 | struct lpfc_hba *phba = vport->phba; |
| 17879 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17880 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17881 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17882 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17883 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17884 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17885 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17886 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17887 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17888 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17889 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17890 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17891 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17892 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17893 | if (aborted == false) |
| 17894 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17895 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17896 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17897 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17898 | if (phba->nvmet_support) { |
| 17899 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17900 | return; |
| 17901 | } |
| 17902 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17903 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17904 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17905 | } |
| 17906 | |
| 17907 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17908 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 17909 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17910 | * |
| 17911 | * This function checks the sequence, starting with the frame described by |
| 17912 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 17913 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 17914 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 17915 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 17916 | * set. 3) That there are no holes in the sequence count. The function will |
| 17917 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 17918 | **/ |
| 17919 | static int |
| 17920 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 17921 | { |
| 17922 | struct fc_frame_header *hdr; |
| 17923 | struct lpfc_dmabuf *d_buf; |
| 17924 | struct hbq_dmabuf *seq_dmabuf; |
| 17925 | uint32_t fctl; |
| 17926 | int seq_count = 0; |
| 17927 | |
| 17928 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17929 | /* make sure first fame of sequence has a sequence count of zero */ |
| 17930 | if (hdr->fh_seq_cnt != seq_count) |
| 17931 | return 0; |
| 17932 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17933 | hdr->fh_f_ctl[1] << 8 | |
| 17934 | hdr->fh_f_ctl[2]); |
| 17935 | /* If last frame of sequence we can return success. */ |
| 17936 | if (fctl & FC_FC_END_SEQ) |
| 17937 | return 1; |
| 17938 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 17939 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17940 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17941 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17942 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17943 | return 0; |
| 17944 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17945 | hdr->fh_f_ctl[1] << 8 | |
| 17946 | hdr->fh_f_ctl[2]); |
| 17947 | /* If last frame of sequence we can return success. */ |
| 17948 | if (fctl & FC_FC_END_SEQ) |
| 17949 | return 1; |
| 17950 | } |
| 17951 | return 0; |
| 17952 | } |
| 17953 | |
| 17954 | /** |
| 17955 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 17956 | * @vport: Pointer to the vport on which this sequence was received |
| 17957 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17958 | * |
| 17959 | * This function takes a sequence, described by a list of frames, and creates |
| 17960 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 17961 | * used to issue to the generic unsolicited sequence handler. This routine |
| 17962 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 17963 | * to allocate an iocbq then it throw out the received frames that were not |
| 17964 | * able to be described and return a pointer to the first iocbq. If unable to |
| 17965 | * allocate any iocbqs (including the first) this function will return NULL. |
| 17966 | **/ |
| 17967 | static struct lpfc_iocbq * |
| 17968 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 17969 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17970 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17971 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 17972 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 17973 | struct fc_frame_header *fc_hdr; |
| 17974 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17975 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17976 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17977 | |
| 17978 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17979 | /* remove from receive buffer list */ |
| 17980 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17981 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17982 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17983 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17984 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17985 | /* Get an iocbq struct to fill in. */ |
| 17986 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17987 | if (first_iocbq) { |
| 17988 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17989 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17990 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17991 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17992 | |
| 17993 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17994 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17995 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17996 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17997 | sli4_did_from_fc_hdr(fc_hdr); |
| 17998 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17999 | } else |
| 18000 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18001 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 18002 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 18003 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 18004 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 18005 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 18006 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18007 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18008 | tot_len = bf_get(lpfc_rcqe_length, |
| 18009 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18010 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18011 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 18012 | first_iocbq->context3 = NULL; |
| 18013 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18014 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 18015 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18016 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18017 | else |
| 18018 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 18019 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18020 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18021 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18022 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18023 | } |
| 18024 | iocbq = first_iocbq; |
| 18025 | /* |
| 18026 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 18027 | * of buffers for this sequence and save two buffers in each IOCBq |
| 18028 | */ |
| 18029 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 18030 | if (!iocbq) { |
| 18031 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18032 | continue; |
| 18033 | } |
| 18034 | if (!iocbq->context3) { |
| 18035 | iocbq->context3 = d_buf; |
| 18036 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18037 | /* We need to get the size out of the right CQE */ |
| 18038 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18039 | len = bf_get(lpfc_rcqe_length, |
| 18040 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18041 | pbde = (struct ulp_bde64 *) |
| 18042 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 18043 | if (len > LPFC_DATA_BUF_SIZE) |
| 18044 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 18045 | else |
| 18046 | pbde->tus.f.bdeSize = len; |
| 18047 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18048 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 18049 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18050 | } else { |
| 18051 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 18052 | if (!iocbq) { |
| 18053 | if (first_iocbq) { |
| 18054 | first_iocbq->iocb.ulpStatus = |
| 18055 | IOSTAT_FCP_RSP_ERROR; |
| 18056 | first_iocbq->iocb.un.ulpWord[4] = |
| 18057 | IOERR_NO_RESOURCES; |
| 18058 | } |
| 18059 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18060 | continue; |
| 18061 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18062 | /* We need to get the size out of the right CQE */ |
| 18063 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18064 | len = bf_get(lpfc_rcqe_length, |
| 18065 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18066 | iocbq->context2 = d_buf; |
| 18067 | iocbq->context3 = NULL; |
| 18068 | iocbq->iocb.ulpBdeCount = 1; |
| 18069 | if (len > LPFC_DATA_BUF_SIZE) |
| 18070 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 18071 | LPFC_DATA_BUF_SIZE; |
| 18072 | else |
| 18073 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 18074 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18075 | tot_len += len; |
| 18076 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 18077 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18078 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 18079 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 18080 | } |
| 18081 | } |
James Smart | 39c4f1a | 2020-01-27 16:23:01 -0800 | [diff] [blame] | 18082 | /* Free the sequence's header buffer */ |
| 18083 | if (!first_iocbq) |
| 18084 | lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf); |
| 18085 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18086 | return first_iocbq; |
| 18087 | } |
| 18088 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18089 | static void |
| 18090 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 18091 | struct hbq_dmabuf *seq_dmabuf) |
| 18092 | { |
| 18093 | struct fc_frame_header *fc_hdr; |
| 18094 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 18095 | struct lpfc_hba *phba = vport->phba; |
| 18096 | |
| 18097 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 18098 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 18099 | if (!iocbq) { |
| 18100 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18101 | "2707 Ring %d handler: Failed to allocate " |
| 18102 | "iocb Rctl x%x Type x%x received\n", |
| 18103 | LPFC_ELS_RING, |
| 18104 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 18105 | return; |
| 18106 | } |
| 18107 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18108 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18109 | iocbq, fc_hdr->fh_r_ctl, |
| 18110 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18111 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18112 | "2540 Ring %d handler: unexpected Rctl " |
| 18113 | "x%x Type x%x received\n", |
| 18114 | LPFC_ELS_RING, |
| 18115 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 18116 | |
| 18117 | /* Free iocb created in lpfc_prep_seq */ |
| 18118 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 18119 | &iocbq->list, list) { |
| 18120 | list_del_init(&curr_iocb->list); |
| 18121 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 18122 | } |
| 18123 | lpfc_sli_release_iocbq(phba, iocbq); |
| 18124 | } |
| 18125 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18126 | static void |
| 18127 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 18128 | struct lpfc_iocbq *rspiocb) |
| 18129 | { |
| 18130 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 18131 | |
| 18132 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18133 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18134 | kfree(pcmd); |
| 18135 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18136 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18137 | } |
| 18138 | |
| 18139 | static void |
| 18140 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 18141 | struct hbq_dmabuf *dmabuf) |
| 18142 | { |
| 18143 | struct fc_frame_header *fc_hdr; |
| 18144 | struct lpfc_hba *phba = vport->phba; |
| 18145 | struct lpfc_iocbq *iocbq = NULL; |
| 18146 | union lpfc_wqe *wqe; |
| 18147 | struct lpfc_dmabuf *pcmd = NULL; |
| 18148 | uint32_t frame_len; |
| 18149 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18150 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18151 | |
| 18152 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 18153 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18154 | |
| 18155 | /* Send the received frame back */ |
| 18156 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18157 | if (!iocbq) { |
| 18158 | /* Queue cq event and wakeup worker thread to process it */ |
| 18159 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 18160 | list_add_tail(&dmabuf->cq_event.list, |
| 18161 | &phba->sli4_hba.sp_queue_event); |
| 18162 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 18163 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 18164 | lpfc_worker_wake_up(phba); |
| 18165 | return; |
| 18166 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18167 | |
| 18168 | /* Allocate buffer for command payload */ |
| 18169 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 18170 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18171 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18172 | &pcmd->phys); |
| 18173 | if (!pcmd || !pcmd->virt) |
| 18174 | goto exit; |
| 18175 | |
| 18176 | INIT_LIST_HEAD(&pcmd->list); |
| 18177 | |
| 18178 | /* copyin the payload */ |
| 18179 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 18180 | |
| 18181 | /* fill in BDE's for command */ |
| 18182 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 18183 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 18184 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 18185 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 18186 | |
| 18187 | iocbq->context2 = pcmd; |
| 18188 | iocbq->vport = vport; |
| 18189 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 18190 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 18191 | |
| 18192 | /* |
| 18193 | * Setup rest of the iocb as though it were a WQE |
| 18194 | * Build the SEND_FRAME WQE |
| 18195 | */ |
| 18196 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 18197 | |
| 18198 | wqe->send_frame.frame_len = frame_len; |
| 18199 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 18200 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 18201 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 18202 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 18203 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 18204 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 18205 | |
| 18206 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 18207 | iocbq->iocb.ulpLe = 1; |
| 18208 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 18209 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 18210 | if (rc == IOCB_ERROR) |
| 18211 | goto exit; |
| 18212 | |
| 18213 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18214 | return; |
| 18215 | |
| 18216 | exit: |
| 18217 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 18218 | "2023 Unable to process MDS loopback frame\n"); |
| 18219 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18220 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18221 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 18222 | if (iocbq) |
| 18223 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18224 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18225 | } |
| 18226 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18227 | /** |
| 18228 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 18229 | * @phba: Pointer to HBA context object. |
| 18230 | * |
| 18231 | * This function is called with no lock held. This function processes all |
| 18232 | * the received buffers and gives it to upper layers when a received buffer |
| 18233 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18234 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18235 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 18236 | * appropriate receive function when the final frame in a sequence is received. |
| 18237 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18238 | void |
| 18239 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 18240 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18241 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18242 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18243 | struct fc_frame_header *fc_hdr; |
| 18244 | struct lpfc_vport *vport; |
| 18245 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18246 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18247 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18248 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18249 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 18250 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18251 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 18252 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 18253 | vport = phba->pport; |
| 18254 | /* Handle MDS Loopback frames */ |
| 18255 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 18256 | return; |
| 18257 | } |
| 18258 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18259 | /* check to see if this a valid type of frame */ |
| 18260 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 18261 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18262 | return; |
| 18263 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 18264 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18265 | if ((bf_get(lpfc_cqe_code, |
| 18266 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 18267 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 18268 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18269 | else |
| 18270 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 18271 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18272 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 18273 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 18274 | vport = phba->pport; |
| 18275 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 18276 | "2023 MDS Loopback %d bytes\n", |
| 18277 | bf_get(lpfc_rcqe_length, |
| 18278 | &dmabuf->cq_event.cqe.rcqe_cmpl)); |
| 18279 | /* Handle MDS Loopback frames */ |
| 18280 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 18281 | return; |
| 18282 | } |
| 18283 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18284 | /* d_id this frame is directed to */ |
| 18285 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 18286 | |
| 18287 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18288 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18289 | /* throw out the frame */ |
| 18290 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18291 | return; |
| 18292 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18293 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18294 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 18295 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 18296 | (did != Fabric_DID)) { |
| 18297 | /* |
| 18298 | * Throw out the frame if we are not pt2pt. |
| 18299 | * The pt2pt protocol allows for discovery frames |
| 18300 | * to be received without a registered VPI. |
| 18301 | */ |
| 18302 | if (!(vport->fc_flag & FC_PT2PT) || |
| 18303 | (phba->link_state == LPFC_HBA_READY)) { |
| 18304 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18305 | return; |
| 18306 | } |
| 18307 | } |
| 18308 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18309 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 18310 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 18311 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 18312 | return; |
| 18313 | } |
| 18314 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18315 | /* Link this frame */ |
| 18316 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 18317 | if (!seq_dmabuf) { |
| 18318 | /* unable to add frame to vport - throw it out */ |
| 18319 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18320 | return; |
| 18321 | } |
| 18322 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18323 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18324 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18325 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18326 | /* Send the complete sequence to the upper layer protocol */ |
| 18327 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18328 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18329 | |
| 18330 | /** |
| 18331 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 18332 | * @phba: pointer to lpfc hba data structure. |
| 18333 | * |
| 18334 | * This routine is invoked to post rpi header templates to the |
| 18335 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18336 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18337 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18338 | * |
| 18339 | * This routine does not require any locks. It's usage is expected |
| 18340 | * to be driver load or reset recovery when the driver is |
| 18341 | * sequential. |
| 18342 | * |
| 18343 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18344 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18345 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18346 | * When this error occurs, the driver is not guaranteed |
| 18347 | * to have any rpi regions posted to the device and |
| 18348 | * must either attempt to repost the regions or take a |
| 18349 | * fatal error. |
| 18350 | **/ |
| 18351 | int |
| 18352 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 18353 | { |
| 18354 | struct lpfc_rpi_hdr *rpi_page; |
| 18355 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18356 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18357 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18358 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18359 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18360 | goto exit; |
| 18361 | if (phba->sli4_hba.extents_in_use) |
| 18362 | return -EIO; |
| 18363 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18364 | 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] | 18365 | /* |
| 18366 | * Assign the rpi headers a physical rpi only if the driver |
| 18367 | * has not initialized those resources. A port reset only |
| 18368 | * needs the headers posted. |
| 18369 | */ |
| 18370 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 18371 | LPFC_RPI_RSRC_RDY) |
| 18372 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 18373 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18374 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 18375 | if (rc != MBX_SUCCESS) { |
| 18376 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18377 | "2008 Error %d posting all rpi " |
| 18378 | "headers\n", rc); |
| 18379 | rc = -EIO; |
| 18380 | break; |
| 18381 | } |
| 18382 | } |
| 18383 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18384 | exit: |
| 18385 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 18386 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18387 | return rc; |
| 18388 | } |
| 18389 | |
| 18390 | /** |
| 18391 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 18392 | * @phba: pointer to lpfc hba data structure. |
| 18393 | * @rpi_page: pointer to the rpi memory region. |
| 18394 | * |
| 18395 | * This routine is invoked to post a single rpi header to the |
| 18396 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 18397 | * maps up to 64 rpi context regions. |
| 18398 | * |
| 18399 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18400 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18401 | * -ENOMEM - No available memory |
| 18402 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18403 | **/ |
| 18404 | int |
| 18405 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 18406 | { |
| 18407 | LPFC_MBOXQ_t *mboxq; |
| 18408 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 18409 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18410 | uint32_t shdr_status, shdr_add_status; |
| 18411 | union lpfc_sli4_cfg_shdr *shdr; |
| 18412 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18413 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18414 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18415 | return rc; |
| 18416 | if (phba->sli4_hba.extents_in_use) |
| 18417 | return -EIO; |
| 18418 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18419 | /* The port is notified of the header region via a mailbox command. */ |
| 18420 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18421 | if (!mboxq) { |
| 18422 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18423 | "2001 Unable to allocate memory for issuing " |
| 18424 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 18425 | return -ENOMEM; |
| 18426 | } |
| 18427 | |
| 18428 | /* Post all rpi memory regions to the port. */ |
| 18429 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18430 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18431 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18432 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18433 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18434 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18435 | |
| 18436 | |
| 18437 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18438 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18439 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18440 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18441 | hdr_tmpl, rpi_page->page_count); |
| 18442 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18443 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18444 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18445 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18446 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18447 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18448 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18449 | if (rc != MBX_TIMEOUT) |
| 18450 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18451 | if (shdr_status || shdr_add_status || rc) { |
| 18452 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18453 | "2514 POST_RPI_HDR mailbox failed with " |
| 18454 | "status x%x add_status x%x, mbx status x%x\n", |
| 18455 | shdr_status, shdr_add_status, rc); |
| 18456 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18457 | } else { |
| 18458 | /* |
| 18459 | * The next_rpi stores the next logical module-64 rpi value used |
| 18460 | * to post physical rpis in subsequent rpi postings. |
| 18461 | */ |
| 18462 | spin_lock_irq(&phba->hbalock); |
| 18463 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18464 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18465 | } |
| 18466 | return rc; |
| 18467 | } |
| 18468 | |
| 18469 | /** |
| 18470 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18471 | * @phba: pointer to lpfc hba data structure. |
| 18472 | * |
| 18473 | * This routine is invoked to post rpi header templates to the |
| 18474 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18475 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18476 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18477 | * |
| 18478 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18479 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18480 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18481 | **/ |
| 18482 | int |
| 18483 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18484 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18485 | unsigned long rpi; |
| 18486 | uint16_t max_rpi, rpi_limit; |
| 18487 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18488 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18489 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18490 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18491 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18492 | * Fetch the next logical rpi. Because this index is logical, |
| 18493 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18494 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18495 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18496 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18497 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18498 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18499 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18500 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18501 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18502 | else { |
| 18503 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18504 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18505 | phba->sli4_hba.rpi_count++; |
| 18506 | } |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18507 | lpfc_printf_log(phba, KERN_INFO, |
| 18508 | LOG_NODE | LOG_DISCOVERY, |
| 18509 | "0001 Allocated rpi:x%x max:x%x lim:x%x\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18510 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18511 | |
| 18512 | /* |
| 18513 | * 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] | 18514 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18515 | */ |
| 18516 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18517 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18518 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18519 | return rpi; |
| 18520 | } |
| 18521 | |
| 18522 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18523 | * RPI header postings are not required for SLI4 ports capable of |
| 18524 | * extents. |
| 18525 | */ |
| 18526 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18527 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18528 | return rpi; |
| 18529 | } |
| 18530 | |
| 18531 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18532 | * If the driver is running low on rpi resources, allocate another |
| 18533 | * page now. Note that the next_rpi value is used because |
| 18534 | * it represents how many are actually in use whereas max_rpi notes |
| 18535 | * how many are supported max by the device. |
| 18536 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18537 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18538 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18539 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18540 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18541 | if (!rpi_hdr) { |
| 18542 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18543 | "2002 Error Could not grow rpi " |
| 18544 | "count\n"); |
| 18545 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18546 | lrpi = rpi_hdr->start_rpi; |
| 18547 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18548 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18549 | } |
| 18550 | } |
| 18551 | |
| 18552 | return rpi; |
| 18553 | } |
| 18554 | |
| 18555 | /** |
| 18556 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18557 | * @phba: pointer to lpfc hba data structure. |
| 18558 | * |
| 18559 | * This routine is invoked to release an rpi to the pool of |
| 18560 | * available rpis maintained by the driver. |
| 18561 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18562 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18563 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18564 | { |
James Smart | 7cfd563 | 2019-11-04 16:56:58 -0800 | [diff] [blame] | 18565 | /* |
| 18566 | * if the rpi value indicates a prior unreg has already |
| 18567 | * been done, skip the unreg. |
| 18568 | */ |
| 18569 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 18570 | return; |
| 18571 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18572 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18573 | phba->sli4_hba.rpi_count--; |
| 18574 | phba->sli4_hba.max_cfg_param.rpi_used--; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18575 | } else { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18576 | lpfc_printf_log(phba, KERN_INFO, |
| 18577 | LOG_NODE | LOG_DISCOVERY, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18578 | "2016 rpi %x not inuse\n", |
| 18579 | rpi); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18580 | } |
| 18581 | } |
| 18582 | |
| 18583 | /** |
| 18584 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18585 | * @phba: pointer to lpfc hba data structure. |
| 18586 | * |
| 18587 | * This routine is invoked to release an rpi to the pool of |
| 18588 | * available rpis maintained by the driver. |
| 18589 | **/ |
| 18590 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18591 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18592 | { |
| 18593 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18594 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18595 | spin_unlock_irq(&phba->hbalock); |
| 18596 | } |
| 18597 | |
| 18598 | /** |
| 18599 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 18600 | * @phba: pointer to lpfc hba data structure. |
| 18601 | * |
| 18602 | * This routine is invoked to remove the memory region that |
| 18603 | * provided rpi via a bitmask. |
| 18604 | **/ |
| 18605 | void |
| 18606 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 18607 | { |
| 18608 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18609 | kfree(phba->sli4_hba.rpi_ids); |
| 18610 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18611 | } |
| 18612 | |
| 18613 | /** |
| 18614 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 18615 | * @phba: pointer to lpfc hba data structure. |
| 18616 | * |
| 18617 | * This routine is invoked to remove the memory region that |
| 18618 | * provided rpi via a bitmask. |
| 18619 | **/ |
| 18620 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18621 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 18622 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18623 | { |
| 18624 | LPFC_MBOXQ_t *mboxq; |
| 18625 | struct lpfc_hba *phba = ndlp->phba; |
| 18626 | int rc; |
| 18627 | |
| 18628 | /* The port is notified of the header region via a mailbox command. */ |
| 18629 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18630 | if (!mboxq) |
| 18631 | return -ENOMEM; |
| 18632 | |
| 18633 | /* Post all rpi memory regions to the port. */ |
| 18634 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18635 | if (cmpl) { |
| 18636 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 18637 | mboxq->ctx_buf = arg; |
| 18638 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 18639 | } else |
| 18640 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18641 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18642 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18643 | if (rc == MBX_NOT_FINISHED) { |
| 18644 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18645 | "2010 Resume RPI Mailbox failed " |
| 18646 | "status %d, mbxStatus x%x\n", rc, |
| 18647 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 18648 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18649 | return -EIO; |
| 18650 | } |
| 18651 | return 0; |
| 18652 | } |
| 18653 | |
| 18654 | /** |
| 18655 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18656 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18657 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18658 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18659 | * |
| 18660 | * Returns: |
| 18661 | * 0 success |
| 18662 | * -Evalue otherwise |
| 18663 | **/ |
| 18664 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18665 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18666 | { |
| 18667 | LPFC_MBOXQ_t *mboxq; |
| 18668 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18669 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18670 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18671 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18672 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18673 | if (!mboxq) |
| 18674 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18675 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18676 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18677 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18678 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18679 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18680 | "2022 INIT VPI Mailbox failed " |
| 18681 | "status %d, mbxStatus x%x\n", rc, |
| 18682 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18683 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18684 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18685 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18686 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18687 | |
| 18688 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18689 | } |
| 18690 | |
| 18691 | /** |
| 18692 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 18693 | * @phba: pointer to lpfc hba data structure. |
| 18694 | * @mboxq: Pointer to mailbox object. |
| 18695 | * |
| 18696 | * This routine is invoked to manually add a single FCF record. The caller |
| 18697 | * must pass a completely initialized FCF_Record. This routine takes |
| 18698 | * care of the nonembedded mailbox operations. |
| 18699 | **/ |
| 18700 | static void |
| 18701 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 18702 | { |
| 18703 | void *virt_addr; |
| 18704 | union lpfc_sli4_cfg_shdr *shdr; |
| 18705 | uint32_t shdr_status, shdr_add_status; |
| 18706 | |
| 18707 | virt_addr = mboxq->sge_array->addr[0]; |
| 18708 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18709 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 18710 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18711 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18712 | |
| 18713 | if ((shdr_status || shdr_add_status) && |
| 18714 | (shdr_status != STATUS_FCF_IN_USE)) |
| 18715 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18716 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 18717 | "status x%x add_status x%x\n", |
| 18718 | shdr_status, shdr_add_status); |
| 18719 | |
| 18720 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18721 | } |
| 18722 | |
| 18723 | /** |
| 18724 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 18725 | * @phba: pointer to lpfc hba data structure. |
| 18726 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18727 | * |
| 18728 | * This routine is invoked to manually add a single FCF record. The caller |
| 18729 | * must pass a completely initialized FCF_Record. This routine takes |
| 18730 | * care of the nonembedded mailbox operations. |
| 18731 | **/ |
| 18732 | int |
| 18733 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18734 | { |
| 18735 | int rc = 0; |
| 18736 | LPFC_MBOXQ_t *mboxq; |
| 18737 | uint8_t *bytep; |
| 18738 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18739 | struct lpfc_mbx_sge sge; |
| 18740 | uint32_t alloc_len, req_len; |
| 18741 | uint32_t fcfindex; |
| 18742 | |
| 18743 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18744 | if (!mboxq) { |
| 18745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18746 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18747 | return -ENOMEM; |
| 18748 | } |
| 18749 | |
| 18750 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18751 | sizeof(uint32_t); |
| 18752 | |
| 18753 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18754 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18755 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18756 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18757 | if (alloc_len < req_len) { |
| 18758 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18759 | "2523 Allocated DMA memory size (x%x) is " |
| 18760 | "less than the requested DMA memory " |
| 18761 | "size (x%x)\n", alloc_len, req_len); |
| 18762 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18763 | return -ENOMEM; |
| 18764 | } |
| 18765 | |
| 18766 | /* |
| 18767 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18768 | * routine only uses a single SGE. |
| 18769 | */ |
| 18770 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18771 | virt_addr = mboxq->sge_array->addr[0]; |
| 18772 | /* |
| 18773 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18774 | * hardcoded default and gets used in nonFIP mode. |
| 18775 | */ |
| 18776 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18777 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18778 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18779 | |
| 18780 | /* |
| 18781 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18782 | * the FCoE header plus word10. The data copy needs to be endian |
| 18783 | * correct. |
| 18784 | */ |
| 18785 | bytep += sizeof(uint32_t); |
| 18786 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18787 | mboxq->vport = phba->pport; |
| 18788 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18789 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18790 | if (rc == MBX_NOT_FINISHED) { |
| 18791 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18792 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18793 | "status 0x%x\n", rc); |
| 18794 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18795 | rc = -EIO; |
| 18796 | } else |
| 18797 | rc = 0; |
| 18798 | |
| 18799 | return rc; |
| 18800 | } |
| 18801 | |
| 18802 | /** |
| 18803 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18804 | * @phba: pointer to lpfc hba data structure. |
| 18805 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18806 | * @fcf_index: FCF table entry index. |
| 18807 | * |
| 18808 | * This routine is invoked to build the driver's default FCF record. The |
| 18809 | * values used are hardcoded. This routine handles memory initialization. |
| 18810 | * |
| 18811 | **/ |
| 18812 | void |
| 18813 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18814 | struct fcf_record *fcf_record, |
| 18815 | uint16_t fcf_index) |
| 18816 | { |
| 18817 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18818 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18819 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18820 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18821 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18822 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18823 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18824 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18825 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18826 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18827 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18828 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18829 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18830 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18831 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18832 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18833 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18834 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18835 | /* Set the VLAN bit map */ |
| 18836 | if (phba->valid_vlan) { |
| 18837 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18838 | = 1 << (phba->vlan_id % 8); |
| 18839 | } |
| 18840 | } |
| 18841 | |
| 18842 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18843 | * 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] | 18844 | * @phba: pointer to lpfc hba data structure. |
| 18845 | * @fcf_index: FCF table entry offset. |
| 18846 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18847 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18848 | * record and processing it one at a time starting from the @fcf_index |
| 18849 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18850 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18851 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18852 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18853 | **/ |
| 18854 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18855 | 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] | 18856 | { |
| 18857 | int rc = 0, error; |
| 18858 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18859 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18860 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18861 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18862 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18863 | if (!mboxq) { |
| 18864 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18865 | "2000 Failed to allocate mbox for " |
| 18866 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18867 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18868 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18869 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18870 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18871 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18872 | if (rc) { |
| 18873 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18874 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18875 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18876 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18877 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18878 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18879 | |
| 18880 | spin_lock_irq(&phba->hbalock); |
| 18881 | phba->hba_flag |= FCF_TS_INPROG; |
| 18882 | spin_unlock_irq(&phba->hbalock); |
| 18883 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18884 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18885 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18886 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18887 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18888 | /* Reset eligible FCF count for new scan */ |
| 18889 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18890 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18891 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18892 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18893 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18894 | if (error) { |
| 18895 | if (mboxq) |
| 18896 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18897 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18898 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18899 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18900 | spin_unlock_irq(&phba->hbalock); |
| 18901 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18902 | return error; |
| 18903 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18904 | |
| 18905 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18906 | * 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] | 18907 | * @phba: pointer to lpfc hba data structure. |
| 18908 | * @fcf_index: FCF table entry offset. |
| 18909 | * |
| 18910 | * 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] | 18911 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18912 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18913 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18914 | * otherwise. |
| 18915 | **/ |
| 18916 | int |
| 18917 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18918 | { |
| 18919 | int rc = 0, error; |
| 18920 | LPFC_MBOXQ_t *mboxq; |
| 18921 | |
| 18922 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18923 | if (!mboxq) { |
| 18924 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18925 | "2763 Failed to allocate mbox for " |
| 18926 | "READ_FCF cmd\n"); |
| 18927 | error = -ENOMEM; |
| 18928 | goto fail_fcf_read; |
| 18929 | } |
| 18930 | /* Construct the read FCF record mailbox command */ |
| 18931 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18932 | if (rc) { |
| 18933 | error = -EINVAL; |
| 18934 | goto fail_fcf_read; |
| 18935 | } |
| 18936 | /* Issue the mailbox command asynchronously */ |
| 18937 | mboxq->vport = phba->pport; |
| 18938 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 18939 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18940 | if (rc == MBX_NOT_FINISHED) |
| 18941 | error = -EIO; |
| 18942 | else |
| 18943 | error = 0; |
| 18944 | |
| 18945 | fail_fcf_read: |
| 18946 | if (error && mboxq) |
| 18947 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18948 | return error; |
| 18949 | } |
| 18950 | |
| 18951 | /** |
| 18952 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 18953 | * @phba: pointer to lpfc hba data structure. |
| 18954 | * @fcf_index: FCF table entry offset. |
| 18955 | * |
| 18956 | * 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] | 18957 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18958 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18959 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18960 | * otherwise. |
| 18961 | **/ |
| 18962 | int |
| 18963 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18964 | { |
| 18965 | int rc = 0, error; |
| 18966 | LPFC_MBOXQ_t *mboxq; |
| 18967 | |
| 18968 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18969 | if (!mboxq) { |
| 18970 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18971 | "2758 Failed to allocate mbox for " |
| 18972 | "READ_FCF cmd\n"); |
| 18973 | error = -ENOMEM; |
| 18974 | goto fail_fcf_read; |
| 18975 | } |
| 18976 | /* Construct the read FCF record mailbox command */ |
| 18977 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18978 | if (rc) { |
| 18979 | error = -EINVAL; |
| 18980 | goto fail_fcf_read; |
| 18981 | } |
| 18982 | /* Issue the mailbox command asynchronously */ |
| 18983 | mboxq->vport = phba->pport; |
| 18984 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 18985 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18986 | if (rc == MBX_NOT_FINISHED) |
| 18987 | error = -EIO; |
| 18988 | else |
| 18989 | error = 0; |
| 18990 | |
| 18991 | fail_fcf_read: |
| 18992 | if (error && mboxq) |
| 18993 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18994 | return error; |
| 18995 | } |
| 18996 | |
| 18997 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18998 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18999 | * phba pointer to the lpfc_hba struct for this port. |
| 19000 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 19001 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 19002 | * rr_bmask based on their priority level. Starting from the highest priority |
| 19003 | * to the lowest. The most likely FCF candidate will be in the highest |
| 19004 | * priority group. When this routine is called it searches the fcf_pri list for |
| 19005 | * next lowest priority group and repopulates the rr_bmask with only those |
| 19006 | * fcf_indexes. |
| 19007 | * returns: |
| 19008 | * 1=success 0=failure |
| 19009 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 19010 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19011 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 19012 | { |
| 19013 | uint16_t next_fcf_pri; |
| 19014 | uint16_t last_index; |
| 19015 | struct lpfc_fcf_pri *fcf_pri; |
| 19016 | int rc; |
| 19017 | int ret = 0; |
| 19018 | |
| 19019 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 19020 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19021 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 19022 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 19023 | |
| 19024 | /* Verify the priority list has 2 or more entries */ |
| 19025 | spin_lock_irq(&phba->hbalock); |
| 19026 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 19027 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 19028 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19029 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 19030 | "3061 Last IDX %d\n", last_index); |
| 19031 | return 0; /* Empty rr list */ |
| 19032 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 19033 | spin_unlock_irq(&phba->hbalock); |
| 19034 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19035 | next_fcf_pri = 0; |
| 19036 | /* |
| 19037 | * Clear the rr_bmask and set all of the bits that are at this |
| 19038 | * priority. |
| 19039 | */ |
| 19040 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 19041 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 19042 | spin_lock_irq(&phba->hbalock); |
| 19043 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 19044 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 19045 | continue; |
| 19046 | /* |
| 19047 | * the 1st priority that has not FLOGI failed |
| 19048 | * will be the highest. |
| 19049 | */ |
| 19050 | if (!next_fcf_pri) |
| 19051 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 19052 | spin_unlock_irq(&phba->hbalock); |
| 19053 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 19054 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 19055 | fcf_pri->fcf_rec.fcf_index); |
| 19056 | if (rc) |
| 19057 | return 0; |
| 19058 | } |
| 19059 | spin_lock_irq(&phba->hbalock); |
| 19060 | } |
| 19061 | /* |
| 19062 | * if next_fcf_pri was not set above and the list is not empty then |
| 19063 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 19064 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19065 | */ |
| 19066 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 19067 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 19068 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 19069 | /* |
| 19070 | * the 1st priority that has not FLOGI failed |
| 19071 | * will be the highest. |
| 19072 | */ |
| 19073 | if (!next_fcf_pri) |
| 19074 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 19075 | spin_unlock_irq(&phba->hbalock); |
| 19076 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 19077 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 19078 | fcf_pri->fcf_rec.fcf_index); |
| 19079 | if (rc) |
| 19080 | return 0; |
| 19081 | } |
| 19082 | spin_lock_irq(&phba->hbalock); |
| 19083 | } |
| 19084 | } else |
| 19085 | ret = 1; |
| 19086 | spin_unlock_irq(&phba->hbalock); |
| 19087 | |
| 19088 | return ret; |
| 19089 | } |
| 19090 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19091 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 19092 | * @phba: pointer to lpfc hba data structure. |
| 19093 | * |
| 19094 | * This routine is to get the next eligible FCF record index in a round |
| 19095 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19096 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19097 | * shall be returned, otherwise, the next eligible FCF record's index |
| 19098 | * shall be returned. |
| 19099 | **/ |
| 19100 | uint16_t |
| 19101 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 19102 | { |
| 19103 | uint16_t next_fcf_index; |
| 19104 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19105 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19106 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19107 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 19108 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19109 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19110 | /* Determine the next fcf index to check */ |
| 19111 | 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] | 19112 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 19113 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19114 | next_fcf_index); |
| 19115 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19116 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19117 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19118 | /* |
| 19119 | * If we have wrapped then we need to clear the bits that |
| 19120 | * have been tested so that we can detect when we should |
| 19121 | * change the priority level. |
| 19122 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19123 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 19124 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19125 | } |
| 19126 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19127 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19128 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19129 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 19130 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 19131 | /* |
| 19132 | * If next fcf index is not found check if there are lower |
| 19133 | * Priority level fcf's in the fcf_priority list. |
| 19134 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 19135 | * at that level and continue the selection process. |
| 19136 | */ |
| 19137 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19138 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19139 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 19140 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 19141 | |
| 19142 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19143 | } |
| 19144 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19145 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 19146 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19147 | LPFC_FCF_FLOGI_FAILED) { |
| 19148 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 19149 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 19150 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19151 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19152 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19153 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19154 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19155 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 19156 | next_fcf_index); |
| 19157 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19158 | return next_fcf_index; |
| 19159 | } |
| 19160 | |
| 19161 | /** |
| 19162 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 19163 | * @phba: pointer to lpfc hba data structure. |
| 19164 | * |
| 19165 | * 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] | 19166 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19167 | * does not go beyond the range of the driver allocated bmask dimension |
| 19168 | * before setting the bit. |
| 19169 | * |
| 19170 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 19171 | * -EINVAL. |
| 19172 | **/ |
| 19173 | int |
| 19174 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19175 | { |
| 19176 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19177 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19178 | "2610 FCF (x%x) reached driver's book " |
| 19179 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19180 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19181 | return -EINVAL; |
| 19182 | } |
| 19183 | /* Set the eligible FCF record index bmask */ |
| 19184 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 19185 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19186 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19187 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19188 | "bmask\n", fcf_index); |
| 19189 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19190 | return 0; |
| 19191 | } |
| 19192 | |
| 19193 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19194 | * 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] | 19195 | * @phba: pointer to lpfc hba data structure. |
| 19196 | * |
| 19197 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19198 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19199 | * does not go beyond the range of the driver allocated bmask dimension |
| 19200 | * before clearing the bit. |
| 19201 | **/ |
| 19202 | void |
| 19203 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19204 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 19205 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19206 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19207 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19208 | "2762 FCF (x%x) reached driver's book " |
| 19209 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19210 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19211 | return; |
| 19212 | } |
| 19213 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19214 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 19215 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 19216 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19217 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 19218 | list_del_init(&fcf_pri->list); |
| 19219 | break; |
| 19220 | } |
| 19221 | } |
| 19222 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19223 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19224 | |
| 19225 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19226 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19227 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19228 | } |
| 19229 | |
| 19230 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19231 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 19232 | * @phba: pointer to lpfc hba data structure. |
| 19233 | * |
| 19234 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 19235 | * command. If the mailbox command returned failure, it will try to stop the |
| 19236 | * FCF rediscover wait timer. |
| 19237 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 19238 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19239 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 19240 | { |
| 19241 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 19242 | uint32_t shdr_status, shdr_add_status; |
| 19243 | |
| 19244 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19245 | |
| 19246 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19247 | &redisc_fcf->header.cfg_shdr.response); |
| 19248 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19249 | &redisc_fcf->header.cfg_shdr.response); |
| 19250 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19251 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19252 | "2746 Requesting for FCF rediscovery failed " |
| 19253 | "status x%x add_status x%x\n", |
| 19254 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19255 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19256 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19257 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19258 | spin_unlock_irq(&phba->hbalock); |
| 19259 | /* |
| 19260 | * CVL event triggered FCF rediscover request failed, |
| 19261 | * last resort to re-try current registered FCF entry. |
| 19262 | */ |
| 19263 | lpfc_retry_pport_discovery(phba); |
| 19264 | } else { |
| 19265 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19266 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19267 | spin_unlock_irq(&phba->hbalock); |
| 19268 | /* |
| 19269 | * DEAD FCF event triggered FCF rediscover request |
| 19270 | * failed, last resort to fail over as a link down |
| 19271 | * to FCF registration. |
| 19272 | */ |
| 19273 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 19274 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19275 | } else { |
| 19276 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19277 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19278 | /* |
| 19279 | * Start FCF rediscovery wait timer for pending FCF |
| 19280 | * before rescan FCF record table. |
| 19281 | */ |
| 19282 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19283 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19284 | |
| 19285 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19286 | } |
| 19287 | |
| 19288 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19289 | * 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] | 19290 | * @phba: pointer to lpfc hba data structure. |
| 19291 | * |
| 19292 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 19293 | * by the port. |
| 19294 | **/ |
| 19295 | int |
| 19296 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 19297 | { |
| 19298 | LPFC_MBOXQ_t *mbox; |
| 19299 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 19300 | int rc, length; |
| 19301 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19302 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 19303 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 19304 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19305 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19306 | if (!mbox) { |
| 19307 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19308 | "2745 Failed to allocate mbox for " |
| 19309 | "requesting FCF rediscover.\n"); |
| 19310 | return -ENOMEM; |
| 19311 | } |
| 19312 | |
| 19313 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 19314 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 19315 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 19316 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 19317 | length, LPFC_SLI4_MBX_EMBED); |
| 19318 | |
| 19319 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19320 | /* Set count to 0 for invalidating the entire FCF database */ |
| 19321 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 19322 | |
| 19323 | /* Issue the mailbox command asynchronously */ |
| 19324 | mbox->vport = phba->pport; |
| 19325 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 19326 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 19327 | |
| 19328 | if (rc == MBX_NOT_FINISHED) { |
| 19329 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19330 | return -EIO; |
| 19331 | } |
| 19332 | return 0; |
| 19333 | } |
| 19334 | |
| 19335 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19336 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 19337 | * @phba: pointer to lpfc hba data structure. |
| 19338 | * |
| 19339 | * This function is the failover routine as a last resort to the FCF DEAD |
| 19340 | * event when driver failed to perform fast FCF failover. |
| 19341 | **/ |
| 19342 | void |
| 19343 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 19344 | { |
| 19345 | uint32_t link_state; |
| 19346 | |
| 19347 | /* |
| 19348 | * Last resort as FCF DEAD event failover will treat this as |
| 19349 | * a link down, but save the link state because we don't want |
| 19350 | * it to be changed to Link Down unless it is already down. |
| 19351 | */ |
| 19352 | link_state = phba->link_state; |
| 19353 | lpfc_linkdown(phba); |
| 19354 | phba->link_state = link_state; |
| 19355 | |
| 19356 | /* Unregister FCF if no devices connected to it */ |
| 19357 | lpfc_unregister_unused_fcf(phba); |
| 19358 | } |
| 19359 | |
| 19360 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19361 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19362 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19363 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19364 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19365 | * This function gets SLI3 port configure region 23 data through memory dump |
| 19366 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19367 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19368 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19369 | static uint32_t |
| 19370 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19371 | { |
| 19372 | LPFC_MBOXQ_t *pmb = NULL; |
| 19373 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19374 | uint32_t offset = 0; |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 19375 | int i, rc; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19376 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19377 | if (!rgn23_data) |
| 19378 | return 0; |
| 19379 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19380 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19381 | if (!pmb) { |
| 19382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19383 | "2600 failed to allocate mailbox memory\n"); |
| 19384 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19385 | } |
| 19386 | mb = &pmb->u.mb; |
| 19387 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19388 | do { |
| 19389 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 19390 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 19391 | |
| 19392 | if (rc != MBX_SUCCESS) { |
| 19393 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19394 | "2601 failed to read config " |
| 19395 | "region 23, rc 0x%x Status 0x%x\n", |
| 19396 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19397 | mb->un.varDmp.word_cnt = 0; |
| 19398 | } |
| 19399 | /* |
| 19400 | * dump mem may return a zero when finished or we got a |
| 19401 | * mailbox error, either way we are done. |
| 19402 | */ |
| 19403 | if (mb->un.varDmp.word_cnt == 0) |
| 19404 | break; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19405 | |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 19406 | i = mb->un.varDmp.word_cnt * sizeof(uint32_t); |
| 19407 | if (offset + i > DMP_RGN23_SIZE) |
| 19408 | i = DMP_RGN23_SIZE - offset; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19409 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 19410 | rgn23_data + offset, i); |
| 19411 | offset += i; |
| 19412 | } while (offset < DMP_RGN23_SIZE); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19413 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19414 | mempool_free(pmb, phba->mbox_mem_pool); |
| 19415 | return offset; |
| 19416 | } |
| 19417 | |
| 19418 | /** |
| 19419 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 19420 | * @phba: pointer to lpfc hba data structure. |
| 19421 | * @rgn23_data: pointer to configure region 23 data. |
| 19422 | * |
| 19423 | * This function gets SLI4 port configure region 23 data through memory dump |
| 19424 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19425 | * will be returned, otherwise, 0 will be returned. |
| 19426 | **/ |
| 19427 | static uint32_t |
| 19428 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 19429 | { |
| 19430 | LPFC_MBOXQ_t *mboxq = NULL; |
| 19431 | struct lpfc_dmabuf *mp = NULL; |
| 19432 | struct lpfc_mqe *mqe; |
| 19433 | uint32_t data_length = 0; |
| 19434 | int rc; |
| 19435 | |
| 19436 | if (!rgn23_data) |
| 19437 | return 0; |
| 19438 | |
| 19439 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19440 | if (!mboxq) { |
| 19441 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19442 | "3105 failed to allocate mailbox memory\n"); |
| 19443 | return 0; |
| 19444 | } |
| 19445 | |
| 19446 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19447 | goto out; |
| 19448 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19449 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19450 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19451 | if (rc) |
| 19452 | goto out; |
| 19453 | data_length = mqe->un.mb_words[5]; |
| 19454 | if (data_length == 0) |
| 19455 | goto out; |
| 19456 | if (data_length > DMP_RGN23_SIZE) { |
| 19457 | data_length = 0; |
| 19458 | goto out; |
| 19459 | } |
| 19460 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19461 | out: |
| 19462 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19463 | if (mp) { |
| 19464 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19465 | kfree(mp); |
| 19466 | } |
| 19467 | return data_length; |
| 19468 | } |
| 19469 | |
| 19470 | /** |
| 19471 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19472 | * @phba: pointer to lpfc hba data structure. |
| 19473 | * |
| 19474 | * This function read region 23 and parse TLV for port status to |
| 19475 | * decide if the user disaled the port. If the TLV indicates the |
| 19476 | * port is disabled, the hba_flag is set accordingly. |
| 19477 | **/ |
| 19478 | void |
| 19479 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19480 | { |
| 19481 | uint8_t *rgn23_data = NULL; |
| 19482 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19483 | uint32_t offset = 0; |
| 19484 | |
| 19485 | /* Get adapter Region 23 data */ |
| 19486 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19487 | if (!rgn23_data) |
| 19488 | goto out; |
| 19489 | |
| 19490 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19491 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19492 | else { |
| 19493 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19494 | &phba->sli4_hba.sli_intf); |
| 19495 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19496 | goto out; |
| 19497 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19498 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19499 | |
| 19500 | if (!data_size) |
| 19501 | goto out; |
| 19502 | |
| 19503 | /* Check the region signature first */ |
| 19504 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 19505 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19506 | "2619 Config region 23 has bad signature\n"); |
| 19507 | goto out; |
| 19508 | } |
| 19509 | offset += 4; |
| 19510 | |
| 19511 | /* Check the data structure version */ |
| 19512 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 19513 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19514 | "2620 Config region 23 has bad version\n"); |
| 19515 | goto out; |
| 19516 | } |
| 19517 | offset += 4; |
| 19518 | |
| 19519 | /* Parse TLV entries in the region */ |
| 19520 | while (offset < data_size) { |
| 19521 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19522 | break; |
| 19523 | /* |
| 19524 | * If the TLV is not driver specific TLV or driver id is |
| 19525 | * not linux driver id, skip the record. |
| 19526 | */ |
| 19527 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19528 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19529 | (rgn23_data[offset + 3] != 0)) { |
| 19530 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19531 | continue; |
| 19532 | } |
| 19533 | |
| 19534 | /* Driver found a driver specific TLV in the config region */ |
| 19535 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19536 | offset += 4; |
| 19537 | tlv_offset = 0; |
| 19538 | |
| 19539 | /* |
| 19540 | * Search for configured port state sub-TLV. |
| 19541 | */ |
| 19542 | while ((offset < data_size) && |
| 19543 | (tlv_offset < sub_tlv_len)) { |
| 19544 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19545 | offset += 4; |
| 19546 | tlv_offset += 4; |
| 19547 | break; |
| 19548 | } |
| 19549 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19550 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19551 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19552 | continue; |
| 19553 | } |
| 19554 | |
| 19555 | /* This HBA contains PORT_STE configured */ |
| 19556 | if (!rgn23_data[offset + 2]) |
| 19557 | phba->hba_flag |= LINK_DISABLED; |
| 19558 | |
| 19559 | goto out; |
| 19560 | } |
| 19561 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19562 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19563 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19564 | kfree(rgn23_data); |
| 19565 | return; |
| 19566 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19567 | |
| 19568 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19569 | * lpfc_wr_object - write an object to the firmware |
| 19570 | * @phba: HBA structure that indicates port to create a queue on. |
| 19571 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19572 | * @size: the total byte value of the objects to write to the port. |
| 19573 | * @offset: the current offset to be used to start the transfer. |
| 19574 | * |
| 19575 | * This routine will create a wr_object mailbox command to send to the port. |
| 19576 | * the mailbox command will be constructed using the dma buffers described in |
| 19577 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19578 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19579 | * used to indicate the starting offset of the transfer and will also return |
| 19580 | * the offset after the write object mailbox has completed. @size is used to |
| 19581 | * determine the end of the object and whether the eof bit should be set. |
| 19582 | * |
| 19583 | * Return 0 is successful and offset will contain the the new offset to use |
| 19584 | * for the next write. |
| 19585 | * Return negative value for error cases. |
| 19586 | **/ |
| 19587 | int |
| 19588 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 19589 | uint32_t size, uint32_t *offset) |
| 19590 | { |
| 19591 | struct lpfc_mbx_wr_object *wr_object; |
| 19592 | LPFC_MBOXQ_t *mbox; |
| 19593 | int rc = 0, i = 0; |
James Smart | f3d0a8a | 2019-12-18 15:58:01 -0800 | [diff] [blame] | 19594 | uint32_t shdr_status, shdr_add_status, shdr_change_status, shdr_csf; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19595 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19596 | struct lpfc_dmabuf *dmabuf; |
| 19597 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19598 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19599 | |
| 19600 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19601 | if (!mbox) |
| 19602 | return -ENOMEM; |
| 19603 | |
| 19604 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 19605 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 19606 | sizeof(struct lpfc_mbx_wr_object) - |
| 19607 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 19608 | |
| 19609 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 19610 | wr_object->u.request.write_offset = *offset; |
| 19611 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 19612 | wr_object->u.request.object_name[0] = |
| 19613 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 19614 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 19615 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 19616 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 19617 | break; |
| 19618 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 19619 | wr_object->u.request.bde[i].addrHigh = |
| 19620 | putPaddrHigh(dmabuf->phys); |
| 19621 | if (written + SLI4_PAGE_SIZE >= size) { |
| 19622 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19623 | (size - written); |
| 19624 | written += (size - written); |
| 19625 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19626 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 19627 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19628 | } else { |
| 19629 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19630 | SLI4_PAGE_SIZE; |
| 19631 | written += SLI4_PAGE_SIZE; |
| 19632 | } |
| 19633 | i++; |
| 19634 | } |
| 19635 | wr_object->u.request.bde_count = i; |
| 19636 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 19637 | if (!phba->sli4_hba.intr_enable) |
| 19638 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 19639 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19640 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19641 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 19642 | } |
| 19643 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19644 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19645 | &wr_object->header.cfg_shdr.response); |
| 19646 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19647 | &wr_object->header.cfg_shdr.response); |
| 19648 | if (check_change_status) { |
| 19649 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 19650 | &wr_object->u.response); |
James Smart | f3d0a8a | 2019-12-18 15:58:01 -0800 | [diff] [blame] | 19651 | |
| 19652 | if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET || |
| 19653 | shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) { |
| 19654 | shdr_csf = bf_get(lpfc_wr_object_csf, |
| 19655 | &wr_object->u.response); |
| 19656 | if (shdr_csf) |
| 19657 | shdr_change_status = |
| 19658 | LPFC_CHANGE_STATUS_PCI_RESET; |
| 19659 | } |
| 19660 | |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19661 | switch (shdr_change_status) { |
| 19662 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 19663 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19664 | "3198 Firmware write complete: System " |
| 19665 | "reboot required to instantiate\n"); |
| 19666 | break; |
| 19667 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 19668 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19669 | "3199 Firmware write complete: Firmware" |
| 19670 | " reset required to instantiate\n"); |
| 19671 | break; |
| 19672 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 19673 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19674 | "3200 Firmware write complete: Port " |
| 19675 | "Migration or PCI Reset required to " |
| 19676 | "instantiate\n"); |
| 19677 | break; |
| 19678 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 19679 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19680 | "3201 Firmware write complete: PCI " |
| 19681 | "Reset required to instantiate\n"); |
| 19682 | break; |
| 19683 | default: |
| 19684 | break; |
| 19685 | } |
| 19686 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19687 | if (rc != MBX_TIMEOUT) |
| 19688 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19689 | if (shdr_status || shdr_add_status || rc) { |
| 19690 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19691 | "3025 Write Object mailbox failed with " |
| 19692 | "status x%x add_status x%x, mbx status x%x\n", |
| 19693 | shdr_status, shdr_add_status, rc); |
| 19694 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 19695 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19696 | } else |
| 19697 | *offset += wr_object->u.response.actual_write_length; |
| 19698 | return rc; |
| 19699 | } |
| 19700 | |
| 19701 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19702 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 19703 | * @vport: pointer to vport data structure. |
| 19704 | * |
| 19705 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 19706 | * and REG_VPI mailbox commands associated with the vport. This function |
| 19707 | * is called when driver want to restart discovery of the vport due to |
| 19708 | * a Clear Virtual Link event. |
| 19709 | **/ |
| 19710 | void |
| 19711 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 19712 | { |
| 19713 | struct lpfc_hba *phba = vport->phba; |
| 19714 | LPFC_MBOXQ_t *mb, *nextmb; |
| 19715 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19716 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19717 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19718 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19719 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19720 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19721 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19722 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19723 | spin_lock_irq(&phba->hbalock); |
| 19724 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 19725 | if (mb->vport != vport) |
| 19726 | continue; |
| 19727 | |
| 19728 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19729 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19730 | continue; |
| 19731 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19732 | list_del(&mb->list); |
| 19733 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 19734 | } |
| 19735 | /* Clean up active mailbox command with the vport */ |
| 19736 | mb = phba->sli.mbox_active; |
| 19737 | if (mb && (mb->vport == vport)) { |
| 19738 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 19739 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 19740 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19741 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19742 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19743 | /* Put reference count for delayed processing */ |
| 19744 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 19745 | /* Unregister the RPI when mailbox complete */ |
| 19746 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19747 | } |
| 19748 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19749 | /* Cleanup any mailbox completions which are not yet processed */ |
| 19750 | do { |
| 19751 | restart_loop = 0; |
| 19752 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 19753 | /* |
| 19754 | * If this mailox is already processed or it is |
| 19755 | * for another vport ignore it. |
| 19756 | */ |
| 19757 | if ((mb->vport != vport) || |
| 19758 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 19759 | continue; |
| 19760 | |
| 19761 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19762 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19763 | continue; |
| 19764 | |
| 19765 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19766 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19767 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19768 | /* Unregister the RPI when mailbox complete */ |
| 19769 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19770 | restart_loop = 1; |
| 19771 | spin_unlock_irq(&phba->hbalock); |
| 19772 | spin_lock(shost->host_lock); |
| 19773 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19774 | spin_unlock(shost->host_lock); |
| 19775 | spin_lock_irq(&phba->hbalock); |
| 19776 | break; |
| 19777 | } |
| 19778 | } |
| 19779 | } while (restart_loop); |
| 19780 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19781 | spin_unlock_irq(&phba->hbalock); |
| 19782 | |
| 19783 | /* Release the cleaned-up mailbox commands */ |
| 19784 | while (!list_empty(&mbox_cmd_list)) { |
| 19785 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19786 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19787 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19788 | if (mp) { |
| 19789 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19790 | kfree(mp); |
| 19791 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19792 | mb->ctx_buf = NULL; |
| 19793 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 19794 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19795 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19796 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19797 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19798 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19799 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19800 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19801 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19802 | mempool_free(mb, phba->mbox_mem_pool); |
| 19803 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19804 | |
| 19805 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19806 | if (act_mbx_ndlp) { |
| 19807 | spin_lock(shost->host_lock); |
| 19808 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19809 | spin_unlock(shost->host_lock); |
| 19810 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19811 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19812 | } |
| 19813 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19814 | /** |
| 19815 | * lpfc_drain_txq - Drain the txq |
| 19816 | * @phba: Pointer to HBA context object. |
| 19817 | * |
| 19818 | * This function attempt to submit IOCBs on the txq |
| 19819 | * to the adapter. For SLI4 adapters, the txq contains |
| 19820 | * ELS IOCBs that have been deferred because the there |
| 19821 | * are no SGLs. This congestion can occur with large |
| 19822 | * vport counts during node discovery. |
| 19823 | **/ |
| 19824 | |
| 19825 | uint32_t |
| 19826 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19827 | { |
| 19828 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19829 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19830 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19831 | unsigned long iflags = 0; |
| 19832 | char *fail_msg = NULL; |
| 19833 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19834 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19835 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19836 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19837 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19838 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19839 | /* MDS WQE are posted only to first WQ*/ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19840 | wq = phba->sli4_hba.hdwq[0].io_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19841 | if (unlikely(!wq)) |
| 19842 | return 0; |
| 19843 | pring = wq->pring; |
| 19844 | } else { |
| 19845 | wq = phba->sli4_hba.els_wq; |
| 19846 | if (unlikely(!wq)) |
| 19847 | return 0; |
| 19848 | pring = lpfc_phba_elsring(phba); |
| 19849 | } |
| 19850 | |
| 19851 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19852 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19853 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19854 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19855 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19856 | txq_cnt++; |
| 19857 | } |
| 19858 | |
| 19859 | if (txq_cnt > pring->txq_max) |
| 19860 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19861 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19862 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19863 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19864 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19865 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19866 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19867 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19868 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19869 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19870 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19871 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19872 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19873 | break; |
| 19874 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19875 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19876 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19877 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19878 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19879 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19880 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19881 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19882 | |
| 19883 | /* The xri and iocb resources secured, |
| 19884 | * attempt to issue request |
| 19885 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19886 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19887 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19888 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19889 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19890 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19891 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19892 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19893 | fail_msg = " - Wq is full"; |
| 19894 | else |
| 19895 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19896 | |
| 19897 | if (fail_msg) { |
| 19898 | /* Failed means we can't issue and need to cancel */ |
| 19899 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19900 | "2822 IOCB failed %s iotag 0x%x " |
| 19901 | "xri 0x%x\n", |
| 19902 | fail_msg, |
| 19903 | piocbq->iotag, piocbq->sli4_xritag); |
| 19904 | list_add_tail(&piocbq->list, &completions); |
| 19905 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19906 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19907 | } |
| 19908 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19909 | /* Cancel all the IOCBs that cannot be issued */ |
| 19910 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 19911 | IOERR_SLI_ABORTED); |
| 19912 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19913 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19914 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19915 | |
| 19916 | /** |
| 19917 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 19918 | * @phba: Pointer to HBA context object. |
| 19919 | * @pwqe: Pointer to command WQE. |
| 19920 | * @sglq: Pointer to the scatter gather queue object. |
| 19921 | * |
| 19922 | * This routine converts the bpl or bde that is in the WQE |
| 19923 | * to a sgl list for the sli4 hardware. The physical address |
| 19924 | * of the bpl/bde is converted back to a virtual address. |
| 19925 | * If the WQE contains a BPL then the list of BDE's is |
| 19926 | * converted to sli4_sge's. If the WQE contains a single |
| 19927 | * BDE then it is converted to a single sli_sge. |
| 19928 | * The WQE is still in cpu endianness so the contents of |
| 19929 | * the bpl can be used without byte swapping. |
| 19930 | * |
| 19931 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 19932 | */ |
| 19933 | static uint16_t |
| 19934 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 19935 | struct lpfc_sglq *sglq) |
| 19936 | { |
| 19937 | uint16_t xritag = NO_XRI; |
| 19938 | struct ulp_bde64 *bpl = NULL; |
| 19939 | struct ulp_bde64 bde; |
| 19940 | struct sli4_sge *sgl = NULL; |
| 19941 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19942 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19943 | int numBdes = 0; |
| 19944 | int i = 0; |
| 19945 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 19946 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 19947 | uint32_t cmd; |
| 19948 | |
| 19949 | if (!pwqeq || !sglq) |
| 19950 | return xritag; |
| 19951 | |
| 19952 | sgl = (struct sli4_sge *)sglq->sgl; |
| 19953 | wqe = &pwqeq->wqe; |
| 19954 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 19955 | |
| 19956 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 19957 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 19958 | return sglq->sli4_xritag; |
| 19959 | numBdes = pwqeq->rsvd2; |
| 19960 | if (numBdes) { |
| 19961 | /* The addrHigh and addrLow fields within the WQE |
| 19962 | * have not been byteswapped yet so there is no |
| 19963 | * need to swap them back. |
| 19964 | */ |
| 19965 | if (pwqeq->context3) |
| 19966 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 19967 | else |
| 19968 | return xritag; |
| 19969 | |
| 19970 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 19971 | if (!bpl) |
| 19972 | return xritag; |
| 19973 | |
| 19974 | for (i = 0; i < numBdes; i++) { |
| 19975 | /* Should already be byte swapped. */ |
| 19976 | sgl->addr_hi = bpl->addrHigh; |
| 19977 | sgl->addr_lo = bpl->addrLow; |
| 19978 | |
| 19979 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19980 | if ((i+1) == numBdes) |
| 19981 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19982 | else |
| 19983 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 19984 | /* swap the size field back to the cpu so we |
| 19985 | * can assign it to the sgl. |
| 19986 | */ |
| 19987 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 19988 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 19989 | /* The offsets in the sgl need to be accumulated |
| 19990 | * separately for the request and reply lists. |
| 19991 | * The request is always first, the reply follows. |
| 19992 | */ |
| 19993 | switch (cmd) { |
| 19994 | case CMD_GEN_REQUEST64_WQE: |
| 19995 | /* add up the reply sg entries */ |
| 19996 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 19997 | inbound++; |
| 19998 | /* first inbound? reset the offset */ |
| 19999 | if (inbound == 1) |
| 20000 | offset = 0; |
| 20001 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 20002 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20003 | LPFC_SGE_TYPE_DATA); |
| 20004 | offset += bde.tus.f.bdeSize; |
| 20005 | break; |
| 20006 | case CMD_FCP_TRSP64_WQE: |
| 20007 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 20008 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20009 | LPFC_SGE_TYPE_DATA); |
| 20010 | break; |
| 20011 | case CMD_FCP_TSEND64_WQE: |
| 20012 | case CMD_FCP_TRECEIVE64_WQE: |
| 20013 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20014 | bpl->tus.f.bdeFlags); |
| 20015 | if (i < 3) |
| 20016 | offset = 0; |
| 20017 | else |
| 20018 | offset += bde.tus.f.bdeSize; |
| 20019 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 20020 | break; |
| 20021 | } |
| 20022 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 20023 | bpl++; |
| 20024 | sgl++; |
| 20025 | } |
| 20026 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 20027 | /* The addrHigh and addrLow fields of the BDE have not |
| 20028 | * been byteswapped yet so they need to be swapped |
| 20029 | * before putting them in the sgl. |
| 20030 | */ |
| 20031 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 20032 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 20033 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 20034 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 20035 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 20036 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 20037 | } |
| 20038 | return sglq->sli4_xritag; |
| 20039 | } |
| 20040 | |
| 20041 | /** |
| 20042 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 20043 | * @phba: Pointer to HBA context object. |
| 20044 | * @ring_number: Base sli ring number |
| 20045 | * @pwqe: Pointer to command WQE. |
| 20046 | **/ |
| 20047 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20048 | 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] | 20049 | struct lpfc_iocbq *pwqe) |
| 20050 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 20051 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | 7cacae2 | 2020-03-31 09:50:03 -0700 | [diff] [blame] | 20052 | struct lpfc_async_xchg_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20053 | struct lpfc_queue *wq; |
| 20054 | struct lpfc_sglq *sglq; |
| 20055 | struct lpfc_sli_ring *pring; |
| 20056 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20057 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20058 | |
| 20059 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 20060 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 20061 | pring = phba->sli4_hba.nvmels_wq->pring; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20062 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20063 | qp, wq_access); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20064 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 20065 | if (!sglq) { |
| 20066 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 20067 | return WQE_BUSY; |
| 20068 | } |
| 20069 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 20070 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 20071 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 20072 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 20073 | return WQE_ERROR; |
| 20074 | } |
| 20075 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 20076 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20077 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 20078 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20079 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20080 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20081 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20082 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20083 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20084 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20085 | |
| 20086 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20087 | return 0; |
| 20088 | } |
| 20089 | |
| 20090 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 20091 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 20092 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20093 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20094 | pring = wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20095 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20096 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20097 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20098 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20099 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20100 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 20101 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20102 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20103 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20104 | } |
| 20105 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20106 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20107 | |
| 20108 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20109 | return 0; |
| 20110 | } |
| 20111 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20112 | /* NVMET requests */ |
| 20113 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 20114 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20115 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20116 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20117 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20118 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 20119 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20120 | if (pwqe->sli4_xritag == NO_XRI) { |
| 20121 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 20122 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 20123 | } |
| 20124 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 20125 | pwqe->sli4_xritag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20126 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20127 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20128 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20129 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20130 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 20131 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20132 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20133 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20134 | } |
| 20135 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20136 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20137 | |
| 20138 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20139 | return 0; |
| 20140 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20141 | return WQE_ERROR; |
| 20142 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20143 | |
| 20144 | #ifdef LPFC_MXP_STAT |
| 20145 | /** |
| 20146 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 20147 | * @phba: pointer to lpfc hba data structure. |
| 20148 | * @hwqid: belong to which HWQ. |
| 20149 | * |
| 20150 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 20151 | * 15 seconds after a test case is running. |
| 20152 | * |
| 20153 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 20154 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 20155 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 20156 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 20157 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 20158 | **/ |
| 20159 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 20160 | { |
| 20161 | struct lpfc_sli4_hdw_queue *qp; |
| 20162 | struct lpfc_multixri_pool *multixri_pool; |
| 20163 | struct lpfc_pvt_pool *pvt_pool; |
| 20164 | struct lpfc_pbl_pool *pbl_pool; |
| 20165 | u32 txcmplq_cnt; |
| 20166 | |
| 20167 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20168 | multixri_pool = qp->p_multixri_pool; |
| 20169 | if (!multixri_pool) |
| 20170 | return; |
| 20171 | |
| 20172 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 20173 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20174 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20175 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20176 | |
| 20177 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 20178 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 20179 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 20180 | } |
| 20181 | |
| 20182 | multixri_pool->stat_snapshot_taken++; |
| 20183 | } |
| 20184 | #endif |
| 20185 | |
| 20186 | /** |
| 20187 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 20188 | * @phba: pointer to lpfc hba data structure. |
| 20189 | * @hwqid: belong to which HWQ. |
| 20190 | * |
| 20191 | * This routine moves some XRIs from private to public pool when private pool |
| 20192 | * is not busy. |
| 20193 | **/ |
| 20194 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 20195 | { |
| 20196 | struct lpfc_multixri_pool *multixri_pool; |
| 20197 | u32 io_req_count; |
| 20198 | u32 prev_io_req_count; |
| 20199 | |
| 20200 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20201 | if (!multixri_pool) |
| 20202 | return; |
| 20203 | io_req_count = multixri_pool->io_req_count; |
| 20204 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 20205 | |
| 20206 | if (prev_io_req_count != io_req_count) { |
| 20207 | /* Private pool is busy */ |
| 20208 | multixri_pool->prev_io_req_count = io_req_count; |
| 20209 | } else { |
| 20210 | /* Private pool is not busy. |
| 20211 | * Move XRIs from private to public pool. |
| 20212 | */ |
| 20213 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 20214 | } |
| 20215 | } |
| 20216 | |
| 20217 | /** |
| 20218 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 20219 | * @phba: pointer to lpfc hba data structure. |
| 20220 | * @hwqid: belong to which HWQ. |
| 20221 | * |
| 20222 | * This routine sets high watermark as number of outstanding XRIs, |
| 20223 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 20224 | **/ |
| 20225 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 20226 | { |
| 20227 | u32 new_watermark; |
| 20228 | u32 watermark_max; |
| 20229 | u32 watermark_min; |
| 20230 | u32 xri_limit; |
| 20231 | u32 txcmplq_cnt; |
| 20232 | u32 abts_io_bufs; |
| 20233 | struct lpfc_multixri_pool *multixri_pool; |
| 20234 | struct lpfc_sli4_hdw_queue *qp; |
| 20235 | |
| 20236 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20237 | multixri_pool = qp->p_multixri_pool; |
| 20238 | if (!multixri_pool) |
| 20239 | return; |
| 20240 | xri_limit = multixri_pool->xri_limit; |
| 20241 | |
| 20242 | watermark_max = xri_limit; |
| 20243 | watermark_min = xri_limit / 2; |
| 20244 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20245 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20246 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20247 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20248 | |
| 20249 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 20250 | new_watermark = min(watermark_max, new_watermark); |
| 20251 | new_watermark = max(watermark_min, new_watermark); |
| 20252 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 20253 | |
| 20254 | #ifdef LPFC_MXP_STAT |
| 20255 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 20256 | new_watermark); |
| 20257 | #endif |
| 20258 | } |
| 20259 | |
| 20260 | /** |
| 20261 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 20262 | * @phba: pointer to lpfc hba data structure. |
| 20263 | * @hwqid: belong to which HWQ. |
| 20264 | * |
| 20265 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 20266 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 20267 | * The first step moves (all - low_watermark) amount of XRIs. |
| 20268 | * The second step moves the rest of XRIs. |
| 20269 | **/ |
| 20270 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 20271 | { |
| 20272 | struct lpfc_pbl_pool *pbl_pool; |
| 20273 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20274 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20275 | struct lpfc_io_buf *lpfc_ncmd; |
| 20276 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20277 | unsigned long iflag; |
| 20278 | struct list_head tmp_list; |
| 20279 | u32 tmp_count; |
| 20280 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20281 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20282 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20283 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20284 | tmp_count = 0; |
| 20285 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20286 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 20287 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20288 | |
| 20289 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 20290 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 20291 | * to pbl_pool |
| 20292 | */ |
| 20293 | |
| 20294 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 20295 | INIT_LIST_HEAD(&tmp_list); |
| 20296 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20297 | &pvt_pool->list, list) { |
| 20298 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 20299 | tmp_count++; |
| 20300 | if (tmp_count >= pvt_pool->low_watermark) |
| 20301 | break; |
| 20302 | } |
| 20303 | |
| 20304 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 20305 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 20306 | |
| 20307 | /* Move all bufs from tmp_list to pvt_pool */ |
| 20308 | list_splice(&tmp_list, &pvt_pool->list); |
| 20309 | |
| 20310 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 20311 | pvt_pool->count = tmp_count; |
| 20312 | } else { |
| 20313 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 20314 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 20315 | pbl_pool->count += pvt_pool->count; |
| 20316 | pvt_pool->count = 0; |
| 20317 | } |
| 20318 | |
| 20319 | spin_unlock(&pvt_pool->lock); |
| 20320 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20321 | } |
| 20322 | |
| 20323 | /** |
| 20324 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20325 | * @phba: pointer to lpfc hba data structure |
| 20326 | * @pbl_pool: specified public free XRI pool |
| 20327 | * @pvt_pool: specified private free XRI pool |
| 20328 | * @count: number of XRIs to move |
| 20329 | * |
| 20330 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 20331 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 20332 | * enough in public pool. |
| 20333 | * |
| 20334 | * Return: |
| 20335 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 20336 | * specified pvt_pool |
| 20337 | * false - if the specified pbl_pool is empty or locked by someone else |
| 20338 | **/ |
| 20339 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20340 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 20341 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20342 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 20343 | { |
| 20344 | struct lpfc_io_buf *lpfc_ncmd; |
| 20345 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20346 | unsigned long iflag; |
| 20347 | int ret; |
| 20348 | |
| 20349 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 20350 | if (ret) { |
| 20351 | if (pbl_pool->count) { |
| 20352 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20353 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20354 | list_for_each_entry_safe(lpfc_ncmd, |
| 20355 | lpfc_ncmd_next, |
| 20356 | &pbl_pool->list, |
| 20357 | list) { |
| 20358 | list_move_tail(&lpfc_ncmd->list, |
| 20359 | &pvt_pool->list); |
| 20360 | pvt_pool->count++; |
| 20361 | pbl_pool->count--; |
| 20362 | count--; |
| 20363 | if (count == 0) |
| 20364 | break; |
| 20365 | } |
| 20366 | |
| 20367 | spin_unlock(&pvt_pool->lock); |
| 20368 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20369 | return true; |
| 20370 | } |
| 20371 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20372 | } |
| 20373 | |
| 20374 | return false; |
| 20375 | } |
| 20376 | |
| 20377 | /** |
| 20378 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20379 | * @phba: pointer to lpfc hba data structure. |
| 20380 | * @hwqid: belong to which HWQ. |
| 20381 | * @count: number of XRIs to move |
| 20382 | * |
| 20383 | * This routine tries to find some free common bufs in one of public pools with |
| 20384 | * Round Robin method. The search always starts from local hwqid, then the next |
| 20385 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 20386 | * a batch of free common bufs are moved to private pool on hwqid. |
| 20387 | * It might move less than count XRIs if there's not enough in public pool. |
| 20388 | **/ |
| 20389 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 20390 | { |
| 20391 | struct lpfc_multixri_pool *multixri_pool; |
| 20392 | struct lpfc_multixri_pool *next_multixri_pool; |
| 20393 | struct lpfc_pvt_pool *pvt_pool; |
| 20394 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20395 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20396 | u32 next_hwqid; |
| 20397 | u32 hwq_count; |
| 20398 | int ret; |
| 20399 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20400 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20401 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20402 | pvt_pool = &multixri_pool->pvt_pool; |
| 20403 | pbl_pool = &multixri_pool->pbl_pool; |
| 20404 | |
| 20405 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20406 | 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] | 20407 | if (ret) { |
| 20408 | #ifdef LPFC_MXP_STAT |
| 20409 | multixri_pool->local_pbl_hit_count++; |
| 20410 | #endif |
| 20411 | return; |
| 20412 | } |
| 20413 | |
| 20414 | hwq_count = phba->cfg_hdw_queue; |
| 20415 | |
| 20416 | /* Get the next hwqid which was found last time */ |
| 20417 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 20418 | |
| 20419 | do { |
| 20420 | /* Go to next hwq */ |
| 20421 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 20422 | |
| 20423 | next_multixri_pool = |
| 20424 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 20425 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 20426 | |
| 20427 | /* Check if the public free xri pool is available */ |
| 20428 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20429 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20430 | |
| 20431 | /* Exit while-loop if success or all hwqid are checked */ |
| 20432 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 20433 | |
| 20434 | /* Starting point for the next time */ |
| 20435 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 20436 | |
| 20437 | if (!ret) { |
| 20438 | /* stats: all public pools are empty*/ |
| 20439 | multixri_pool->pbl_empty_count++; |
| 20440 | } |
| 20441 | |
| 20442 | #ifdef LPFC_MXP_STAT |
| 20443 | if (ret) { |
| 20444 | if (next_hwqid == hwqid) |
| 20445 | multixri_pool->local_pbl_hit_count++; |
| 20446 | else |
| 20447 | multixri_pool->other_pbl_hit_count++; |
| 20448 | } |
| 20449 | #endif |
| 20450 | } |
| 20451 | |
| 20452 | /** |
| 20453 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 20454 | * @phba: pointer to lpfc hba data structure. |
| 20455 | * @qp: belong to which HWQ. |
| 20456 | * |
| 20457 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 20458 | * low watermark. |
| 20459 | **/ |
| 20460 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 20461 | { |
| 20462 | struct lpfc_multixri_pool *multixri_pool; |
| 20463 | struct lpfc_pvt_pool *pvt_pool; |
| 20464 | |
| 20465 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20466 | pvt_pool = &multixri_pool->pvt_pool; |
| 20467 | |
| 20468 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 20469 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20470 | } |
| 20471 | |
| 20472 | /** |
| 20473 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 20474 | * @phba: pointer to lpfc hba data structure. |
| 20475 | * @lpfc_ncmd: IO buf to be returned. |
| 20476 | * @qp: belong to which HWQ. |
| 20477 | * |
| 20478 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 20479 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 20480 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 20481 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 20482 | * lpfc_io_buf_list_put. |
| 20483 | **/ |
| 20484 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 20485 | struct lpfc_sli4_hdw_queue *qp) |
| 20486 | { |
| 20487 | unsigned long iflag; |
| 20488 | struct lpfc_pbl_pool *pbl_pool; |
| 20489 | struct lpfc_pvt_pool *pvt_pool; |
| 20490 | struct lpfc_epd_pool *epd_pool; |
| 20491 | u32 txcmplq_cnt; |
| 20492 | u32 xri_owned; |
| 20493 | u32 xri_limit; |
| 20494 | u32 abts_io_bufs; |
| 20495 | |
| 20496 | /* MUST zero fields if buffer is reused by another protocol */ |
| 20497 | lpfc_ncmd->nvmeCmd = NULL; |
| 20498 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 20499 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 20500 | |
James Smart | 35a635a | 2019-09-21 20:59:02 -0700 | [diff] [blame] | 20501 | if (phba->cfg_xpsgl && !phba->nvmet_support && |
| 20502 | !list_empty(&lpfc_ncmd->dma_sgl_xtra_list)) |
| 20503 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 20504 | |
| 20505 | if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list)) |
| 20506 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
| 20507 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20508 | if (phba->cfg_xri_rebalancing) { |
| 20509 | if (lpfc_ncmd->expedite) { |
| 20510 | /* Return to expedite pool */ |
| 20511 | epd_pool = &phba->epd_pool; |
| 20512 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20513 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 20514 | epd_pool->count++; |
| 20515 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20516 | return; |
| 20517 | } |
| 20518 | |
| 20519 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 20520 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 20521 | * Nothing much can be done at this point. |
| 20522 | */ |
| 20523 | if (!qp->p_multixri_pool) |
| 20524 | return; |
| 20525 | |
| 20526 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20527 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20528 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20529 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20530 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20531 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20532 | |
| 20533 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 20534 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 20535 | |
| 20536 | #ifdef LPFC_MXP_STAT |
| 20537 | if (xri_owned <= xri_limit) |
| 20538 | qp->p_multixri_pool->below_limit_count++; |
| 20539 | else |
| 20540 | qp->p_multixri_pool->above_limit_count++; |
| 20541 | #endif |
| 20542 | |
| 20543 | /* XRI goes to either public or private free xri pool |
| 20544 | * based on watermark and xri_limit |
| 20545 | */ |
| 20546 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 20547 | (xri_owned < xri_limit && |
| 20548 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20549 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 20550 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20551 | list_add_tail(&lpfc_ncmd->list, |
| 20552 | &pvt_pool->list); |
| 20553 | pvt_pool->count++; |
| 20554 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20555 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20556 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 20557 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20558 | list_add_tail(&lpfc_ncmd->list, |
| 20559 | &pbl_pool->list); |
| 20560 | pbl_pool->count++; |
| 20561 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20562 | } |
| 20563 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20564 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 20565 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20566 | list_add_tail(&lpfc_ncmd->list, |
| 20567 | &qp->lpfc_io_buf_list_put); |
| 20568 | qp->put_io_bufs++; |
| 20569 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 20570 | iflag); |
| 20571 | } |
| 20572 | } |
| 20573 | |
| 20574 | /** |
| 20575 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 20576 | * @phba: pointer to lpfc hba data structure. |
| 20577 | * @pvt_pool: pointer to private pool data structure. |
| 20578 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20579 | * |
| 20580 | * This routine tries to get one free IO buf from private pool. |
| 20581 | * |
| 20582 | * Return: |
| 20583 | * pointer to one free IO buf - if private pool is not empty |
| 20584 | * NULL - if private pool is empty |
| 20585 | **/ |
| 20586 | static struct lpfc_io_buf * |
| 20587 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20588 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20589 | struct lpfc_pvt_pool *pvt_pool, |
| 20590 | struct lpfc_nodelist *ndlp) |
| 20591 | { |
| 20592 | struct lpfc_io_buf *lpfc_ncmd; |
| 20593 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20594 | unsigned long iflag; |
| 20595 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20596 | 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] | 20597 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20598 | &pvt_pool->list, list) { |
| 20599 | if (lpfc_test_rrq_active( |
| 20600 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 20601 | continue; |
| 20602 | list_del(&lpfc_ncmd->list); |
| 20603 | pvt_pool->count--; |
| 20604 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20605 | return lpfc_ncmd; |
| 20606 | } |
| 20607 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20608 | |
| 20609 | return NULL; |
| 20610 | } |
| 20611 | |
| 20612 | /** |
| 20613 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 20614 | * @phba: pointer to lpfc hba data structure. |
| 20615 | * |
| 20616 | * This routine tries to get one free IO buf from expedite pool. |
| 20617 | * |
| 20618 | * Return: |
| 20619 | * pointer to one free IO buf - if expedite pool is not empty |
| 20620 | * NULL - if expedite pool is empty |
| 20621 | **/ |
| 20622 | static struct lpfc_io_buf * |
| 20623 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 20624 | { |
| 20625 | struct lpfc_io_buf *lpfc_ncmd; |
| 20626 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20627 | unsigned long iflag; |
| 20628 | struct lpfc_epd_pool *epd_pool; |
| 20629 | |
| 20630 | epd_pool = &phba->epd_pool; |
| 20631 | lpfc_ncmd = NULL; |
| 20632 | |
| 20633 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20634 | if (epd_pool->count > 0) { |
| 20635 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20636 | &epd_pool->list, list) { |
| 20637 | list_del(&lpfc_ncmd->list); |
| 20638 | epd_pool->count--; |
| 20639 | break; |
| 20640 | } |
| 20641 | } |
| 20642 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20643 | |
| 20644 | return lpfc_ncmd; |
| 20645 | } |
| 20646 | |
| 20647 | /** |
| 20648 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 20649 | * @phba: pointer to lpfc hba data structure. |
| 20650 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20651 | * @hwqid: belong to which HWQ |
| 20652 | * @expedite: 1 means this request is urgent. |
| 20653 | * |
| 20654 | * This routine will do the following actions and then return a pointer to |
| 20655 | * one free IO buf. |
| 20656 | * |
| 20657 | * 1. If private free xri count is empty, move some XRIs from public to |
| 20658 | * private pool. |
| 20659 | * 2. Get one XRI from private free xri pool. |
| 20660 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 20661 | * get one free xri from expedite pool. |
| 20662 | * |
| 20663 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20664 | * The caller should pass NULL for ndlp on NVME side. |
| 20665 | * |
| 20666 | * Return: |
| 20667 | * pointer to one free IO buf - if private pool is not empty |
| 20668 | * NULL - if private pool is empty |
| 20669 | **/ |
| 20670 | static struct lpfc_io_buf * |
| 20671 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 20672 | struct lpfc_nodelist *ndlp, |
| 20673 | int hwqid, int expedite) |
| 20674 | { |
| 20675 | struct lpfc_sli4_hdw_queue *qp; |
| 20676 | struct lpfc_multixri_pool *multixri_pool; |
| 20677 | struct lpfc_pvt_pool *pvt_pool; |
| 20678 | struct lpfc_io_buf *lpfc_ncmd; |
| 20679 | |
| 20680 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20681 | lpfc_ncmd = NULL; |
| 20682 | multixri_pool = qp->p_multixri_pool; |
| 20683 | pvt_pool = &multixri_pool->pvt_pool; |
| 20684 | multixri_pool->io_req_count++; |
| 20685 | |
| 20686 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 20687 | if (pvt_pool->count == 0) |
| 20688 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20689 | |
| 20690 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20691 | 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] | 20692 | |
| 20693 | if (lpfc_ncmd) { |
| 20694 | lpfc_ncmd->hdwq = qp; |
| 20695 | lpfc_ncmd->hdwq_no = hwqid; |
| 20696 | } else if (expedite) { |
| 20697 | /* If we fail to get one from pvt_pool and this is an expedite |
| 20698 | * request, get one free xri from expedite pool. |
| 20699 | */ |
| 20700 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 20701 | } |
| 20702 | |
| 20703 | return lpfc_ncmd; |
| 20704 | } |
| 20705 | |
| 20706 | static inline struct lpfc_io_buf * |
| 20707 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 20708 | { |
| 20709 | struct lpfc_sli4_hdw_queue *qp; |
| 20710 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 20711 | |
| 20712 | qp = &phba->sli4_hba.hdwq[idx]; |
| 20713 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 20714 | &qp->lpfc_io_buf_list_get, list) { |
| 20715 | if (lpfc_test_rrq_active(phba, ndlp, |
| 20716 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 20717 | continue; |
| 20718 | |
| 20719 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 20720 | continue; |
| 20721 | |
| 20722 | list_del_init(&lpfc_cmd->list); |
| 20723 | qp->get_io_bufs--; |
| 20724 | lpfc_cmd->hdwq = qp; |
| 20725 | lpfc_cmd->hdwq_no = idx; |
| 20726 | return lpfc_cmd; |
| 20727 | } |
| 20728 | return NULL; |
| 20729 | } |
| 20730 | |
| 20731 | /** |
| 20732 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 20733 | * @phba: The HBA for which this call is being executed. |
| 20734 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20735 | * @hwqid: belong to which HWQ |
| 20736 | * @expedite: 1 means this request is urgent. |
| 20737 | * |
| 20738 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 20739 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 20740 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 20741 | * |
| 20742 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20743 | * The caller should pass NULL for ndlp on NVME side. |
| 20744 | * |
| 20745 | * Return codes: |
| 20746 | * NULL - Error |
| 20747 | * Pointer to lpfc_io_buf - Success |
| 20748 | **/ |
| 20749 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 20750 | struct lpfc_nodelist *ndlp, |
| 20751 | u32 hwqid, int expedite) |
| 20752 | { |
| 20753 | struct lpfc_sli4_hdw_queue *qp; |
| 20754 | unsigned long iflag; |
| 20755 | struct lpfc_io_buf *lpfc_cmd; |
| 20756 | |
| 20757 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20758 | lpfc_cmd = NULL; |
| 20759 | |
| 20760 | if (phba->cfg_xri_rebalancing) |
| 20761 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 20762 | phba, ndlp, hwqid, expedite); |
| 20763 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20764 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 20765 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20766 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 20767 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20768 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20769 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 20770 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20771 | list_splice(&qp->lpfc_io_buf_list_put, |
| 20772 | &qp->lpfc_io_buf_list_get); |
| 20773 | qp->get_io_bufs += qp->put_io_bufs; |
| 20774 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 20775 | qp->put_io_bufs = 0; |
| 20776 | spin_unlock(&qp->io_buf_list_put_lock); |
| 20777 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 20778 | expedite) |
| 20779 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20780 | } |
| 20781 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 20782 | } |
| 20783 | |
| 20784 | return lpfc_cmd; |
| 20785 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20786 | |
| 20787 | /** |
| 20788 | * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool |
| 20789 | * @phba: The HBA for which this call is being executed. |
| 20790 | * @lpfc_buf: IO buf structure to append the SGL chunk |
| 20791 | * |
| 20792 | * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool, |
| 20793 | * and will allocate an SGL chunk if the pool is empty. |
| 20794 | * |
| 20795 | * Return codes: |
| 20796 | * NULL - Error |
| 20797 | * Pointer to sli4_hybrid_sgl - Success |
| 20798 | **/ |
| 20799 | struct sli4_hybrid_sgl * |
| 20800 | lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20801 | { |
| 20802 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20803 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20804 | struct sli4_hybrid_sgl *allocated_sgl = NULL; |
| 20805 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20806 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20807 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20808 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20809 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20810 | |
| 20811 | if (likely(!list_empty(buf_list))) { |
| 20812 | /* break off 1 chunk from the sgl_list */ |
| 20813 | list_for_each_entry_safe(list_entry, tmp, |
| 20814 | buf_list, list_node) { |
| 20815 | list_move_tail(&list_entry->list_node, |
| 20816 | &lpfc_buf->dma_sgl_xtra_list); |
| 20817 | break; |
| 20818 | } |
| 20819 | } else { |
| 20820 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20821 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20822 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 20823 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20824 | if (!tmp) { |
| 20825 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20826 | "8353 error kmalloc memory for HDWQ " |
| 20827 | "%d %s\n", |
| 20828 | lpfc_buf->hdwq_no, __func__); |
| 20829 | return NULL; |
| 20830 | } |
| 20831 | |
| 20832 | tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, |
| 20833 | GFP_ATOMIC, &tmp->dma_phys_sgl); |
| 20834 | if (!tmp->dma_sgl) { |
| 20835 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20836 | "8354 error pool_alloc memory for HDWQ " |
| 20837 | "%d %s\n", |
| 20838 | lpfc_buf->hdwq_no, __func__); |
| 20839 | kfree(tmp); |
| 20840 | return NULL; |
| 20841 | } |
| 20842 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20843 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20844 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list); |
| 20845 | } |
| 20846 | |
| 20847 | allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list, |
| 20848 | struct sli4_hybrid_sgl, |
| 20849 | list_node); |
| 20850 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20851 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20852 | |
| 20853 | return allocated_sgl; |
| 20854 | } |
| 20855 | |
| 20856 | /** |
| 20857 | * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool |
| 20858 | * @phba: The HBA for which this call is being executed. |
| 20859 | * @lpfc_buf: IO buf structure with the SGL chunk |
| 20860 | * |
| 20861 | * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool. |
| 20862 | * |
| 20863 | * Return codes: |
| 20864 | * 0 - Success |
| 20865 | * -EINVAL - Error |
| 20866 | **/ |
| 20867 | int |
| 20868 | lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20869 | { |
| 20870 | int rc = 0; |
| 20871 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20872 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20873 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20874 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20875 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20876 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20877 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20878 | |
| 20879 | if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) { |
| 20880 | list_for_each_entry_safe(list_entry, tmp, |
| 20881 | &lpfc_buf->dma_sgl_xtra_list, |
| 20882 | list_node) { |
| 20883 | list_move_tail(&list_entry->list_node, |
| 20884 | buf_list); |
| 20885 | } |
| 20886 | } else { |
| 20887 | rc = -EINVAL; |
| 20888 | } |
| 20889 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20890 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20891 | return rc; |
| 20892 | } |
| 20893 | |
| 20894 | /** |
| 20895 | * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool |
| 20896 | * @phba: phba object |
| 20897 | * @hdwq: hdwq to cleanup sgl buff resources on |
| 20898 | * |
| 20899 | * This routine frees all SGL chunks of hdwq SGL chunk pool. |
| 20900 | * |
| 20901 | * Return codes: |
| 20902 | * None |
| 20903 | **/ |
| 20904 | void |
| 20905 | lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba, |
| 20906 | struct lpfc_sli4_hdw_queue *hdwq) |
| 20907 | { |
| 20908 | struct list_head *buf_list = &hdwq->sgl_list; |
| 20909 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20910 | struct sli4_hybrid_sgl *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20911 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20912 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20913 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20914 | |
| 20915 | /* Free sgl pool */ |
| 20916 | list_for_each_entry_safe(list_entry, tmp, |
| 20917 | buf_list, list_node) { |
| 20918 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 20919 | list_entry->dma_sgl, |
| 20920 | list_entry->dma_phys_sgl); |
| 20921 | list_del(&list_entry->list_node); |
| 20922 | kfree(list_entry); |
| 20923 | } |
| 20924 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20925 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20926 | } |
| 20927 | |
| 20928 | /** |
| 20929 | * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq |
| 20930 | * @phba: The HBA for which this call is being executed. |
| 20931 | * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer |
| 20932 | * |
| 20933 | * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool, |
| 20934 | * and will allocate an CMD/RSP buffer if the pool is empty. |
| 20935 | * |
| 20936 | * Return codes: |
| 20937 | * NULL - Error |
| 20938 | * Pointer to fcp_cmd_rsp_buf - Success |
| 20939 | **/ |
| 20940 | struct fcp_cmd_rsp_buf * |
| 20941 | lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20942 | struct lpfc_io_buf *lpfc_buf) |
| 20943 | { |
| 20944 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20945 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 20946 | struct fcp_cmd_rsp_buf *allocated_buf = NULL; |
| 20947 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20948 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20949 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20950 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20951 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20952 | |
| 20953 | if (likely(!list_empty(buf_list))) { |
| 20954 | /* break off 1 chunk from the list */ |
| 20955 | list_for_each_entry_safe(list_entry, tmp, |
| 20956 | buf_list, |
| 20957 | list_node) { |
| 20958 | list_move_tail(&list_entry->list_node, |
| 20959 | &lpfc_buf->dma_cmd_rsp_list); |
| 20960 | break; |
| 20961 | } |
| 20962 | } else { |
| 20963 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20964 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20965 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 20966 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20967 | if (!tmp) { |
| 20968 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20969 | "8355 error kmalloc memory for HDWQ " |
| 20970 | "%d %s\n", |
| 20971 | lpfc_buf->hdwq_no, __func__); |
| 20972 | return NULL; |
| 20973 | } |
| 20974 | |
| 20975 | tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool, |
| 20976 | GFP_ATOMIC, |
| 20977 | &tmp->fcp_cmd_rsp_dma_handle); |
| 20978 | |
| 20979 | if (!tmp->fcp_cmnd) { |
| 20980 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20981 | "8356 error pool_alloc memory for HDWQ " |
| 20982 | "%d %s\n", |
| 20983 | lpfc_buf->hdwq_no, __func__); |
| 20984 | kfree(tmp); |
| 20985 | return NULL; |
| 20986 | } |
| 20987 | |
| 20988 | tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd + |
| 20989 | sizeof(struct fcp_cmnd)); |
| 20990 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20991 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20992 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list); |
| 20993 | } |
| 20994 | |
| 20995 | allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list, |
| 20996 | struct fcp_cmd_rsp_buf, |
| 20997 | list_node); |
| 20998 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20999 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21000 | |
| 21001 | return allocated_buf; |
| 21002 | } |
| 21003 | |
| 21004 | /** |
| 21005 | * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool |
| 21006 | * @phba: The HBA for which this call is being executed. |
| 21007 | * @lpfc_buf: IO buf structure with the CMD/RSP buf |
| 21008 | * |
| 21009 | * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool. |
| 21010 | * |
| 21011 | * Return codes: |
| 21012 | * 0 - Success |
| 21013 | * -EINVAL - Error |
| 21014 | **/ |
| 21015 | int |
| 21016 | lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 21017 | struct lpfc_io_buf *lpfc_buf) |
| 21018 | { |
| 21019 | int rc = 0; |
| 21020 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 21021 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 21022 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 21023 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21024 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21025 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21026 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21027 | |
| 21028 | if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) { |
| 21029 | list_for_each_entry_safe(list_entry, tmp, |
| 21030 | &lpfc_buf->dma_cmd_rsp_list, |
| 21031 | list_node) { |
| 21032 | list_move_tail(&list_entry->list_node, |
| 21033 | buf_list); |
| 21034 | } |
| 21035 | } else { |
| 21036 | rc = -EINVAL; |
| 21037 | } |
| 21038 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21039 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21040 | return rc; |
| 21041 | } |
| 21042 | |
| 21043 | /** |
| 21044 | * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool |
| 21045 | * @phba: phba object |
| 21046 | * @hdwq: hdwq to cleanup cmd rsp buff resources on |
| 21047 | * |
| 21048 | * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool. |
| 21049 | * |
| 21050 | * Return codes: |
| 21051 | * None |
| 21052 | **/ |
| 21053 | void |
| 21054 | lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 21055 | struct lpfc_sli4_hdw_queue *hdwq) |
| 21056 | { |
| 21057 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 21058 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 21059 | struct fcp_cmd_rsp_buf *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21060 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21061 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21062 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21063 | |
| 21064 | /* Free cmd_rsp buf pool */ |
| 21065 | list_for_each_entry_safe(list_entry, tmp, |
| 21066 | buf_list, |
| 21067 | list_node) { |
| 21068 | dma_pool_free(phba->lpfc_cmd_rsp_buf_pool, |
| 21069 | list_entry->fcp_cmnd, |
| 21070 | list_entry->fcp_cmd_rsp_dma_handle); |
| 21071 | list_del(&list_entry->list_node); |
| 21072 | kfree(list_entry); |
| 21073 | } |
| 21074 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21075 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21076 | } |